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
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.Protein;
92 import org.forester.rio.TestRIO;
93 import org.forester.sdi.SDI;
94 import org.forester.sdi.SDIR;
95 import org.forester.sdi.TestGSDI;
96 import org.forester.sequence.BasicSequence;
97 import org.forester.sequence.Sequence;
98 import org.forester.surfacing.TestSurfacing;
99 import org.forester.tools.ConfidenceAssessor;
100 import org.forester.tools.SupportCount;
101 import org.forester.tools.TreeSplitMatrix;
102 import org.forester.util.AsciiHistogram;
103 import org.forester.util.BasicDescriptiveStatistics;
104 import org.forester.util.BasicTable;
105 import org.forester.util.BasicTableParser;
106 import org.forester.util.DescriptiveStatistics;
107 import org.forester.util.ForesterConstants;
108 import org.forester.util.ForesterUtil;
109 import org.forester.util.GeneralTable;
110 import org.forester.util.SequenceIdParser;
111 import org.forester.ws.seqdb.SequenceDatabaseEntry;
112 import org.forester.ws.seqdb.SequenceDbWsTools;
113 import org.forester.ws.seqdb.UniProtTaxonomy;
114 import org.forester.ws.wabi.TxSearch;
115 import org.forester.ws.wabi.TxSearch.RANKS;
116 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
117 import org.forester.ws.wabi.TxSearch.TAX_RANK;
118
119 @SuppressWarnings( "unused")
120 public final class Test {
121
122     private final static double  ZERO_DIFF                 = 1.0E-9;
123     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
124                                                                    + ForesterUtil.getFileSeparator() + "test_data"
125                                                                    + ForesterUtil.getFileSeparator();
126     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
127                                                                    + ForesterUtil.getFileSeparator() + "resources"
128                                                                    + ForesterUtil.getFileSeparator();
129     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
130     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
131                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
132                                                                    + ForesterConstants.PHYLO_XML_XSD;
133     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
134                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
135                                                                    + ForesterConstants.PHYLO_XML_XSD;
136
137     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
138         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
139         return p;
140     }
141
142     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
143         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
144     }
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( "Sequence writer: " );
178         if ( testSequenceWriter() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Sequence id parsing: " );
187         if ( testSequenceIdParsing() ) {
188             System.out.println( "OK." );
189             succeeded++;
190         }
191         else {
192             System.out.println( "failed." );
193             failed++;
194         }
195         System.out.print( "Hmmscan output parser: " );
196         if ( testHmmscanOutputParser() ) {
197             System.out.println( "OK." );
198             succeeded++;
199         }
200         else {
201             System.out.println( "failed." );
202             failed++;
203         }
204         System.out.print( "Basic node methods: " );
205         if ( Test.testBasicNodeMethods() ) {
206             System.out.println( "OK." );
207             succeeded++;
208         }
209         else {
210             System.out.println( "failed." );
211             failed++;
212         }
213         System.out.print( "Taxonomy code extraction: " );
214         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
215             System.out.println( "OK." );
216             succeeded++;
217         }
218         else {
219             System.out.println( "failed." );
220             failed++;
221         }
222         System.out.print( "SN extraction: " );
223         if ( Test.testExtractSNFromNodeName() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "Taxonomy extraction (general): " );
232         if ( Test.testTaxonomyExtraction() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         System.exit( 0 );
241         System.out.print( "UniProtKB id extraction: " );
242         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
243             System.out.println( "OK." );
244             succeeded++;
245         }
246         else {
247             System.out.println( "failed." );
248             failed++;
249         }
250         System.out.print( "Uri for Aptx web sequence accession: " );
251         if ( Test.testCreateUriForSeqWeb() ) {
252             System.out.println( "OK." );
253             succeeded++;
254         }
255         else {
256             System.out.println( "failed." );
257             failed++;
258         }
259         System.out.print( "Basic node construction and parsing of NHX (node level): " );
260         if ( Test.testNHXNodeParsing() ) {
261             System.out.println( "OK." );
262             succeeded++;
263         }
264         else {
265             System.out.println( "failed." );
266             failed++;
267         }
268         System.out.print( "NHX parsing iterating: " );
269         if ( Test.testNHParsingIter() ) {
270             System.out.println( "OK." );
271             succeeded++;
272         }
273         else {
274             System.out.println( "failed." );
275             failed++;
276         }
277         System.out.print( "NH parsing: " );
278         if ( Test.testNHParsing() ) {
279             System.out.println( "OK." );
280             succeeded++;
281         }
282         else {
283             System.out.println( "failed." );
284             failed++;
285         }
286         System.out.print( "Conversion to NHX (node level): " );
287         if ( Test.testNHXconversion() ) {
288             System.out.println( "OK." );
289             succeeded++;
290         }
291         else {
292             System.out.println( "failed." );
293             failed++;
294         }
295         System.out.print( "NHX parsing: " );
296         if ( Test.testNHXParsing() ) {
297             System.out.println( "OK." );
298             succeeded++;
299         }
300         else {
301             System.out.println( "failed." );
302             failed++;
303         }
304         System.out.print( "NHX parsing with quotes: " );
305         if ( Test.testNHXParsingQuotes() ) {
306             System.out.println( "OK." );
307             succeeded++;
308         }
309         else {
310             System.out.println( "failed." );
311             failed++;
312         }
313         System.out.print( "NHX parsing (MrBayes): " );
314         if ( Test.testNHXParsingMB() ) {
315             System.out.println( "OK." );
316             succeeded++;
317         }
318         else {
319             System.out.println( "failed." );
320             failed++;
321         }
322         System.out.print( "Nexus characters parsing: " );
323         if ( Test.testNexusCharactersParsing() ) {
324             System.out.println( "OK." );
325             succeeded++;
326         }
327         else {
328             System.out.println( "failed." );
329             failed++;
330         }
331         System.out.print( "Nexus tree parsing iterating: " );
332         if ( Test.testNexusTreeParsingIterating() ) {
333             System.out.println( "OK." );
334             succeeded++;
335         }
336         else {
337             System.out.println( "failed." );
338             failed++;
339         }
340         System.out.print( "Nexus tree parsing: " );
341         if ( Test.testNexusTreeParsing() ) {
342             System.out.println( "OK." );
343             succeeded++;
344         }
345         else {
346             System.out.println( "failed." );
347             failed++;
348         }
349         System.out.print( "Nexus tree parsing (translating): " );
350         if ( Test.testNexusTreeParsingTranslating() ) {
351             System.out.println( "OK." );
352             succeeded++;
353         }
354         else {
355             System.out.println( "failed." );
356             failed++;
357         }
358         System.out.print( "Nexus matrix parsing: " );
359         if ( Test.testNexusMatrixParsing() ) {
360             System.out.println( "OK." );
361             succeeded++;
362         }
363         else {
364             System.out.println( "failed." );
365             failed++;
366         }
367         System.out.print( "Basic phyloXML parsing: " );
368         if ( Test.testBasicPhyloXMLparsing() ) {
369             System.out.println( "OK." );
370             succeeded++;
371         }
372         else {
373             System.out.println( "failed." );
374             failed++;
375         }
376         System.out.print( "Basic phyloXML parsing (validating against schema): " );
377         if ( testBasicPhyloXMLparsingValidating() ) {
378             System.out.println( "OK." );
379             succeeded++;
380         }
381         else {
382             System.out.println( "failed." );
383             failed++;
384         }
385         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
386         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
387             System.out.println( "OK." );
388             succeeded++;
389         }
390         else {
391             System.out.println( "failed." );
392             failed++;
393         }
394         System.out.print( "phyloXML Distribution Element: " );
395         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
396             System.out.println( "OK." );
397             succeeded++;
398         }
399         else {
400             System.out.println( "failed." );
401             failed++;
402         }
403         System.out.print( "Tol XML parsing: " );
404         if ( Test.testBasicTolXMLparsing() ) {
405             System.out.println( "OK." );
406             succeeded++;
407         }
408         else {
409             System.out.println( "failed." );
410             failed++;
411         }
412         System.out.print( "Copying of node data: " );
413         if ( Test.testCopyOfNodeData() ) {
414             System.out.println( "OK." );
415             succeeded++;
416         }
417         else {
418             System.out.println( "failed." );
419             failed++;
420         }
421         System.out.print( "Basic tree methods: " );
422         if ( Test.testBasicTreeMethods() ) {
423             System.out.println( "OK." );
424             succeeded++;
425         }
426         else {
427             System.out.println( "failed." );
428             failed++;
429         }
430         System.out.print( "Tree methods: " );
431         if ( Test.testTreeMethods() ) {
432             System.out.println( "OK." );
433             succeeded++;
434         }
435         else {
436             System.out.println( "failed." );
437             failed++;
438         }
439         System.out.print( "Postorder Iterator: " );
440         if ( Test.testPostOrderIterator() ) {
441             System.out.println( "OK." );
442             succeeded++;
443         }
444         else {
445             System.out.println( "failed." );
446             failed++;
447         }
448         System.out.print( "Preorder Iterator: " );
449         if ( Test.testPreOrderIterator() ) {
450             System.out.println( "OK." );
451             succeeded++;
452         }
453         else {
454             System.out.println( "failed." );
455             failed++;
456         }
457         System.out.print( "Levelorder Iterator: " );
458         if ( Test.testLevelOrderIterator() ) {
459             System.out.println( "OK." );
460             succeeded++;
461         }
462         else {
463             System.out.println( "failed." );
464             failed++;
465         }
466         System.out.print( "Re-id methods: " );
467         if ( Test.testReIdMethods() ) {
468             System.out.println( "OK." );
469             succeeded++;
470         }
471         else {
472             System.out.println( "failed." );
473             failed++;
474         }
475         System.out.print( "Methods on last external nodes: " );
476         if ( Test.testLastExternalNodeMethods() ) {
477             System.out.println( "OK." );
478             succeeded++;
479         }
480         else {
481             System.out.println( "failed." );
482             failed++;
483         }
484         System.out.print( "Methods on external nodes: " );
485         if ( Test.testExternalNodeRelatedMethods() ) {
486             System.out.println( "OK." );
487             succeeded++;
488         }
489         else {
490             System.out.println( "failed." );
491             failed++;
492         }
493         System.out.print( "Deletion of external nodes: " );
494         if ( Test.testDeletionOfExternalNodes() ) {
495             System.out.println( "OK." );
496             succeeded++;
497         }
498         else {
499             System.out.println( "failed." );
500             failed++;
501         }
502         System.out.print( "Subtree deletion: " );
503         if ( Test.testSubtreeDeletion() ) {
504             System.out.println( "OK." );
505             succeeded++;
506         }
507         else {
508             System.out.println( "failed." );
509             failed++;
510         }
511         System.out.print( "Phylogeny branch: " );
512         if ( Test.testPhylogenyBranch() ) {
513             System.out.println( "OK." );
514             succeeded++;
515         }
516         else {
517             System.out.println( "failed." );
518             failed++;
519         }
520         System.out.print( "Rerooting: " );
521         if ( Test.testRerooting() ) {
522             System.out.println( "OK." );
523             succeeded++;
524         }
525         else {
526             System.out.println( "failed." );
527             failed++;
528         }
529         System.out.print( "Mipoint rooting: " );
530         if ( Test.testMidpointrooting() ) {
531             System.out.println( "OK." );
532             succeeded++;
533         }
534         else {
535             System.out.println( "failed." );
536             failed++;
537         }
538         System.out.print( "Node removal: " );
539         if ( Test.testNodeRemoval() ) {
540             System.out.println( "OK." );
541             succeeded++;
542         }
543         else {
544             System.out.println( "failed." );
545             failed++;
546         }
547         System.out.print( "Support count: " );
548         if ( Test.testSupportCount() ) {
549             System.out.println( "OK." );
550             succeeded++;
551         }
552         else {
553             System.out.println( "failed." );
554             failed++;
555         }
556         System.out.print( "Support transfer: " );
557         if ( Test.testSupportTransfer() ) {
558             System.out.println( "OK." );
559             succeeded++;
560         }
561         else {
562             System.out.println( "failed." );
563             failed++;
564         }
565         System.out.print( "Finding of LCA: " );
566         if ( Test.testGetLCA() ) {
567             System.out.println( "OK." );
568             succeeded++;
569         }
570         else {
571             System.out.println( "failed." );
572             failed++;
573         }
574         System.out.print( "Finding of LCA 2: " );
575         if ( Test.testGetLCA2() ) {
576             System.out.println( "OK." );
577             succeeded++;
578         }
579         else {
580             System.out.println( "failed." );
581             failed++;
582         }
583         System.out.print( "Calculation of distance between nodes: " );
584         if ( Test.testGetDistance() ) {
585             System.out.println( "OK." );
586             succeeded++;
587         }
588         else {
589             System.out.println( "failed." );
590             failed++;
591         }
592         System.out.print( "Descriptive statistics: " );
593         if ( Test.testDescriptiveStatistics() ) {
594             System.out.println( "OK." );
595             succeeded++;
596         }
597         else {
598             System.out.println( "failed." );
599             failed++;
600         }
601         System.out.print( "Data objects and methods: " );
602         if ( Test.testDataObjects() ) {
603             System.out.println( "OK." );
604             succeeded++;
605         }
606         else {
607             System.out.println( "failed." );
608             failed++;
609         }
610         System.out.print( "Properties map: " );
611         if ( Test.testPropertiesMap() ) {
612             System.out.println( "OK." );
613             succeeded++;
614         }
615         else {
616             System.out.println( "failed." );
617             failed++;
618         }
619         System.out.print( "SDIse: " );
620         if ( Test.testSDIse() ) {
621             System.out.println( "OK." );
622             succeeded++;
623         }
624         else {
625             System.out.println( "failed." );
626             failed++;
627         }
628         System.out.print( "SDIunrooted: " );
629         if ( Test.testSDIunrooted() ) {
630             System.out.println( "OK." );
631             succeeded++;
632         }
633         else {
634             System.out.println( "failed." );
635             failed++;
636         }
637         System.out.print( "GSDI: " );
638         if ( TestGSDI.test() ) {
639             System.out.println( "OK." );
640             succeeded++;
641         }
642         else {
643             System.out.println( "failed." );
644             failed++;
645         }
646         System.out.print( "RIO: " );
647         if ( TestRIO.test() ) {
648             System.out.println( "OK." );
649             succeeded++;
650         }
651         else {
652             System.out.println( "failed." );
653             failed++;
654         }
655         System.out.print( "Phylogeny reconstruction:" );
656         System.out.println();
657         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
658             System.out.println( "OK." );
659             succeeded++;
660         }
661         else {
662             System.out.println( "failed." );
663             failed++;
664         }
665         System.out.print( "Analysis of domain architectures: " );
666         System.out.println();
667         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
668             System.out.println( "OK." );
669             succeeded++;
670         }
671         else {
672             System.out.println( "failed." );
673             failed++;
674         }
675         System.out.print( "GO: " );
676         System.out.println();
677         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
678             System.out.println( "OK." );
679             succeeded++;
680         }
681         else {
682             System.out.println( "failed." );
683             failed++;
684         }
685         System.out.print( "Modeling tools: " );
686         if ( TestPccx.test() ) {
687             System.out.println( "OK." );
688             succeeded++;
689         }
690         else {
691             System.out.println( "failed." );
692             failed++;
693         }
694         System.out.print( "Split Matrix strict: " );
695         if ( Test.testSplitStrict() ) {
696             System.out.println( "OK." );
697             succeeded++;
698         }
699         else {
700             System.out.println( "failed." );
701             failed++;
702         }
703         System.out.print( "Split Matrix: " );
704         if ( Test.testSplit() ) {
705             System.out.println( "OK." );
706             succeeded++;
707         }
708         else {
709             System.out.println( "failed." );
710             failed++;
711         }
712         System.out.print( "Confidence Assessor: " );
713         if ( Test.testConfidenceAssessor() ) {
714             System.out.println( "OK." );
715             succeeded++;
716         }
717         else {
718             System.out.println( "failed." );
719             failed++;
720         }
721         System.out.print( "Basic table: " );
722         if ( Test.testBasicTable() ) {
723             System.out.println( "OK." );
724             succeeded++;
725         }
726         else {
727             System.out.println( "failed." );
728             failed++;
729         }
730         System.out.print( "General table: " );
731         if ( Test.testGeneralTable() ) {
732             System.out.println( "OK." );
733             succeeded++;
734         }
735         else {
736             System.out.println( "failed." );
737             failed++;
738         }
739         System.out.print( "Amino acid sequence: " );
740         if ( Test.testAminoAcidSequence() ) {
741             System.out.println( "OK." );
742             succeeded++;
743         }
744         else {
745             System.out.println( "failed." );
746             failed++;
747         }
748         System.out.print( "General MSA parser: " );
749         if ( Test.testGeneralMsaParser() ) {
750             System.out.println( "OK." );
751             succeeded++;
752         }
753         else {
754             System.out.println( "failed." );
755             failed++;
756         }
757         System.out.print( "Fasta parser for msa: " );
758         if ( Test.testFastaParser() ) {
759             System.out.println( "OK." );
760             succeeded++;
761         }
762         else {
763             System.out.println( "failed." );
764             failed++;
765         }
766         System.out.print( "Creation of balanced phylogeny: " );
767         if ( Test.testCreateBalancedPhylogeny() ) {
768             System.out.println( "OK." );
769             succeeded++;
770         }
771         else {
772             System.out.println( "failed." );
773             failed++;
774         }
775         System.out.print( "EMBL Entry Retrieval: " );
776         if ( Test.testEmblEntryRetrieval() ) {
777             System.out.println( "OK." );
778             succeeded++;
779         }
780         else {
781             System.out.println( "failed." );
782             failed++;
783         }
784         System.out.print( "Uniprot Entry Retrieval: " );
785         if ( Test.testUniprotEntryRetrieval() ) {
786             System.out.println( "OK." );
787             succeeded++;
788         }
789         else {
790             System.out.println( "failed." );
791             failed++;
792         }
793         System.out.print( "Uniprot Taxonomy Search: " );
794         if ( Test.testUniprotTaxonomySearch() ) {
795             System.out.println( "OK." );
796             succeeded++;
797         }
798         else {
799             System.out.println( "failed." );
800             failed++;
801         }
802         //----
803         String path = "";
804         final String os = ForesterUtil.OS_NAME.toLowerCase();
805         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
806             path = "/usr/local/bin/mafft";
807         }
808         else if ( os.indexOf( "win" ) >= 0 ) {
809             path = "C:\\Program Files\\mafft-win\\mafft.bat";
810         }
811         else {
812             path = "/home/czmasek/bin/mafft";
813         }
814         if ( !MsaInferrer.isInstalled( path ) ) {
815             path = "mafft";
816         }
817         if ( !MsaInferrer.isInstalled( path ) ) {
818             path = "/usr/local/bin/mafft";
819         }
820         if ( MsaInferrer.isInstalled( path ) ) {
821             System.out.print( "MAFFT (external program): " );
822             if ( Test.testMafft( path ) ) {
823                 System.out.println( "OK." );
824                 succeeded++;
825             }
826             else {
827                 System.out.println( "failed [will not count towards failed tests]" );
828             }
829         }
830         //----
831         System.out.print( "Next nodes with collapsed: " );
832         if ( Test.testNextNodeWithCollapsing() ) {
833             System.out.println( "OK." );
834             succeeded++;
835         }
836         else {
837             System.out.println( "failed." );
838             failed++;
839         }
840         System.out.print( "Simple MSA quality: " );
841         if ( Test.testMsaQualityMethod() ) {
842             System.out.println( "OK." );
843             succeeded++;
844         }
845         else {
846             System.out.println( "failed." );
847             failed++;
848         }
849         System.out.println();
850         final Runtime rt = java.lang.Runtime.getRuntime();
851         final long free_memory = rt.freeMemory() / 1000000;
852         final long total_memory = rt.totalMemory() / 1000000;
853         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
854                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
855         System.out.println();
856         System.out.println( "Successful tests: " + succeeded );
857         System.out.println( "Failed     tests: " + failed );
858         System.out.println();
859         if ( failed < 1 ) {
860             System.out.println( "OK." );
861         }
862         else {
863             System.out.println( "Not OK." );
864         }
865     }
866
867     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
868         try {
869             PhylogenyNode n = new PhylogenyNode();
870             n.setName( "tr|B3RJ64" );
871             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
872                 return false;
873             }
874             n.setName( "tr.B3RJ64" );
875             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
876                 return false;
877             }
878             n.setName( "tr=B3RJ64" );
879             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
880                 return false;
881             }
882             n.setName( "tr-B3RJ64" );
883             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
884                 return false;
885             }
886             n.setName( "tr/B3RJ64" );
887             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
888                 return false;
889             }
890             n.setName( "tr\\B3RJ64" );
891             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
892                 return false;
893             }
894             n.setName( "tr_B3RJ64" );
895             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
896                 return false;
897             }
898             n.setName( " tr|B3RJ64 " );
899             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
900                 return false;
901             }
902             n.setName( "-tr|B3RJ64-" );
903             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
904                 return false;
905             }
906             n.setName( "-tr=B3RJ64-" );
907             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
908                 return false;
909             }
910             n.setName( "_tr=B3RJ64_" );
911             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
912                 return false;
913             }
914             n.setName( " tr_tr|B3RJ64_sp|123 " );
915             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
916                 return false;
917             }
918             n.setName( "sp|B3RJ64" );
919             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
920                 return false;
921             }
922             n.setName( "ssp|B3RJ64" );
923             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
924                 return false;
925             }
926             n.setName( "sp|B3RJ64C" );
927             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
928                 return false;
929             }
930             n.setName( "sp B3RJ64" );
931             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
932                 return false;
933             }
934             n.setName( "sp|B3RJ6X" );
935             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
936                 return false;
937             }
938             n.setName( "sp|B3RJ6" );
939             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
940                 return false;
941             }
942             n.setName( "K1PYK7_CRAGI" );
943             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
944                 return false;
945             }
946             n.setName( "K1PYK7_PEA" );
947             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
948                 return false;
949             }
950             n.setName( "K1PYK7_RAT" );
951             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
952                 return false;
953             }
954             n.setName( "K1PYK7_PIG" );
955             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
956                 return false;
957             }
958             n.setName( "~K1PYK7_PIG~" );
959             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
960                 return false;
961             }
962             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
963             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
964                 return false;
965             }
966             n.setName( "K1PYKX_CRAGI" );
967             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
968                 return false;
969             }
970             n.setName( "XXXXX_CRAGI" );
971             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
972                 return false;
973             }
974             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
975             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
976                 return false;
977             }
978             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
979             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
980                 return false;
981             }
982             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
983             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
984                 return false;
985             }
986             n = new PhylogenyNode();
987             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
988             seq.setSymbol( "K1PYK7_CRAGI" );
989             n.getNodeData().addSequence( seq );
990             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
991                 return false;
992             }
993             seq.setSymbol( "tr|B3RJ64" );
994             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
995                 return false;
996             }
997             n = new PhylogenyNode();
998             seq = new org.forester.phylogeny.data.Sequence();
999             seq.setName( "K1PYK7_CRAGI" );
1000             n.getNodeData().addSequence( seq );
1001             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
1002                 return false;
1003             }
1004             seq.setName( "tr|B3RJ64" );
1005             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1006                 return false;
1007             }
1008             n = new PhylogenyNode();
1009             seq = new org.forester.phylogeny.data.Sequence();
1010             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
1011             n.getNodeData().addSequence( seq );
1012             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
1013                 return false;
1014             }
1015             n = new PhylogenyNode();
1016             seq = new org.forester.phylogeny.data.Sequence();
1017             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
1018             n.getNodeData().addSequence( seq );
1019             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1020                 return false;
1021             }
1022             //
1023             n = new PhylogenyNode();
1024             n.setName( "ACP19736" );
1025             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1026                 return false;
1027             }
1028             n = new PhylogenyNode();
1029             n.setName( "_ACP19736_" );
1030             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
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 testCreateUriForSeqWeb() {
1042         try {
1043             final PhylogenyNode n = new PhylogenyNode();
1044             n.setName( "tr|B3RJ64" );
1045             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1046                 return false;
1047             }
1048             n.setName( "B0LM41_HUMAN" );
1049             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1050                 return false;
1051             }
1052             n.setName( "NP_001025424" );
1053             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1054                 return false;
1055             }
1056             n.setName( "_NM_001030253-" );
1057             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1058                 return false;
1059             }
1060             n.setName( "XM_002122186" );
1061             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1062                 return false;
1063             }
1064             n.setName( "dgh_AAA34956_gdg" );
1065             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1066                 return false;
1067             }
1068             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
1069             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
1070                 return false;
1071             }
1072             n.setName( "GI:394892" );
1073             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1074                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1075                 return false;
1076             }
1077             n.setName( "gi_394892" );
1078             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1079                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1080                 return false;
1081             }
1082             n.setName( "gi6335_gi_394892_56635_Gi_43" );
1083             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1084                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1085                 return false;
1086             }
1087         }
1088         catch ( final Exception e ) {
1089             e.printStackTrace( System.out );
1090             return false;
1091         }
1092         return true;
1093     }
1094
1095     private static boolean testExtractSNFromNodeName() {
1096         try {
1097             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
1098                 return false;
1099             }
1100             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
1101                     .equals( "Mus musculus musculus" ) ) {
1102                 return false;
1103             }
1104             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
1105                     .equals( "Mus musculus musculus" ) ) {
1106                 return false;
1107             }
1108             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
1109                 return false;
1110             }
1111             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS_Mus_musculus-12 affrre e" )
1112                     .equals( "Mus musculus" ) ) {
1113                 return false;
1114             }
1115         }
1116         catch ( final Exception e ) {
1117             e.printStackTrace( System.out );
1118             return false;
1119         }
1120         return true;
1121     }
1122
1123     private static boolean testExtractTaxonomyCodeFromNodeName() {
1124         try {
1125             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1126                     .equals( "MOUSE" ) ) {
1127                 return false;
1128             }
1129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1130                     .equals( "SOYBN" ) ) {
1131                 return false;
1132             }
1133             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1134                     .equals( "ARATH" ) ) {
1135                 return false;
1136             }
1137             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
1138                     .equals( "ARATH" ) ) {
1139                 return false;
1140             }
1141             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1142                     .equals( "RAT" ) ) {
1143                 return false;
1144             }
1145             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
1146                 return false;
1147             }
1148             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1149                 return false;
1150             }
1151             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1152                     .equals( "MOUSE" ) ) {
1153                 return false;
1154             }
1155             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1156                     .equals( "SOYBN" ) ) {
1157                 return false;
1158             }
1159             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1160                     .equals( "SOYBN" ) ) {
1161                 return false;
1162             }
1163             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1164                     .equals( "SOYBN" ) ) {
1165                 return false;
1166             }
1167             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1168                     .equals( "SOYBN" ) ) {
1169                 return false;
1170             }
1171             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1172                     .equals( "SOYBN" ) ) {
1173                 return false;
1174             }
1175             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1176                     .equals( "SOYBN" ) ) {
1177                 return false;
1178             }
1179             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1180                     .equals( "SOYBN" ) ) {
1181                 return false;
1182             }
1183             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1184                     .equals( "SOYBN" ) ) {
1185                 return false;
1186             }
1187             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN qwerty", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1188                     .equals( "SOYBN" ) ) {
1189                 return false;
1190             }
1191             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN qwerty", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1192                     .equals( "SOYBN" ) ) {
1193                 return false;
1194             }
1195             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1196                     .equals( "SOYBN" ) ) {
1197                 return false;
1198             }
1199             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1200                     .equals( "SOYBN" ) ) {
1201                 return false;
1202             }
1203             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1204                 return false;
1205             }
1206             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1207                     .equals( "SOYBN" ) ) {
1208                 return false;
1209             }
1210             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "N8_ECOLI/1-2:0.01",
1211                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
1212                 return false;
1213             }
1214             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag",
1215                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1216                     .equals( "9YX45" ) ) {
1217                 return false;
1218             }
1219             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1220                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1221                     .equals( "MOUSE" ) ) {
1222                 return false;
1223             }
1224             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
1225                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1226                     .equals( "MOUSE" ) ) {
1227                 return false;
1228             }
1229             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1230                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1231                     .equals( "MOUSE" ) ) {
1232                 return false;
1233             }
1234             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1235                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1236                 return false;
1237             }
1238             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1239                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1240                 return false;
1241             }
1242             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1243                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1244                 return false;
1245             }
1246             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1247                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1248                 return false;
1249             }
1250             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1251                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1252                 return false;
1253             }
1254             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1255                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1256                 return false;
1257             }
1258             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1259                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1260                 return false;
1261             }
1262             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1263                     .equals( "RAT" ) ) {
1264                 return false;
1265             }
1266             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1267                     .equals( "PIG" ) ) {
1268                 return false;
1269             }
1270             if ( !ParserUtils
1271                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1272                     .equals( "MOUSE" ) ) {
1273                 return false;
1274             }
1275             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1276                     .equals( "MOUSE" ) ) {
1277                 return false;
1278             }
1279             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1280                     .equals( "MOUSE" ) ) {
1281                 return false;
1282             }
1283             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE^", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1284                     .equals( "MOUSE" ) ) {
1285                 return false;
1286             }
1287             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE*", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1288                 return false;
1289             }
1290             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE=x", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1291                     .equals( "MOUSE" ) ) {
1292                 return false;
1293             }
1294         }
1295         catch ( final Exception e ) {
1296             e.printStackTrace( System.out );
1297             return false;
1298         }
1299         return true;
1300     }
1301
1302     private static boolean testBasicNodeMethods() {
1303         try {
1304             if ( PhylogenyNode.getNodeCount() != 0 ) {
1305                 return false;
1306             }
1307             final PhylogenyNode n1 = new PhylogenyNode();
1308             final PhylogenyNode n2 = PhylogenyNode
1309                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1310             final PhylogenyNode n3 = PhylogenyNode
1311                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1312             final PhylogenyNode n4 = PhylogenyNode
1313                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1314             if ( n1.isHasAssignedEvent() ) {
1315                 return false;
1316             }
1317             if ( PhylogenyNode.getNodeCount() != 4 ) {
1318                 return false;
1319             }
1320             if ( n3.getIndicator() != 0 ) {
1321                 return false;
1322             }
1323             if ( n3.getNumberOfExternalNodes() != 1 ) {
1324                 return false;
1325             }
1326             if ( !n3.isExternal() ) {
1327                 return false;
1328             }
1329             if ( !n3.isRoot() ) {
1330                 return false;
1331             }
1332             if ( !n4.getName().equals( "n4" ) ) {
1333                 return false;
1334             }
1335         }
1336         catch ( final Exception e ) {
1337             e.printStackTrace( System.out );
1338             return false;
1339         }
1340         return true;
1341     }
1342
1343     private static boolean testBasicPhyloXMLparsing() {
1344         try {
1345             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1346             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1347             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1348                                                               xml_parser );
1349             if ( xml_parser.getErrorCount() > 0 ) {
1350                 System.out.println( xml_parser.getErrorMessages().toString() );
1351                 return false;
1352             }
1353             if ( phylogenies_0.length != 4 ) {
1354                 return false;
1355             }
1356             final Phylogeny t1 = phylogenies_0[ 0 ];
1357             final Phylogeny t2 = phylogenies_0[ 1 ];
1358             final Phylogeny t3 = phylogenies_0[ 2 ];
1359             final Phylogeny t4 = phylogenies_0[ 3 ];
1360             if ( t1.getNumberOfExternalNodes() != 1 ) {
1361                 return false;
1362             }
1363             if ( !t1.isRooted() ) {
1364                 return false;
1365             }
1366             if ( t1.isRerootable() ) {
1367                 return false;
1368             }
1369             if ( !t1.getType().equals( "gene_tree" ) ) {
1370                 return false;
1371             }
1372             if ( t2.getNumberOfExternalNodes() != 2 ) {
1373                 return false;
1374             }
1375             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1376                 return false;
1377             }
1378             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1379                 return false;
1380             }
1381             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1382                 return false;
1383             }
1384             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1385                 return false;
1386             }
1387             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1388                 return false;
1389             }
1390             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1391                 return false;
1392             }
1393             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1394                     .startsWith( "actgtgggggt" ) ) {
1395                 return false;
1396             }
1397             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1398                     .startsWith( "ctgtgatgcat" ) ) {
1399                 return false;
1400             }
1401             if ( t3.getNumberOfExternalNodes() != 4 ) {
1402                 return false;
1403             }
1404             if ( !t1.getName().equals( "t1" ) ) {
1405                 return false;
1406             }
1407             if ( !t2.getName().equals( "t2" ) ) {
1408                 return false;
1409             }
1410             if ( !t3.getName().equals( "t3" ) ) {
1411                 return false;
1412             }
1413             if ( !t4.getName().equals( "t4" ) ) {
1414                 return false;
1415             }
1416             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1417                 return false;
1418             }
1419             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1420                 return false;
1421             }
1422             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1423                 return false;
1424             }
1425             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1426                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1427                 return false;
1428             }
1429             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1430                 return false;
1431             }
1432             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1433                 return false;
1434             }
1435             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1436                 return false;
1437             }
1438             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1439                     .equals( "apoptosis" ) ) {
1440                 return false;
1441             }
1442             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1443                     .equals( "GO:0006915" ) ) {
1444                 return false;
1445             }
1446             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1447                     .equals( "UniProtKB" ) ) {
1448                 return false;
1449             }
1450             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1451                     .equals( "experimental" ) ) {
1452                 return false;
1453             }
1454             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1455                     .equals( "function" ) ) {
1456                 return false;
1457             }
1458             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1459                     .getValue() != 1 ) {
1460                 return false;
1461             }
1462             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1463                     .getType().equals( "ml" ) ) {
1464                 return false;
1465             }
1466             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1467                     .equals( "apoptosis" ) ) {
1468                 return false;
1469             }
1470             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1471                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1472                 return false;
1473             }
1474             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1475                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1476                 return false;
1477             }
1478             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1479                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1480                 return false;
1481             }
1482             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1483                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1484                 return false;
1485             }
1486             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1487                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1488                 return false;
1489             }
1490             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1491                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1492                 return false;
1493             }
1494             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1495                     .equals( "GO:0005829" ) ) {
1496                 return false;
1497             }
1498             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1499                     .equals( "intracellular organelle" ) ) {
1500                 return false;
1501             }
1502             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1503                 return false;
1504             }
1505             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1506                     .equals( "UniProt link" ) ) ) {
1507                 return false;
1508             }
1509             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1510                 return false;
1511             }
1512         }
1513         catch ( final Exception e ) {
1514             e.printStackTrace( System.out );
1515             return false;
1516         }
1517         return true;
1518     }
1519
1520     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1521         try {
1522             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1523             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1524             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1525                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1526             }
1527             else {
1528                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1529             }
1530             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1531                                                               xml_parser );
1532             if ( xml_parser.getErrorCount() > 0 ) {
1533                 System.out.println( xml_parser.getErrorMessages().toString() );
1534                 return false;
1535             }
1536             if ( phylogenies_0.length != 4 ) {
1537                 return false;
1538             }
1539             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1540             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1541             if ( phylogenies_t1.length != 1 ) {
1542                 return false;
1543             }
1544             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1545             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1546                 return false;
1547             }
1548             if ( !t1_rt.isRooted() ) {
1549                 return false;
1550             }
1551             if ( t1_rt.isRerootable() ) {
1552                 return false;
1553             }
1554             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1555                 return false;
1556             }
1557             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1558             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1559             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1560             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1561                 return false;
1562             }
1563             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1564                 return false;
1565             }
1566             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1567                 return false;
1568             }
1569             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1570                 return false;
1571             }
1572             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1573                     .startsWith( "actgtgggggt" ) ) {
1574                 return false;
1575             }
1576             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1577                     .startsWith( "ctgtgatgcat" ) ) {
1578                 return false;
1579             }
1580             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1581             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1582             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1583             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1584             if ( phylogenies_1.length != 1 ) {
1585                 return false;
1586             }
1587             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1588             if ( !t3_rt.getName().equals( "t3" ) ) {
1589                 return false;
1590             }
1591             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1592                 return false;
1593             }
1594             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1595                 return false;
1596             }
1597             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1598                 return false;
1599             }
1600             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1601                 return false;
1602             }
1603             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1604                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1605                 return false;
1606             }
1607             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1608                 return false;
1609             }
1610             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1611                 return false;
1612             }
1613             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1614                     .equals( "UniProtKB" ) ) {
1615                 return false;
1616             }
1617             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1618                     .equals( "apoptosis" ) ) {
1619                 return false;
1620             }
1621             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1622                     .equals( "GO:0006915" ) ) {
1623                 return false;
1624             }
1625             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1626                     .equals( "UniProtKB" ) ) {
1627                 return false;
1628             }
1629             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1630                     .equals( "experimental" ) ) {
1631                 return false;
1632             }
1633             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1634                     .equals( "function" ) ) {
1635                 return false;
1636             }
1637             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1638                     .getValue() != 1 ) {
1639                 return false;
1640             }
1641             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1642                     .getType().equals( "ml" ) ) {
1643                 return false;
1644             }
1645             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1646                     .equals( "apoptosis" ) ) {
1647                 return false;
1648             }
1649             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1650                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1651                 return false;
1652             }
1653             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1654                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1655                 return false;
1656             }
1657             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1658                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1659                 return false;
1660             }
1661             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1662                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1663                 return false;
1664             }
1665             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1666                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1667                 return false;
1668             }
1669             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1670                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1671                 return false;
1672             }
1673             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1674                     .equals( "GO:0005829" ) ) {
1675                 return false;
1676             }
1677             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1678                     .equals( "intracellular organelle" ) ) {
1679                 return false;
1680             }
1681             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1682                 return false;
1683             }
1684             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1685                     .equals( "UniProt link" ) ) ) {
1686                 return false;
1687             }
1688             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1689                 return false;
1690             }
1691             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1692                 return false;
1693             }
1694             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1695                     .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." ) ) ) {
1696                 return false;
1697             }
1698             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1699                 return false;
1700             }
1701             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1702                 return false;
1703             }
1704             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1705                 return false;
1706             }
1707             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1708                 return false;
1709             }
1710             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1711                     .equals( "ncbi" ) ) {
1712                 return false;
1713             }
1714             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1715                 return false;
1716             }
1717             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1718                     .getName().equals( "B" ) ) {
1719                 return false;
1720             }
1721             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1722                     .getFrom() != 21 ) {
1723                 return false;
1724             }
1725             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1726                 return false;
1727             }
1728             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1729                     .getLength() != 24 ) {
1730                 return false;
1731             }
1732             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1733                     .getConfidence() != 2144 ) {
1734                 return false;
1735             }
1736             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1737                     .equals( "pfam" ) ) {
1738                 return false;
1739             }
1740             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1741                 return false;
1742             }
1743             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1744                 return false;
1745             }
1746             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1747                 return false;
1748             }
1749             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1750                 return false;
1751             }
1752             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1753             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1754                 return false;
1755             }
1756             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1757                 return false;
1758             }
1759             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1760                 return false;
1761             }
1762             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1763                 return false;
1764             }
1765             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1766                 return false;
1767             }
1768             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1769                 return false;
1770             }
1771             if ( taxbb.getSynonyms().size() != 2 ) {
1772                 return false;
1773             }
1774             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1775                 return false;
1776             }
1777             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1778                 return false;
1779             }
1780             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1781                 return false;
1782             }
1783             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1784                 return false;
1785             }
1786             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1787                 return false;
1788             }
1789             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1790                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1791                 ;
1792                 return false;
1793             }
1794             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1795                 return false;
1796             }
1797             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1798                 return false;
1799             }
1800             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1801                 return false;
1802             }
1803             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1804                 return false;
1805             }
1806             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1807                 return false;
1808             }
1809             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1810                 return false;
1811             }
1812             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1813                 return false;
1814             }
1815             //
1816             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1817                 return false;
1818             }
1819             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1820                     .equalsIgnoreCase( "435" ) ) {
1821                 return false;
1822             }
1823             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1824                 return false;
1825             }
1826             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1827                     .equalsIgnoreCase( "443.7" ) ) {
1828                 return false;
1829             }
1830             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1831                 return false;
1832             }
1833             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1834                 return false;
1835             }
1836             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1837                     .equalsIgnoreCase( "433" ) ) {
1838                 return false;
1839             }
1840         }
1841         catch ( final Exception e ) {
1842             e.printStackTrace( System.out );
1843             return false;
1844         }
1845         return true;
1846     }
1847
1848     private static boolean testBasicPhyloXMLparsingValidating() {
1849         try {
1850             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1851             PhyloXmlParser xml_parser = null;
1852             try {
1853                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1854             }
1855             catch ( final Exception e ) {
1856                 // Do nothing -- means were not running from jar.
1857             }
1858             if ( xml_parser == null ) {
1859                 xml_parser = new PhyloXmlParser();
1860                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1861                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1862                 }
1863                 else {
1864                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1865                 }
1866             }
1867             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1868                                                               xml_parser );
1869             if ( xml_parser.getErrorCount() > 0 ) {
1870                 System.out.println( xml_parser.getErrorMessages().toString() );
1871                 return false;
1872             }
1873             if ( phylogenies_0.length != 4 ) {
1874                 return false;
1875             }
1876             final Phylogeny t1 = phylogenies_0[ 0 ];
1877             final Phylogeny t2 = phylogenies_0[ 1 ];
1878             final Phylogeny t3 = phylogenies_0[ 2 ];
1879             final Phylogeny t4 = phylogenies_0[ 3 ];
1880             if ( !t1.getName().equals( "t1" ) ) {
1881                 return false;
1882             }
1883             if ( !t2.getName().equals( "t2" ) ) {
1884                 return false;
1885             }
1886             if ( !t3.getName().equals( "t3" ) ) {
1887                 return false;
1888             }
1889             if ( !t4.getName().equals( "t4" ) ) {
1890                 return false;
1891             }
1892             if ( t1.getNumberOfExternalNodes() != 1 ) {
1893                 return false;
1894             }
1895             if ( t2.getNumberOfExternalNodes() != 2 ) {
1896                 return false;
1897             }
1898             if ( t3.getNumberOfExternalNodes() != 4 ) {
1899                 return false;
1900             }
1901             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1902             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1903             if ( xml_parser.getErrorCount() > 0 ) {
1904                 System.out.println( "errors:" );
1905                 System.out.println( xml_parser.getErrorMessages().toString() );
1906                 return false;
1907             }
1908             if ( phylogenies_1.length != 4 ) {
1909                 return false;
1910             }
1911             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1912                                                               xml_parser );
1913             if ( xml_parser.getErrorCount() > 0 ) {
1914                 System.out.println( "errors:" );
1915                 System.out.println( xml_parser.getErrorMessages().toString() );
1916                 return false;
1917             }
1918             if ( phylogenies_2.length != 1 ) {
1919                 return false;
1920             }
1921             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1922                 return false;
1923             }
1924             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1925                                                               xml_parser );
1926             if ( xml_parser.getErrorCount() > 0 ) {
1927                 System.out.println( xml_parser.getErrorMessages().toString() );
1928                 return false;
1929             }
1930             if ( phylogenies_3.length != 2 ) {
1931                 return false;
1932             }
1933             final Phylogeny a = phylogenies_3[ 0 ];
1934             if ( !a.getName().equals( "tree 4" ) ) {
1935                 return false;
1936             }
1937             if ( a.getNumberOfExternalNodes() != 3 ) {
1938                 return false;
1939             }
1940             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1941                 return false;
1942             }
1943             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1944                 return false;
1945             }
1946             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1947                                                               xml_parser );
1948             if ( xml_parser.getErrorCount() > 0 ) {
1949                 System.out.println( xml_parser.getErrorMessages().toString() );
1950                 return false;
1951             }
1952             if ( phylogenies_4.length != 1 ) {
1953                 return false;
1954             }
1955             final Phylogeny s = phylogenies_4[ 0 ];
1956             if ( s.getNumberOfExternalNodes() != 6 ) {
1957                 return false;
1958             }
1959             s.getNode( "first" );
1960             s.getNode( "<>" );
1961             s.getNode( "\"<a'b&c'd\">\"" );
1962             s.getNode( "'''\"" );
1963             s.getNode( "\"\"\"" );
1964             s.getNode( "dick & doof" );
1965         }
1966         catch ( final Exception e ) {
1967             e.printStackTrace( System.out );
1968             return false;
1969         }
1970         return true;
1971     }
1972
1973     private static boolean testBasicTable() {
1974         try {
1975             final BasicTable<String> t0 = new BasicTable<String>();
1976             if ( t0.getNumberOfColumns() != 0 ) {
1977                 return false;
1978             }
1979             if ( t0.getNumberOfRows() != 0 ) {
1980                 return false;
1981             }
1982             t0.setValue( 3, 2, "23" );
1983             t0.setValue( 10, 1, "error" );
1984             t0.setValue( 10, 1, "110" );
1985             t0.setValue( 9, 1, "19" );
1986             t0.setValue( 1, 10, "101" );
1987             t0.setValue( 10, 10, "1010" );
1988             t0.setValue( 100, 10, "10100" );
1989             t0.setValue( 0, 0, "00" );
1990             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1991                 return false;
1992             }
1993             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1994                 return false;
1995             }
1996             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1997                 return false;
1998             }
1999             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2000                 return false;
2001             }
2002             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2003                 return false;
2004             }
2005             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2006                 return false;
2007             }
2008             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2009                 return false;
2010             }
2011             if ( t0.getNumberOfColumns() != 101 ) {
2012                 return false;
2013             }
2014             if ( t0.getNumberOfRows() != 11 ) {
2015                 return false;
2016             }
2017             if ( t0.getValueAsString( 49, 4 ) != null ) {
2018                 return false;
2019             }
2020             final String l = ForesterUtil.getLineSeparator();
2021             final StringBuffer source = new StringBuffer();
2022             source.append( "" + l );
2023             source.append( "# 1 1 1 1 1 1 1 1" + l );
2024             source.append( " 00 01 02 03" + l );
2025             source.append( "   10 11 12 13  " + l );
2026             source.append( "20 21 22 23 " + l );
2027             source.append( "    30  31    32 33" + l );
2028             source.append( "40 41 42 43" + l );
2029             source.append( "  # 1 1 1 1 1 " + l );
2030             source.append( "50 51 52 53 54" + l );
2031             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2032             if ( t1.getNumberOfColumns() != 5 ) {
2033                 return false;
2034             }
2035             if ( t1.getNumberOfRows() != 6 ) {
2036                 return false;
2037             }
2038             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2039                 return false;
2040             }
2041             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2042                 return false;
2043             }
2044             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2045                 return false;
2046             }
2047             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2048                 return false;
2049             }
2050             final StringBuffer source1 = new StringBuffer();
2051             source1.append( "" + l );
2052             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2053             source1.append( " 00; 01 ;02;03" + l );
2054             source1.append( "   10; 11; 12; 13  " + l );
2055             source1.append( "20; 21; 22; 23 " + l );
2056             source1.append( "    30;  31;    32; 33" + l );
2057             source1.append( "40;41;42;43" + l );
2058             source1.append( "  # 1 1 1 1 1 " + l );
2059             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2060             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2061             if ( t2.getNumberOfColumns() != 5 ) {
2062                 return false;
2063             }
2064             if ( t2.getNumberOfRows() != 6 ) {
2065                 return false;
2066             }
2067             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2068                 return false;
2069             }
2070             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2071                 return false;
2072             }
2073             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2074                 return false;
2075             }
2076             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2077                 return false;
2078             }
2079             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2080                 return false;
2081             }
2082             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2083                 return false;
2084             }
2085             final StringBuffer source2 = new StringBuffer();
2086             source2.append( "" + l );
2087             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2088             source2.append( " 00; 01 ;02;03" + l );
2089             source2.append( "   10; 11; 12; 13  " + l );
2090             source2.append( "20; 21; 22; 23 " + l );
2091             source2.append( "                     " + l );
2092             source2.append( "    30;  31;    32; 33" + l );
2093             source2.append( "40;41;42;43" + l );
2094             source2.append( "  comment: 1 1 1 1 1 " + l );
2095             source2.append( ";;;50  ;   52; 53;;54   " + l );
2096             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2097                                                                         ';',
2098                                                                         false,
2099                                                                         false,
2100                                                                         "comment:",
2101                                                                         false );
2102             if ( tl.size() != 2 ) {
2103                 return false;
2104             }
2105             final BasicTable<String> t3 = tl.get( 0 );
2106             final BasicTable<String> t4 = tl.get( 1 );
2107             if ( t3.getNumberOfColumns() != 4 ) {
2108                 return false;
2109             }
2110             if ( t3.getNumberOfRows() != 3 ) {
2111                 return false;
2112             }
2113             if ( t4.getNumberOfColumns() != 4 ) {
2114                 return false;
2115             }
2116             if ( t4.getNumberOfRows() != 3 ) {
2117                 return false;
2118             }
2119             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2120                 return false;
2121             }
2122             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2123                 return false;
2124             }
2125         }
2126         catch ( final Exception e ) {
2127             e.printStackTrace( System.out );
2128             return false;
2129         }
2130         return true;
2131     }
2132
2133     private static boolean testBasicTolXMLparsing() {
2134         try {
2135             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2136             final TolParser parser = new TolParser();
2137             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2138             if ( parser.getErrorCount() > 0 ) {
2139                 System.out.println( parser.getErrorMessages().toString() );
2140                 return false;
2141             }
2142             if ( phylogenies_0.length != 1 ) {
2143                 return false;
2144             }
2145             final Phylogeny t1 = phylogenies_0[ 0 ];
2146             if ( t1.getNumberOfExternalNodes() != 5 ) {
2147                 return false;
2148             }
2149             if ( !t1.isRooted() ) {
2150                 return false;
2151             }
2152             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2153                 return false;
2154             }
2155             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2156                 return false;
2157             }
2158             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2159                 return false;
2160             }
2161             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2162                 return false;
2163             }
2164             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2165             if ( parser.getErrorCount() > 0 ) {
2166                 System.out.println( parser.getErrorMessages().toString() );
2167                 return false;
2168             }
2169             if ( phylogenies_1.length != 1 ) {
2170                 return false;
2171             }
2172             final Phylogeny t2 = phylogenies_1[ 0 ];
2173             if ( t2.getNumberOfExternalNodes() != 664 ) {
2174                 return false;
2175             }
2176             if ( !t2.isRooted() ) {
2177                 return false;
2178             }
2179             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2180                 return false;
2181             }
2182             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2183                 return false;
2184             }
2185             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2186                 return false;
2187             }
2188             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2189                 return false;
2190             }
2191             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2192                 return false;
2193             }
2194             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2195                     .equals( "Aquifex" ) ) {
2196                 return false;
2197             }
2198             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2199             if ( parser.getErrorCount() > 0 ) {
2200                 System.out.println( parser.getErrorMessages().toString() );
2201                 return false;
2202             }
2203             if ( phylogenies_2.length != 1 ) {
2204                 return false;
2205             }
2206             final Phylogeny t3 = phylogenies_2[ 0 ];
2207             if ( t3.getNumberOfExternalNodes() != 184 ) {
2208                 return false;
2209             }
2210             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2211                 return false;
2212             }
2213             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2214                 return false;
2215             }
2216             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2217                 return false;
2218             }
2219             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2220             if ( parser.getErrorCount() > 0 ) {
2221                 System.out.println( parser.getErrorMessages().toString() );
2222                 return false;
2223             }
2224             if ( phylogenies_3.length != 1 ) {
2225                 return false;
2226             }
2227             final Phylogeny t4 = phylogenies_3[ 0 ];
2228             if ( t4.getNumberOfExternalNodes() != 1 ) {
2229                 return false;
2230             }
2231             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2232                 return false;
2233             }
2234             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2235                 return false;
2236             }
2237             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2238                 return false;
2239             }
2240             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2241             if ( parser.getErrorCount() > 0 ) {
2242                 System.out.println( parser.getErrorMessages().toString() );
2243                 return false;
2244             }
2245             if ( phylogenies_4.length != 1 ) {
2246                 return false;
2247             }
2248             final Phylogeny t5 = phylogenies_4[ 0 ];
2249             if ( t5.getNumberOfExternalNodes() != 13 ) {
2250                 return false;
2251             }
2252             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2253                 return false;
2254             }
2255             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2256                 return false;
2257             }
2258             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2259                 return false;
2260             }
2261         }
2262         catch ( final Exception e ) {
2263             e.printStackTrace( System.out );
2264             return false;
2265         }
2266         return true;
2267     }
2268
2269     private static boolean testBasicTreeMethods() {
2270         try {
2271             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2272             final Phylogeny t1 = factory.create();
2273             if ( !t1.isEmpty() ) {
2274                 return false;
2275             }
2276             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2277             if ( t2.getNumberOfExternalNodes() != 4 ) {
2278                 return false;
2279             }
2280             if ( t2.getHeight() != 8.5 ) {
2281                 return false;
2282             }
2283             if ( !t2.isCompletelyBinary() ) {
2284                 return false;
2285             }
2286             if ( t2.isEmpty() ) {
2287                 return false;
2288             }
2289             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2290             if ( t3.getNumberOfExternalNodes() != 5 ) {
2291                 return false;
2292             }
2293             if ( t3.getHeight() != 11 ) {
2294                 return false;
2295             }
2296             if ( t3.isCompletelyBinary() ) {
2297                 return false;
2298             }
2299             final PhylogenyNode n = t3.getNode( "ABC" );
2300             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 ];
2301             if ( t4.getNumberOfExternalNodes() != 9 ) {
2302                 return false;
2303             }
2304             if ( t4.getHeight() != 11 ) {
2305                 return false;
2306             }
2307             if ( t4.isCompletelyBinary() ) {
2308                 return false;
2309             }
2310             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)" );
2311             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2312             if ( t5.getNumberOfExternalNodes() != 8 ) {
2313                 return false;
2314             }
2315             if ( t5.getHeight() != 15 ) {
2316                 return false;
2317             }
2318             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)" );
2319             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2320             if ( t6.getHeight() != 15 ) {
2321                 return false;
2322             }
2323             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)" );
2324             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2325             if ( t7.getHeight() != 15 ) {
2326                 return false;
2327             }
2328             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)" );
2329             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2330             if ( t8.getNumberOfExternalNodes() != 10 ) {
2331                 return false;
2332             }
2333             if ( t8.getHeight() != 15 ) {
2334                 return false;
2335             }
2336             final char[] a9 = new char[] { 'a' };
2337             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2338             if ( t9.getHeight() != 0 ) {
2339                 return false;
2340             }
2341             final char[] a10 = new char[] { 'a', ':', '6' };
2342             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2343             if ( t10.getHeight() != 6 ) {
2344                 return false;
2345             }
2346         }
2347         catch ( final Exception e ) {
2348             e.printStackTrace( System.out );
2349             return false;
2350         }
2351         return true;
2352     }
2353
2354     private static boolean testTreeMethods() {
2355         try {
2356             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2357             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2358             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2359             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2360                 System.out.println( t0.toNewHampshireX() );
2361                 return false;
2362             }
2363             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2364             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2365             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2366                 return false;
2367             }
2368             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2369                 return false;
2370             }
2371             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2372                 return false;
2373             }
2374         }
2375         catch ( final Exception e ) {
2376             e.printStackTrace( System.out );
2377             return false;
2378         }
2379         return true;
2380     }
2381
2382     private static boolean testConfidenceAssessor() {
2383         try {
2384             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2385             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2386             final Phylogeny[] ev0 = factory
2387                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2388                              new NHXParser() );
2389             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2390             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2391                 return false;
2392             }
2393             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2394                 return false;
2395             }
2396             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2397             final Phylogeny[] ev1 = factory
2398                     .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)));",
2399                              new NHXParser() );
2400             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2401             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2402                 return false;
2403             }
2404             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2405                 return false;
2406             }
2407             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2408             final Phylogeny[] ev_b = factory
2409                     .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",
2410                              new NHXParser() );
2411             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2412             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2413                 return false;
2414             }
2415             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2416                 return false;
2417             }
2418             //
2419             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2420             final Phylogeny[] ev1x = factory
2421                     .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)));",
2422                              new NHXParser() );
2423             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2424             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2425                 return false;
2426             }
2427             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2428                 return false;
2429             }
2430             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2431             final Phylogeny[] ev_bx = factory
2432                     .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",
2433                              new NHXParser() );
2434             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2435             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2436                 return false;
2437             }
2438             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2439                 return false;
2440             }
2441             //
2442             final Phylogeny[] t2 = factory
2443                     .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);",
2444                              new NHXParser() );
2445             final Phylogeny[] ev2 = factory
2446                     .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);",
2447                              new NHXParser() );
2448             for( final Phylogeny target : t2 ) {
2449                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2450             }
2451             //
2452             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2453                                                  new NHXParser() )[ 0 ];
2454             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2455             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2456             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2457                 return false;
2458             }
2459             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2460                 return false;
2461             }
2462             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2463                 return false;
2464             }
2465         }
2466         catch ( final Exception e ) {
2467             e.printStackTrace();
2468             return false;
2469         }
2470         return true;
2471     }
2472
2473     private static boolean testCopyOfNodeData() {
2474         try {
2475             final PhylogenyNode n1 = PhylogenyNode
2476                     .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]" );
2477             final PhylogenyNode n2 = n1.copyNodeData();
2478             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2479                 return false;
2480             }
2481         }
2482         catch ( final Exception e ) {
2483             e.printStackTrace();
2484             return false;
2485         }
2486         return true;
2487     }
2488
2489     private static boolean testDataObjects() {
2490         try {
2491             final Confidence s0 = new Confidence();
2492             final Confidence s1 = new Confidence();
2493             if ( !s0.isEqual( s1 ) ) {
2494                 return false;
2495             }
2496             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2497             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2498             if ( s2.isEqual( s1 ) ) {
2499                 return false;
2500             }
2501             if ( !s2.isEqual( s3 ) ) {
2502                 return false;
2503             }
2504             final Confidence s4 = ( Confidence ) s3.copy();
2505             if ( !s4.isEqual( s3 ) ) {
2506                 return false;
2507             }
2508             s3.asSimpleText();
2509             s3.asText();
2510             // Taxonomy
2511             // ----------
2512             final Taxonomy t1 = new Taxonomy();
2513             final Taxonomy t2 = new Taxonomy();
2514             final Taxonomy t3 = new Taxonomy();
2515             final Taxonomy t4 = new Taxonomy();
2516             final Taxonomy t5 = new Taxonomy();
2517             t1.setIdentifier( new Identifier( "ecoli" ) );
2518             t1.setTaxonomyCode( "ECOLI" );
2519             t1.setScientificName( "E. coli" );
2520             t1.setCommonName( "coli" );
2521             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2522             if ( !t1.isEqual( t0 ) ) {
2523                 return false;
2524             }
2525             t2.setIdentifier( new Identifier( "ecoli" ) );
2526             t2.setTaxonomyCode( "OTHER" );
2527             t2.setScientificName( "what" );
2528             t2.setCommonName( "something" );
2529             if ( !t1.isEqual( t2 ) ) {
2530                 return false;
2531             }
2532             t2.setIdentifier( new Identifier( "nemve" ) );
2533             if ( t1.isEqual( t2 ) ) {
2534                 return false;
2535             }
2536             t1.setIdentifier( null );
2537             t3.setTaxonomyCode( "ECOLI" );
2538             t3.setScientificName( "what" );
2539             t3.setCommonName( "something" );
2540             if ( !t1.isEqual( t3 ) ) {
2541                 return false;
2542             }
2543             t1.setIdentifier( null );
2544             t1.setTaxonomyCode( "" );
2545             t4.setScientificName( "E. ColI" );
2546             t4.setCommonName( "something" );
2547             if ( !t1.isEqual( t4 ) ) {
2548                 return false;
2549             }
2550             t4.setScientificName( "B. subtilis" );
2551             t4.setCommonName( "something" );
2552             if ( t1.isEqual( t4 ) ) {
2553                 return false;
2554             }
2555             t1.setIdentifier( null );
2556             t1.setTaxonomyCode( "" );
2557             t1.setScientificName( "" );
2558             t5.setCommonName( "COLI" );
2559             if ( !t1.isEqual( t5 ) ) {
2560                 return false;
2561             }
2562             t5.setCommonName( "vibrio" );
2563             if ( t1.isEqual( t5 ) ) {
2564                 return false;
2565             }
2566             // Identifier
2567             // ----------
2568             final Identifier id0 = new Identifier( "123", "pfam" );
2569             final Identifier id1 = ( Identifier ) id0.copy();
2570             if ( !id1.isEqual( id1 ) ) {
2571                 return false;
2572             }
2573             if ( !id1.isEqual( id0 ) ) {
2574                 return false;
2575             }
2576             if ( !id0.isEqual( id1 ) ) {
2577                 return false;
2578             }
2579             id1.asSimpleText();
2580             id1.asText();
2581             // ProteinDomain
2582             // ---------------
2583             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2584             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2585             if ( !pd1.isEqual( pd1 ) ) {
2586                 return false;
2587             }
2588             if ( !pd1.isEqual( pd0 ) ) {
2589                 return false;
2590             }
2591             pd1.asSimpleText();
2592             pd1.asText();
2593             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2594             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2595             if ( !pd3.isEqual( pd3 ) ) {
2596                 return false;
2597             }
2598             if ( !pd2.isEqual( pd3 ) ) {
2599                 return false;
2600             }
2601             if ( !pd0.isEqual( pd3 ) ) {
2602                 return false;
2603             }
2604             pd3.asSimpleText();
2605             pd3.asText();
2606             // DomainArchitecture
2607             // ------------------
2608             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2609             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2610             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2611             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2612             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2613             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2614             domains0.add( d2 );
2615             domains0.add( d0 );
2616             domains0.add( d3 );
2617             domains0.add( d1 );
2618             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2619             if ( ds0.getNumberOfDomains() != 4 ) {
2620                 return false;
2621             }
2622             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2623             if ( !ds0.isEqual( ds0 ) ) {
2624                 return false;
2625             }
2626             if ( !ds0.isEqual( ds1 ) ) {
2627                 return false;
2628             }
2629             if ( ds1.getNumberOfDomains() != 4 ) {
2630                 return false;
2631             }
2632             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2633             domains1.add( d1 );
2634             domains1.add( d2 );
2635             domains1.add( d4 );
2636             domains1.add( d0 );
2637             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2638             if ( ds0.isEqual( ds2 ) ) {
2639                 return false;
2640             }
2641             ds1.asSimpleText();
2642             ds1.asText();
2643             ds1.toNHX();
2644             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2645             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2646                 System.out.println( ds3.toNHX() );
2647                 return false;
2648             }
2649             if ( ds3.getNumberOfDomains() != 3 ) {
2650                 return false;
2651             }
2652             // Event
2653             // -----
2654             final Event e1 = new Event( Event.EventType.fusion );
2655             if ( e1.isDuplication() ) {
2656                 return false;
2657             }
2658             if ( !e1.isFusion() ) {
2659                 return false;
2660             }
2661             if ( !e1.asText().toString().equals( "fusion" ) ) {
2662                 return false;
2663             }
2664             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2665                 return false;
2666             }
2667             final Event e11 = new Event( Event.EventType.fusion );
2668             if ( !e11.isEqual( e1 ) ) {
2669                 return false;
2670             }
2671             if ( !e11.toNHX().toString().equals( "" ) ) {
2672                 return false;
2673             }
2674             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2675             if ( e2.isDuplication() ) {
2676                 return false;
2677             }
2678             if ( !e2.isSpeciationOrDuplication() ) {
2679                 return false;
2680             }
2681             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2682                 return false;
2683             }
2684             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2685                 return false;
2686             }
2687             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2688                 return false;
2689             }
2690             if ( e11.isEqual( e2 ) ) {
2691                 return false;
2692             }
2693             final Event e2c = ( Event ) e2.copy();
2694             if ( !e2c.isEqual( e2 ) ) {
2695                 return false;
2696             }
2697             Event e3 = new Event( 1, 2, 3 );
2698             if ( e3.isDuplication() ) {
2699                 return false;
2700             }
2701             if ( e3.isSpeciation() ) {
2702                 return false;
2703             }
2704             if ( e3.isGeneLoss() ) {
2705                 return false;
2706             }
2707             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2708                 return false;
2709             }
2710             final Event e3c = ( Event ) e3.copy();
2711             final Event e3cc = ( Event ) e3c.copy();
2712             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2713                 return false;
2714             }
2715             e3 = null;
2716             if ( !e3c.isEqual( e3cc ) ) {
2717                 return false;
2718             }
2719             Event e4 = new Event( 1, 2, 3 );
2720             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2721                 return false;
2722             }
2723             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2724                 return false;
2725             }
2726             final Event e4c = ( Event ) e4.copy();
2727             e4 = null;
2728             final Event e4cc = ( Event ) e4c.copy();
2729             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2730                 return false;
2731             }
2732             if ( !e4c.isEqual( e4cc ) ) {
2733                 return false;
2734             }
2735             final Event e5 = new Event();
2736             if ( !e5.isUnassigned() ) {
2737                 return false;
2738             }
2739             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2740                 return false;
2741             }
2742             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2743                 return false;
2744             }
2745             final Event e6 = new Event( 1, 0, 0 );
2746             if ( !e6.asText().toString().equals( "duplication" ) ) {
2747                 return false;
2748             }
2749             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2750                 return false;
2751             }
2752             final Event e7 = new Event( 0, 1, 0 );
2753             if ( !e7.asText().toString().equals( "speciation" ) ) {
2754                 return false;
2755             }
2756             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2757                 return false;
2758             }
2759             final Event e8 = new Event( 0, 0, 1 );
2760             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2761                 return false;
2762             }
2763             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2764                 return false;
2765             }
2766         }
2767         catch ( final Exception e ) {
2768             e.printStackTrace( System.out );
2769             return false;
2770         }
2771         return true;
2772     }
2773
2774     private static boolean testDeletionOfExternalNodes() {
2775         try {
2776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2777             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2778             final PhylogenyWriter w = new PhylogenyWriter();
2779             if ( t0.isEmpty() ) {
2780                 return false;
2781             }
2782             if ( t0.getNumberOfExternalNodes() != 1 ) {
2783                 return false;
2784             }
2785             t0.deleteSubtree( t0.getNode( "A" ), false );
2786             if ( t0.getNumberOfExternalNodes() != 0 ) {
2787                 return false;
2788             }
2789             if ( !t0.isEmpty() ) {
2790                 return false;
2791             }
2792             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2793             if ( t1.getNumberOfExternalNodes() != 2 ) {
2794                 return false;
2795             }
2796             t1.deleteSubtree( t1.getNode( "A" ), false );
2797             if ( t1.getNumberOfExternalNodes() != 1 ) {
2798                 return false;
2799             }
2800             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2801                 return false;
2802             }
2803             t1.deleteSubtree( t1.getNode( "B" ), false );
2804             if ( t1.getNumberOfExternalNodes() != 1 ) {
2805                 return false;
2806             }
2807             t1.deleteSubtree( t1.getNode( "r" ), false );
2808             if ( !t1.isEmpty() ) {
2809                 return false;
2810             }
2811             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2812             if ( t2.getNumberOfExternalNodes() != 3 ) {
2813                 return false;
2814             }
2815             t2.deleteSubtree( t2.getNode( "B" ), false );
2816             if ( t2.getNumberOfExternalNodes() != 2 ) {
2817                 return false;
2818             }
2819             t2.toNewHampshireX();
2820             PhylogenyNode n = t2.getNode( "A" );
2821             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2822                 return false;
2823             }
2824             t2.deleteSubtree( t2.getNode( "A" ), false );
2825             if ( t2.getNumberOfExternalNodes() != 2 ) {
2826                 return false;
2827             }
2828             t2.deleteSubtree( t2.getNode( "C" ), true );
2829             if ( t2.getNumberOfExternalNodes() != 1 ) {
2830                 return false;
2831             }
2832             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2833             if ( t3.getNumberOfExternalNodes() != 4 ) {
2834                 return false;
2835             }
2836             t3.deleteSubtree( t3.getNode( "B" ), true );
2837             if ( t3.getNumberOfExternalNodes() != 3 ) {
2838                 return false;
2839             }
2840             n = t3.getNode( "A" );
2841             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2842                 return false;
2843             }
2844             n = n.getNextExternalNode();
2845             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2846                 return false;
2847             }
2848             t3.deleteSubtree( t3.getNode( "A" ), true );
2849             if ( t3.getNumberOfExternalNodes() != 2 ) {
2850                 return false;
2851             }
2852             n = t3.getNode( "C" );
2853             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2854                 return false;
2855             }
2856             t3.deleteSubtree( t3.getNode( "C" ), true );
2857             if ( t3.getNumberOfExternalNodes() != 1 ) {
2858                 return false;
2859             }
2860             t3.deleteSubtree( t3.getNode( "D" ), true );
2861             if ( t3.getNumberOfExternalNodes() != 0 ) {
2862                 return false;
2863             }
2864             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2865             if ( t4.getNumberOfExternalNodes() != 6 ) {
2866                 return false;
2867             }
2868             t4.deleteSubtree( t4.getNode( "B2" ), true );
2869             if ( t4.getNumberOfExternalNodes() != 5 ) {
2870                 return false;
2871             }
2872             String s = w.toNewHampshire( t4, false, true ).toString();
2873             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2874                 return false;
2875             }
2876             t4.deleteSubtree( t4.getNode( "B11" ), true );
2877             if ( t4.getNumberOfExternalNodes() != 4 ) {
2878                 return false;
2879             }
2880             t4.deleteSubtree( t4.getNode( "C" ), true );
2881             if ( t4.getNumberOfExternalNodes() != 3 ) {
2882                 return false;
2883             }
2884             n = t4.getNode( "A" );
2885             n = n.getNextExternalNode();
2886             if ( !n.getName().equals( "B12" ) ) {
2887                 return false;
2888             }
2889             n = n.getNextExternalNode();
2890             if ( !n.getName().equals( "D" ) ) {
2891                 return false;
2892             }
2893             s = w.toNewHampshire( t4, false, true ).toString();
2894             if ( !s.equals( "((A,B12),D);" ) ) {
2895                 return false;
2896             }
2897             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2898             t5.deleteSubtree( t5.getNode( "A" ), true );
2899             if ( t5.getNumberOfExternalNodes() != 5 ) {
2900                 return false;
2901             }
2902             s = w.toNewHampshire( t5, false, true ).toString();
2903             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2904                 return false;
2905             }
2906             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2907             t6.deleteSubtree( t6.getNode( "B11" ), true );
2908             if ( t6.getNumberOfExternalNodes() != 5 ) {
2909                 return false;
2910             }
2911             s = w.toNewHampshire( t6, false, false ).toString();
2912             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2913                 return false;
2914             }
2915             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2916             t7.deleteSubtree( t7.getNode( "B12" ), true );
2917             if ( t7.getNumberOfExternalNodes() != 5 ) {
2918                 return false;
2919             }
2920             s = w.toNewHampshire( t7, false, true ).toString();
2921             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2922                 return false;
2923             }
2924             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2925             t8.deleteSubtree( t8.getNode( "B2" ), true );
2926             if ( t8.getNumberOfExternalNodes() != 5 ) {
2927                 return false;
2928             }
2929             s = w.toNewHampshire( t8, false, false ).toString();
2930             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2931                 return false;
2932             }
2933             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2934             t9.deleteSubtree( t9.getNode( "C" ), true );
2935             if ( t9.getNumberOfExternalNodes() != 5 ) {
2936                 return false;
2937             }
2938             s = w.toNewHampshire( t9, false, true ).toString();
2939             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2940                 return false;
2941             }
2942             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2943             t10.deleteSubtree( t10.getNode( "D" ), true );
2944             if ( t10.getNumberOfExternalNodes() != 5 ) {
2945                 return false;
2946             }
2947             s = w.toNewHampshire( t10, false, true ).toString();
2948             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2949                 return false;
2950             }
2951             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2952             t11.deleteSubtree( t11.getNode( "A" ), true );
2953             if ( t11.getNumberOfExternalNodes() != 2 ) {
2954                 return false;
2955             }
2956             s = w.toNewHampshire( t11, false, true ).toString();
2957             if ( !s.equals( "(B,C);" ) ) {
2958                 return false;
2959             }
2960             t11.deleteSubtree( t11.getNode( "C" ), true );
2961             if ( t11.getNumberOfExternalNodes() != 1 ) {
2962                 return false;
2963             }
2964             s = w.toNewHampshire( t11, false, false ).toString();
2965             if ( !s.equals( "B;" ) ) {
2966                 return false;
2967             }
2968             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2969             t12.deleteSubtree( t12.getNode( "B2" ), true );
2970             if ( t12.getNumberOfExternalNodes() != 8 ) {
2971                 return false;
2972             }
2973             s = w.toNewHampshire( t12, false, true ).toString();
2974             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2975                 return false;
2976             }
2977             t12.deleteSubtree( t12.getNode( "B3" ), true );
2978             if ( t12.getNumberOfExternalNodes() != 7 ) {
2979                 return false;
2980             }
2981             s = w.toNewHampshire( t12, false, true ).toString();
2982             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2983                 return false;
2984             }
2985             t12.deleteSubtree( t12.getNode( "C3" ), true );
2986             if ( t12.getNumberOfExternalNodes() != 6 ) {
2987                 return false;
2988             }
2989             s = w.toNewHampshire( t12, false, true ).toString();
2990             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2991                 return false;
2992             }
2993             t12.deleteSubtree( t12.getNode( "A1" ), true );
2994             if ( t12.getNumberOfExternalNodes() != 5 ) {
2995                 return false;
2996             }
2997             s = w.toNewHampshire( t12, false, true ).toString();
2998             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2999                 return false;
3000             }
3001             t12.deleteSubtree( t12.getNode( "B1" ), true );
3002             if ( t12.getNumberOfExternalNodes() != 4 ) {
3003                 return false;
3004             }
3005             s = w.toNewHampshire( t12, false, true ).toString();
3006             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3007                 return false;
3008             }
3009             t12.deleteSubtree( t12.getNode( "A3" ), true );
3010             if ( t12.getNumberOfExternalNodes() != 3 ) {
3011                 return false;
3012             }
3013             s = w.toNewHampshire( t12, false, true ).toString();
3014             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3015                 return false;
3016             }
3017             t12.deleteSubtree( t12.getNode( "A2" ), true );
3018             if ( t12.getNumberOfExternalNodes() != 2 ) {
3019                 return false;
3020             }
3021             s = w.toNewHampshire( t12, false, true ).toString();
3022             if ( !s.equals( "(C1,C2);" ) ) {
3023                 return false;
3024             }
3025             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3026             t13.deleteSubtree( t13.getNode( "D" ), true );
3027             if ( t13.getNumberOfExternalNodes() != 4 ) {
3028                 return false;
3029             }
3030             s = w.toNewHampshire( t13, false, true ).toString();
3031             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3032                 return false;
3033             }
3034             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3035             t14.deleteSubtree( t14.getNode( "E" ), true );
3036             if ( t14.getNumberOfExternalNodes() != 5 ) {
3037                 return false;
3038             }
3039             s = w.toNewHampshire( t14, false, true ).toString();
3040             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3041                 return false;
3042             }
3043             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3044             t15.deleteSubtree( t15.getNode( "B2" ), true );
3045             if ( t15.getNumberOfExternalNodes() != 11 ) {
3046                 return false;
3047             }
3048             t15.deleteSubtree( t15.getNode( "B1" ), true );
3049             if ( t15.getNumberOfExternalNodes() != 10 ) {
3050                 return false;
3051             }
3052             t15.deleteSubtree( t15.getNode( "B3" ), true );
3053             if ( t15.getNumberOfExternalNodes() != 9 ) {
3054                 return false;
3055             }
3056             t15.deleteSubtree( t15.getNode( "B4" ), true );
3057             if ( t15.getNumberOfExternalNodes() != 8 ) {
3058                 return false;
3059             }
3060             t15.deleteSubtree( t15.getNode( "A1" ), true );
3061             if ( t15.getNumberOfExternalNodes() != 7 ) {
3062                 return false;
3063             }
3064             t15.deleteSubtree( t15.getNode( "C4" ), true );
3065             if ( t15.getNumberOfExternalNodes() != 6 ) {
3066                 return false;
3067             }
3068         }
3069         catch ( final Exception e ) {
3070             e.printStackTrace( System.out );
3071             return false;
3072         }
3073         return true;
3074     }
3075
3076     private static boolean testDescriptiveStatistics() {
3077         try {
3078             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3079             dss1.addValue( 82 );
3080             dss1.addValue( 78 );
3081             dss1.addValue( 70 );
3082             dss1.addValue( 58 );
3083             dss1.addValue( 42 );
3084             if ( dss1.getN() != 5 ) {
3085                 return false;
3086             }
3087             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3088                 return false;
3089             }
3090             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3091                 return false;
3092             }
3093             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3094                 return false;
3095             }
3096             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3097                 return false;
3098             }
3099             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3100                 return false;
3101             }
3102             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3103                 return false;
3104             }
3105             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3106                 return false;
3107             }
3108             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3109                 return false;
3110             }
3111             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3112                 return false;
3113             }
3114             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3115                 return false;
3116             }
3117             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3118                 return false;
3119             }
3120             dss1.addValue( 123 );
3121             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3122                 return false;
3123             }
3124             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3125                 return false;
3126             }
3127             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3128                 return false;
3129             }
3130             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3131             dss2.addValue( -1.85 );
3132             dss2.addValue( 57.5 );
3133             dss2.addValue( 92.78 );
3134             dss2.addValue( 57.78 );
3135             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3136                 return false;
3137             }
3138             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3139                 return false;
3140             }
3141             final double[] a = dss2.getDataAsDoubleArray();
3142             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3143                 return false;
3144             }
3145             dss2.addValue( -100 );
3146             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3147                 return false;
3148             }
3149             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3150                 return false;
3151             }
3152             final double[] ds = new double[ 14 ];
3153             ds[ 0 ] = 34;
3154             ds[ 1 ] = 23;
3155             ds[ 2 ] = 1;
3156             ds[ 3 ] = 32;
3157             ds[ 4 ] = 11;
3158             ds[ 5 ] = 2;
3159             ds[ 6 ] = 12;
3160             ds[ 7 ] = 33;
3161             ds[ 8 ] = 13;
3162             ds[ 9 ] = 22;
3163             ds[ 10 ] = 21;
3164             ds[ 11 ] = 35;
3165             ds[ 12 ] = 24;
3166             ds[ 13 ] = 31;
3167             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3168             if ( bins.length != 4 ) {
3169                 return false;
3170             }
3171             if ( bins[ 0 ] != 2 ) {
3172                 return false;
3173             }
3174             if ( bins[ 1 ] != 3 ) {
3175                 return false;
3176             }
3177             if ( bins[ 2 ] != 4 ) {
3178                 return false;
3179             }
3180             if ( bins[ 3 ] != 5 ) {
3181                 return false;
3182             }
3183             final double[] ds1 = new double[ 9 ];
3184             ds1[ 0 ] = 10.0;
3185             ds1[ 1 ] = 19.0;
3186             ds1[ 2 ] = 9.999;
3187             ds1[ 3 ] = 0.0;
3188             ds1[ 4 ] = 39.9;
3189             ds1[ 5 ] = 39.999;
3190             ds1[ 6 ] = 30.0;
3191             ds1[ 7 ] = 19.999;
3192             ds1[ 8 ] = 30.1;
3193             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3194             if ( bins1.length != 4 ) {
3195                 return false;
3196             }
3197             if ( bins1[ 0 ] != 2 ) {
3198                 return false;
3199             }
3200             if ( bins1[ 1 ] != 3 ) {
3201                 return false;
3202             }
3203             if ( bins1[ 2 ] != 0 ) {
3204                 return false;
3205             }
3206             if ( bins1[ 3 ] != 4 ) {
3207                 return false;
3208             }
3209             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3210             if ( bins1_1.length != 3 ) {
3211                 return false;
3212             }
3213             if ( bins1_1[ 0 ] != 3 ) {
3214                 return false;
3215             }
3216             if ( bins1_1[ 1 ] != 2 ) {
3217                 return false;
3218             }
3219             if ( bins1_1[ 2 ] != 4 ) {
3220                 return false;
3221             }
3222             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3223             if ( bins1_2.length != 3 ) {
3224                 return false;
3225             }
3226             if ( bins1_2[ 0 ] != 2 ) {
3227                 return false;
3228             }
3229             if ( bins1_2[ 1 ] != 2 ) {
3230                 return false;
3231             }
3232             if ( bins1_2[ 2 ] != 2 ) {
3233                 return false;
3234             }
3235             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3236             dss3.addValue( 1 );
3237             dss3.addValue( 1 );
3238             dss3.addValue( 1 );
3239             dss3.addValue( 2 );
3240             dss3.addValue( 3 );
3241             dss3.addValue( 4 );
3242             dss3.addValue( 5 );
3243             dss3.addValue( 5 );
3244             dss3.addValue( 5 );
3245             dss3.addValue( 6 );
3246             dss3.addValue( 7 );
3247             dss3.addValue( 8 );
3248             dss3.addValue( 9 );
3249             dss3.addValue( 10 );
3250             dss3.addValue( 10 );
3251             dss3.addValue( 10 );
3252             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3253             histo.toStringBuffer( 10, '=', 40, 5 );
3254             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3255         }
3256         catch ( final Exception e ) {
3257             e.printStackTrace( System.out );
3258             return false;
3259         }
3260         return true;
3261     }
3262
3263     private static boolean testDir( final String file ) {
3264         try {
3265             final File f = new File( file );
3266             if ( !f.exists() ) {
3267                 return false;
3268             }
3269             if ( !f.isDirectory() ) {
3270                 return false;
3271             }
3272             if ( !f.canRead() ) {
3273                 return false;
3274             }
3275         }
3276         catch ( final Exception e ) {
3277             return false;
3278         }
3279         return true;
3280     }
3281
3282     private static boolean testExternalNodeRelatedMethods() {
3283         try {
3284             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3285             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3286             PhylogenyNode n = t1.getNode( "A" );
3287             n = n.getNextExternalNode();
3288             if ( !n.getName().equals( "B" ) ) {
3289                 return false;
3290             }
3291             n = n.getNextExternalNode();
3292             if ( !n.getName().equals( "C" ) ) {
3293                 return false;
3294             }
3295             n = n.getNextExternalNode();
3296             if ( !n.getName().equals( "D" ) ) {
3297                 return false;
3298             }
3299             n = t1.getNode( "B" );
3300             while ( !n.isLastExternalNode() ) {
3301                 n = n.getNextExternalNode();
3302             }
3303             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3304             n = t2.getNode( "A" );
3305             n = n.getNextExternalNode();
3306             if ( !n.getName().equals( "B" ) ) {
3307                 return false;
3308             }
3309             n = n.getNextExternalNode();
3310             if ( !n.getName().equals( "C" ) ) {
3311                 return false;
3312             }
3313             n = n.getNextExternalNode();
3314             if ( !n.getName().equals( "D" ) ) {
3315                 return false;
3316             }
3317             n = t2.getNode( "B" );
3318             while ( !n.isLastExternalNode() ) {
3319                 n = n.getNextExternalNode();
3320             }
3321             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3322             n = t3.getNode( "A" );
3323             n = n.getNextExternalNode();
3324             if ( !n.getName().equals( "B" ) ) {
3325                 return false;
3326             }
3327             n = n.getNextExternalNode();
3328             if ( !n.getName().equals( "C" ) ) {
3329                 return false;
3330             }
3331             n = n.getNextExternalNode();
3332             if ( !n.getName().equals( "D" ) ) {
3333                 return false;
3334             }
3335             n = n.getNextExternalNode();
3336             if ( !n.getName().equals( "E" ) ) {
3337                 return false;
3338             }
3339             n = n.getNextExternalNode();
3340             if ( !n.getName().equals( "F" ) ) {
3341                 return false;
3342             }
3343             n = n.getNextExternalNode();
3344             if ( !n.getName().equals( "G" ) ) {
3345                 return false;
3346             }
3347             n = n.getNextExternalNode();
3348             if ( !n.getName().equals( "H" ) ) {
3349                 return false;
3350             }
3351             n = t3.getNode( "B" );
3352             while ( !n.isLastExternalNode() ) {
3353                 n = n.getNextExternalNode();
3354             }
3355             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3356             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3357                 final PhylogenyNode node = iter.next();
3358             }
3359             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3360             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3361                 final PhylogenyNode node = iter.next();
3362             }
3363             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3364             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3365             if ( !iter.next().getName().equals( "A" ) ) {
3366                 return false;
3367             }
3368             if ( !iter.next().getName().equals( "B" ) ) {
3369                 return false;
3370             }
3371             if ( !iter.next().getName().equals( "C" ) ) {
3372                 return false;
3373             }
3374             if ( !iter.next().getName().equals( "D" ) ) {
3375                 return false;
3376             }
3377             if ( !iter.next().getName().equals( "E" ) ) {
3378                 return false;
3379             }
3380             if ( !iter.next().getName().equals( "F" ) ) {
3381                 return false;
3382             }
3383             if ( iter.hasNext() ) {
3384                 return false;
3385             }
3386         }
3387         catch ( final Exception e ) {
3388             e.printStackTrace( System.out );
3389             return false;
3390         }
3391         return true;
3392     }
3393
3394     private static boolean testGeneralTable() {
3395         try {
3396             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3397             t0.setValue( 3, 2, "23" );
3398             t0.setValue( 10, 1, "error" );
3399             t0.setValue( 10, 1, "110" );
3400             t0.setValue( 9, 1, "19" );
3401             t0.setValue( 1, 10, "101" );
3402             t0.setValue( 10, 10, "1010" );
3403             t0.setValue( 100, 10, "10100" );
3404             t0.setValue( 0, 0, "00" );
3405             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3406                 return false;
3407             }
3408             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3409                 return false;
3410             }
3411             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3412                 return false;
3413             }
3414             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3415                 return false;
3416             }
3417             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3418                 return false;
3419             }
3420             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3421                 return false;
3422             }
3423             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3424                 return false;
3425             }
3426             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3427                 return false;
3428             }
3429             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3430                 return false;
3431             }
3432             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3433             t1.setValue( "3", "2", "23" );
3434             t1.setValue( "10", "1", "error" );
3435             t1.setValue( "10", "1", "110" );
3436             t1.setValue( "9", "1", "19" );
3437             t1.setValue( "1", "10", "101" );
3438             t1.setValue( "10", "10", "1010" );
3439             t1.setValue( "100", "10", "10100" );
3440             t1.setValue( "0", "0", "00" );
3441             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3442             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3443                 return false;
3444             }
3445             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3446                 return false;
3447             }
3448             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3449                 return false;
3450             }
3451             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3452                 return false;
3453             }
3454             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3455                 return false;
3456             }
3457             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3458                 return false;
3459             }
3460             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3461                 return false;
3462             }
3463             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3464                 return false;
3465             }
3466             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3467                 return false;
3468             }
3469             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3470                 return false;
3471             }
3472         }
3473         catch ( final Exception e ) {
3474             e.printStackTrace( System.out );
3475             return false;
3476         }
3477         return true;
3478     }
3479
3480     private static boolean testGetDistance() {
3481         try {
3482             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3483             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",
3484                                                  new NHXParser() )[ 0 ];
3485             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3486                 return false;
3487             }
3488             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3489                 return false;
3490             }
3491             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3492                 return false;
3493             }
3494             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3495                 return false;
3496             }
3497             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3498                 return false;
3499             }
3500             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3501                 return false;
3502             }
3503             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3504                 return false;
3505             }
3506             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3507                 return false;
3508             }
3509             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3510                 return false;
3511             }
3512             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3513                 return false;
3514             }
3515             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3516                 return false;
3517             }
3518             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3519                 return false;
3520             }
3521             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3522                 return false;
3523             }
3524             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3525                 return false;
3526             }
3527             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3528                 return false;
3529             }
3530             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3531                 return false;
3532             }
3533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3534                 return false;
3535             }
3536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3537                 return false;
3538             }
3539             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3540                 return false;
3541             }
3542             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3543                 return false;
3544             }
3545             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3546                 return false;
3547             }
3548             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3549                 return false;
3550             }
3551             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3552                 return false;
3553             }
3554             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3555                 return false;
3556             }
3557             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3558                 return false;
3559             }
3560             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3561                 return false;
3562             }
3563             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3564                 return false;
3565             }
3566             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3567                 return false;
3568             }
3569             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3570                 return false;
3571             }
3572             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3573                 return false;
3574             }
3575             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3576                 return false;
3577             }
3578             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",
3579                                                  new NHXParser() )[ 0 ];
3580             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3581                 return false;
3582             }
3583             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3584                 return false;
3585             }
3586             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3587                 return false;
3588             }
3589             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3590                 return false;
3591             }
3592             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3593                 return false;
3594             }
3595             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3596                 return false;
3597             }
3598             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3599                 return false;
3600             }
3601             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3602                 return false;
3603             }
3604             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3605                 return false;
3606             }
3607             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3608                 return false;
3609             }
3610             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3611                 return false;
3612             }
3613         }
3614         catch ( final Exception e ) {
3615             e.printStackTrace( System.out );
3616             return false;
3617         }
3618         return true;
3619     }
3620
3621     private static boolean testGetLCA() {
3622         try {
3623             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3624             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3625                                                  new NHXParser() )[ 0 ];
3626             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3627             if ( !A.getName().equals( "A" ) ) {
3628                 return false;
3629             }
3630             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3631             if ( !gh.getName().equals( "gh" ) ) {
3632                 return false;
3633             }
3634             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3635             if ( !ab.getName().equals( "ab" ) ) {
3636                 return false;
3637             }
3638             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3639             if ( !ab2.getName().equals( "ab" ) ) {
3640                 return false;
3641             }
3642             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3643             if ( !gh2.getName().equals( "gh" ) ) {
3644                 return false;
3645             }
3646             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3647             if ( !gh3.getName().equals( "gh" ) ) {
3648                 return false;
3649             }
3650             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3651             if ( !abc.getName().equals( "abc" ) ) {
3652                 return false;
3653             }
3654             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3655             if ( !abc2.getName().equals( "abc" ) ) {
3656                 return false;
3657             }
3658             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3659             if ( !abcd.getName().equals( "abcd" ) ) {
3660                 return false;
3661             }
3662             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3663             if ( !abcd2.getName().equals( "abcd" ) ) {
3664                 return false;
3665             }
3666             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3667             if ( !abcdef.getName().equals( "abcdef" ) ) {
3668                 return false;
3669             }
3670             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3671             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3672                 return false;
3673             }
3674             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3675             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3676                 return false;
3677             }
3678             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3679             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3680                 return false;
3681             }
3682             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3683             if ( !abcde.getName().equals( "abcde" ) ) {
3684                 return false;
3685             }
3686             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3687             if ( !abcde2.getName().equals( "abcde" ) ) {
3688                 return false;
3689             }
3690             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3691             if ( !r.getName().equals( "abcdefgh" ) ) {
3692                 return false;
3693             }
3694             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3695             if ( !r2.getName().equals( "abcdefgh" ) ) {
3696                 return false;
3697             }
3698             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3699             if ( !r3.getName().equals( "abcdefgh" ) ) {
3700                 return false;
3701             }
3702             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3703             if ( !abcde3.getName().equals( "abcde" ) ) {
3704                 return false;
3705             }
3706             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3707             if ( !abcde4.getName().equals( "abcde" ) ) {
3708                 return false;
3709             }
3710             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3711             if ( !ab3.getName().equals( "ab" ) ) {
3712                 return false;
3713             }
3714             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3715             if ( !ab4.getName().equals( "ab" ) ) {
3716                 return false;
3717             }
3718             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3719             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3720             if ( !cd.getName().equals( "cd" ) ) {
3721                 return false;
3722             }
3723             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3724             if ( !cd2.getName().equals( "cd" ) ) {
3725                 return false;
3726             }
3727             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3728             if ( !cde.getName().equals( "cde" ) ) {
3729                 return false;
3730             }
3731             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3732             if ( !cde2.getName().equals( "cde" ) ) {
3733                 return false;
3734             }
3735             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3736             if ( !cdef.getName().equals( "cdef" ) ) {
3737                 return false;
3738             }
3739             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3740             if ( !cdef2.getName().equals( "cdef" ) ) {
3741                 return false;
3742             }
3743             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3744             if ( !cdef3.getName().equals( "cdef" ) ) {
3745                 return false;
3746             }
3747             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3748             if ( !rt.getName().equals( "r" ) ) {
3749                 return false;
3750             }
3751             final Phylogeny p3 = factory
3752                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3753                              new NHXParser() )[ 0 ];
3754             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3755             if ( !bc_3.getName().equals( "bc" ) ) {
3756                 return false;
3757             }
3758             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3759             if ( !ac_3.getName().equals( "abc" ) ) {
3760                 return false;
3761             }
3762             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3763             if ( !ad_3.getName().equals( "abcde" ) ) {
3764                 return false;
3765             }
3766             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3767             if ( !af_3.getName().equals( "abcdef" ) ) {
3768                 return false;
3769             }
3770             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3771             if ( !ag_3.getName().equals( "" ) ) {
3772                 return false;
3773             }
3774             if ( !ag_3.isRoot() ) {
3775                 return false;
3776             }
3777             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3778             if ( !al_3.getName().equals( "" ) ) {
3779                 return false;
3780             }
3781             if ( !al_3.isRoot() ) {
3782                 return false;
3783             }
3784             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3785             if ( !kl_3.getName().equals( "" ) ) {
3786                 return false;
3787             }
3788             if ( !kl_3.isRoot() ) {
3789                 return false;
3790             }
3791             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3792             if ( !fl_3.getName().equals( "" ) ) {
3793                 return false;
3794             }
3795             if ( !fl_3.isRoot() ) {
3796                 return false;
3797             }
3798             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3799             if ( !gk_3.getName().equals( "ghijk" ) ) {
3800                 return false;
3801             }
3802             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3803             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3804             if ( !r_4.getName().equals( "r" ) ) {
3805                 return false;
3806             }
3807             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3808             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3809             if ( !r_5.getName().equals( "root" ) ) {
3810                 return false;
3811             }
3812             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3813             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3814             if ( !r_6.getName().equals( "rot" ) ) {
3815                 return false;
3816             }
3817             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3818             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3819             if ( !r_7.getName().equals( "rott" ) ) {
3820                 return false;
3821             }
3822         }
3823         catch ( final Exception e ) {
3824             e.printStackTrace( System.out );
3825             return false;
3826         }
3827         return true;
3828     }
3829
3830     private static boolean testGetLCA2() {
3831         try {
3832             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3833             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3834             PhylogenyMethods.preOrderReId( p_a );
3835             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3836                                                                                               p_a.getNode( "a" ) );
3837             if ( !p_a_1.getName().equals( "a" ) ) {
3838                 return false;
3839             }
3840             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3841             PhylogenyMethods.preOrderReId( p_b );
3842             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3843                                                                                               p_b.getNode( "a" ) );
3844             if ( !p_b_1.getName().equals( "b" ) ) {
3845                 return false;
3846             }
3847             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3848                                                                                               p_b.getNode( "b" ) );
3849             if ( !p_b_2.getName().equals( "b" ) ) {
3850                 return false;
3851             }
3852             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3853             PhylogenyMethods.preOrderReId( p_c );
3854             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3855                                                                                               p_c.getNode( "a" ) );
3856             if ( !p_c_1.getName().equals( "b" ) ) {
3857                 return false;
3858             }
3859             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3860                                                                                               p_c.getNode( "c" ) );
3861             if ( !p_c_2.getName().equals( "c" ) ) {
3862                 System.out.println( p_c_2.getName() );
3863                 System.exit( -1 );
3864                 return false;
3865             }
3866             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3867                                                                                               p_c.getNode( "b" ) );
3868             if ( !p_c_3.getName().equals( "b" ) ) {
3869                 return false;
3870             }
3871             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3872                                                                                               p_c.getNode( "a" ) );
3873             if ( !p_c_4.getName().equals( "c" ) ) {
3874                 return false;
3875             }
3876             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3877                                                  new NHXParser() )[ 0 ];
3878             PhylogenyMethods.preOrderReId( p1 );
3879             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3880                                                                                           p1.getNode( "A" ) );
3881             if ( !A.getName().equals( "A" ) ) {
3882                 return false;
3883             }
3884             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3885                                                                                            p1.getNode( "gh" ) );
3886             if ( !gh.getName().equals( "gh" ) ) {
3887                 return false;
3888             }
3889             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3890                                                                                            p1.getNode( "B" ) );
3891             if ( !ab.getName().equals( "ab" ) ) {
3892                 return false;
3893             }
3894             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3895                                                                                             p1.getNode( "A" ) );
3896             if ( !ab2.getName().equals( "ab" ) ) {
3897                 return false;
3898             }
3899             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3900                                                                                             p1.getNode( "G" ) );
3901             if ( !gh2.getName().equals( "gh" ) ) {
3902                 return false;
3903             }
3904             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3905                                                                                             p1.getNode( "H" ) );
3906             if ( !gh3.getName().equals( "gh" ) ) {
3907                 return false;
3908             }
3909             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3910                                                                                             p1.getNode( "A" ) );
3911             if ( !abc.getName().equals( "abc" ) ) {
3912                 return false;
3913             }
3914             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3915                                                                                              p1.getNode( "C" ) );
3916             if ( !abc2.getName().equals( "abc" ) ) {
3917                 return false;
3918             }
3919             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3920                                                                                              p1.getNode( "D" ) );
3921             if ( !abcd.getName().equals( "abcd" ) ) {
3922                 return false;
3923             }
3924             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3925                                                                                               p1.getNode( "A" ) );
3926             if ( !abcd2.getName().equals( "abcd" ) ) {
3927                 return false;
3928             }
3929             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3930                                                                                                p1.getNode( "F" ) );
3931             if ( !abcdef.getName().equals( "abcdef" ) ) {
3932                 return false;
3933             }
3934             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3935                                                                                                 p1.getNode( "A" ) );
3936             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3937                 return false;
3938             }
3939             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3940                                                                                                 p1.getNode( "F" ) );
3941             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3942                 return false;
3943             }
3944             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3945                                                                                                 p1.getNode( "ab" ) );
3946             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3947                 return false;
3948             }
3949             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3950                                                                                               p1.getNode( "E" ) );
3951             if ( !abcde.getName().equals( "abcde" ) ) {
3952                 return false;
3953             }
3954             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3955                                                                                                p1.getNode( "A" ) );
3956             if ( !abcde2.getName().equals( "abcde" ) ) {
3957                 return false;
3958             }
3959             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3960                                                                                           p1.getNode( "abcdefgh" ) );
3961             if ( !r.getName().equals( "abcdefgh" ) ) {
3962                 return false;
3963             }
3964             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3965                                                                                            p1.getNode( "H" ) );
3966             if ( !r2.getName().equals( "abcdefgh" ) ) {
3967                 return false;
3968             }
3969             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3970                                                                                            p1.getNode( "A" ) );
3971             if ( !r3.getName().equals( "abcdefgh" ) ) {
3972                 return false;
3973             }
3974             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3975                                                                                                p1.getNode( "abcde" ) );
3976             if ( !abcde3.getName().equals( "abcde" ) ) {
3977                 return false;
3978             }
3979             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3980                                                                                                p1.getNode( "E" ) );
3981             if ( !abcde4.getName().equals( "abcde" ) ) {
3982                 return false;
3983             }
3984             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3985                                                                                             p1.getNode( "B" ) );
3986             if ( !ab3.getName().equals( "ab" ) ) {
3987                 return false;
3988             }
3989             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3990                                                                                             p1.getNode( "ab" ) );
3991             if ( !ab4.getName().equals( "ab" ) ) {
3992                 return false;
3993             }
3994             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3995             PhylogenyMethods.preOrderReId( p2 );
3996             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3997                                                                                            p2.getNode( "d" ) );
3998             if ( !cd.getName().equals( "cd" ) ) {
3999                 return false;
4000             }
4001             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4002                                                                                             p2.getNode( "c" ) );
4003             if ( !cd2.getName().equals( "cd" ) ) {
4004                 return false;
4005             }
4006             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4007                                                                                             p2.getNode( "e" ) );
4008             if ( !cde.getName().equals( "cde" ) ) {
4009                 return false;
4010             }
4011             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4012                                                                                              p2.getNode( "c" ) );
4013             if ( !cde2.getName().equals( "cde" ) ) {
4014                 return false;
4015             }
4016             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4017                                                                                              p2.getNode( "f" ) );
4018             if ( !cdef.getName().equals( "cdef" ) ) {
4019                 return false;
4020             }
4021             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4022                                                                                               p2.getNode( "f" ) );
4023             if ( !cdef2.getName().equals( "cdef" ) ) {
4024                 return false;
4025             }
4026             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4027                                                                                               p2.getNode( "d" ) );
4028             if ( !cdef3.getName().equals( "cdef" ) ) {
4029                 return false;
4030             }
4031             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4032                                                                                            p2.getNode( "a" ) );
4033             if ( !rt.getName().equals( "r" ) ) {
4034                 return false;
4035             }
4036             final Phylogeny p3 = factory
4037                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4038                              new NHXParser() )[ 0 ];
4039             PhylogenyMethods.preOrderReId( p3 );
4040             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4041                                                                                              p3.getNode( "c" ) );
4042             if ( !bc_3.getName().equals( "bc" ) ) {
4043                 return false;
4044             }
4045             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4046                                                                                              p3.getNode( "c" ) );
4047             if ( !ac_3.getName().equals( "abc" ) ) {
4048                 return false;
4049             }
4050             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4051                                                                                              p3.getNode( "d" ) );
4052             if ( !ad_3.getName().equals( "abcde" ) ) {
4053                 return false;
4054             }
4055             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4056                                                                                              p3.getNode( "f" ) );
4057             if ( !af_3.getName().equals( "abcdef" ) ) {
4058                 return false;
4059             }
4060             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4061                                                                                              p3.getNode( "g" ) );
4062             if ( !ag_3.getName().equals( "" ) ) {
4063                 return false;
4064             }
4065             if ( !ag_3.isRoot() ) {
4066                 return false;
4067             }
4068             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4069                                                                                              p3.getNode( "l" ) );
4070             if ( !al_3.getName().equals( "" ) ) {
4071                 return false;
4072             }
4073             if ( !al_3.isRoot() ) {
4074                 return false;
4075             }
4076             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4077                                                                                              p3.getNode( "l" ) );
4078             if ( !kl_3.getName().equals( "" ) ) {
4079                 return false;
4080             }
4081             if ( !kl_3.isRoot() ) {
4082                 return false;
4083             }
4084             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4085                                                                                              p3.getNode( "l" ) );
4086             if ( !fl_3.getName().equals( "" ) ) {
4087                 return false;
4088             }
4089             if ( !fl_3.isRoot() ) {
4090                 return false;
4091             }
4092             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4093                                                                                              p3.getNode( "k" ) );
4094             if ( !gk_3.getName().equals( "ghijk" ) ) {
4095                 return false;
4096             }
4097             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4098             PhylogenyMethods.preOrderReId( p4 );
4099             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4100                                                                                             p4.getNode( "c" ) );
4101             if ( !r_4.getName().equals( "r" ) ) {
4102                 return false;
4103             }
4104             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4105             PhylogenyMethods.preOrderReId( p5 );
4106             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4107                                                                                             p5.getNode( "c" ) );
4108             if ( !r_5.getName().equals( "root" ) ) {
4109                 return false;
4110             }
4111             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4112             PhylogenyMethods.preOrderReId( p6 );
4113             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4114                                                                                             p6.getNode( "a" ) );
4115             if ( !r_6.getName().equals( "rot" ) ) {
4116                 return false;
4117             }
4118             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4119             PhylogenyMethods.preOrderReId( p7 );
4120             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4121                                                                                             p7.getNode( "e" ) );
4122             if ( !r_7.getName().equals( "rott" ) ) {
4123                 return false;
4124             }
4125             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4126                                                                                              p7.getNode( "a" ) );
4127             if ( !r_71.getName().equals( "rott" ) ) {
4128                 return false;
4129             }
4130             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4131                                                                                              p7.getNode( "rott" ) );
4132             if ( !r_72.getName().equals( "rott" ) ) {
4133                 return false;
4134             }
4135             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4136                                                                                              p7.getNode( "a" ) );
4137             if ( !r_73.getName().equals( "rott" ) ) {
4138                 return false;
4139             }
4140             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4141                                                                                              p7.getNode( "rott" ) );
4142             if ( !r_74.getName().equals( "rott" ) ) {
4143                 return false;
4144             }
4145             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4146                                                                                              p7.getNode( "e" ) );
4147             if ( !r_75.getName().equals( "e" ) ) {
4148                 return false;
4149             }
4150         }
4151         catch ( final Exception e ) {
4152             e.printStackTrace( System.out );
4153             return false;
4154         }
4155         return true;
4156     }
4157
4158     private static boolean testHmmscanOutputParser() {
4159         final String test_dir = Test.PATH_TO_TEST_DATA;
4160         try {
4161             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4162                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4163             parser1.parse();
4164             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4165                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4166             final List<Protein> proteins = parser2.parse();
4167             if ( parser2.getProteinsEncountered() != 4 ) {
4168                 return false;
4169             }
4170             if ( proteins.size() != 4 ) {
4171                 return false;
4172             }
4173             if ( parser2.getDomainsEncountered() != 69 ) {
4174                 return false;
4175             }
4176             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4177                 return false;
4178             }
4179             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4180                 return false;
4181             }
4182             final Protein p1 = proteins.get( 0 );
4183             if ( p1.getNumberOfProteinDomains() != 15 ) {
4184                 return false;
4185             }
4186             if ( p1.getLength() != 850 ) {
4187                 return false;
4188             }
4189             final Protein p2 = proteins.get( 1 );
4190             if ( p2.getNumberOfProteinDomains() != 51 ) {
4191                 return false;
4192             }
4193             if ( p2.getLength() != 1291 ) {
4194                 return false;
4195             }
4196             final Protein p3 = proteins.get( 2 );
4197             if ( p3.getNumberOfProteinDomains() != 2 ) {
4198                 return false;
4199             }
4200             final Protein p4 = proteins.get( 3 );
4201             if ( p4.getNumberOfProteinDomains() != 1 ) {
4202                 return false;
4203             }
4204             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4205                 return false;
4206             }
4207             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4208                 return false;
4209             }
4210             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4211                 return false;
4212             }
4213             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4214                 return false;
4215             }
4216             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4217                 return false;
4218             }
4219             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4220                 return false;
4221             }
4222             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4223                 return false;
4224             }
4225             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4226                 return false;
4227             }
4228             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4229                 return false;
4230             }
4231         }
4232         catch ( final Exception e ) {
4233             e.printStackTrace( System.out );
4234             return false;
4235         }
4236         return true;
4237     }
4238
4239     private static boolean testLastExternalNodeMethods() {
4240         try {
4241             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4242             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4243             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4244             final PhylogenyNode n1 = t0.getNode( "A" );
4245             if ( n1.isLastExternalNode() ) {
4246                 return false;
4247             }
4248             final PhylogenyNode n2 = t0.getNode( "B" );
4249             if ( n2.isLastExternalNode() ) {
4250                 return false;
4251             }
4252             final PhylogenyNode n3 = t0.getNode( "C" );
4253             if ( n3.isLastExternalNode() ) {
4254                 return false;
4255             }
4256             final PhylogenyNode n4 = t0.getNode( "D" );
4257             if ( !n4.isLastExternalNode() ) {
4258                 return false;
4259             }
4260         }
4261         catch ( final Exception e ) {
4262             e.printStackTrace( System.out );
4263             return false;
4264         }
4265         return true;
4266     }
4267
4268     private static boolean testLevelOrderIterator() {
4269         try {
4270             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4271             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4272             PhylogenyNodeIterator it0;
4273             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4274                 it0.next();
4275             }
4276             for( it0.reset(); it0.hasNext(); ) {
4277                 it0.next();
4278             }
4279             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4280             if ( !it.next().getName().equals( "r" ) ) {
4281                 return false;
4282             }
4283             if ( !it.next().getName().equals( "ab" ) ) {
4284                 return false;
4285             }
4286             if ( !it.next().getName().equals( "cd" ) ) {
4287                 return false;
4288             }
4289             if ( !it.next().getName().equals( "A" ) ) {
4290                 return false;
4291             }
4292             if ( !it.next().getName().equals( "B" ) ) {
4293                 return false;
4294             }
4295             if ( !it.next().getName().equals( "C" ) ) {
4296                 return false;
4297             }
4298             if ( !it.next().getName().equals( "D" ) ) {
4299                 return false;
4300             }
4301             if ( it.hasNext() ) {
4302                 return false;
4303             }
4304             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",
4305                                                  new NHXParser() )[ 0 ];
4306             PhylogenyNodeIterator it2;
4307             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4308                 it2.next();
4309             }
4310             for( it2.reset(); it2.hasNext(); ) {
4311                 it2.next();
4312             }
4313             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4314             if ( !it3.next().getName().equals( "r" ) ) {
4315                 return false;
4316             }
4317             if ( !it3.next().getName().equals( "abc" ) ) {
4318                 return false;
4319             }
4320             if ( !it3.next().getName().equals( "defg" ) ) {
4321                 return false;
4322             }
4323             if ( !it3.next().getName().equals( "A" ) ) {
4324                 return false;
4325             }
4326             if ( !it3.next().getName().equals( "B" ) ) {
4327                 return false;
4328             }
4329             if ( !it3.next().getName().equals( "C" ) ) {
4330                 return false;
4331             }
4332             if ( !it3.next().getName().equals( "D" ) ) {
4333                 return false;
4334             }
4335             if ( !it3.next().getName().equals( "E" ) ) {
4336                 return false;
4337             }
4338             if ( !it3.next().getName().equals( "F" ) ) {
4339                 return false;
4340             }
4341             if ( !it3.next().getName().equals( "G" ) ) {
4342                 return false;
4343             }
4344             if ( !it3.next().getName().equals( "1" ) ) {
4345                 return false;
4346             }
4347             if ( !it3.next().getName().equals( "2" ) ) {
4348                 return false;
4349             }
4350             if ( !it3.next().getName().equals( "3" ) ) {
4351                 return false;
4352             }
4353             if ( !it3.next().getName().equals( "4" ) ) {
4354                 return false;
4355             }
4356             if ( !it3.next().getName().equals( "5" ) ) {
4357                 return false;
4358             }
4359             if ( !it3.next().getName().equals( "6" ) ) {
4360                 return false;
4361             }
4362             if ( !it3.next().getName().equals( "f1" ) ) {
4363                 return false;
4364             }
4365             if ( !it3.next().getName().equals( "f2" ) ) {
4366                 return false;
4367             }
4368             if ( !it3.next().getName().equals( "f3" ) ) {
4369                 return false;
4370             }
4371             if ( !it3.next().getName().equals( "a" ) ) {
4372                 return false;
4373             }
4374             if ( !it3.next().getName().equals( "b" ) ) {
4375                 return false;
4376             }
4377             if ( !it3.next().getName().equals( "f21" ) ) {
4378                 return false;
4379             }
4380             if ( !it3.next().getName().equals( "X" ) ) {
4381                 return false;
4382             }
4383             if ( !it3.next().getName().equals( "Y" ) ) {
4384                 return false;
4385             }
4386             if ( !it3.next().getName().equals( "Z" ) ) {
4387                 return false;
4388             }
4389             if ( it3.hasNext() ) {
4390                 return false;
4391             }
4392             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4393             PhylogenyNodeIterator it4;
4394             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4395                 it4.next();
4396             }
4397             for( it4.reset(); it4.hasNext(); ) {
4398                 it4.next();
4399             }
4400             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4401             if ( !it5.next().getName().equals( "r" ) ) {
4402                 return false;
4403             }
4404             if ( !it5.next().getName().equals( "A" ) ) {
4405                 return false;
4406             }
4407             if ( !it5.next().getName().equals( "B" ) ) {
4408                 return false;
4409             }
4410             if ( !it5.next().getName().equals( "C" ) ) {
4411                 return false;
4412             }
4413             if ( !it5.next().getName().equals( "D" ) ) {
4414                 return false;
4415             }
4416             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4417             PhylogenyNodeIterator it6;
4418             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4419                 it6.next();
4420             }
4421             for( it6.reset(); it6.hasNext(); ) {
4422                 it6.next();
4423             }
4424             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4425             if ( !it7.next().getName().equals( "A" ) ) {
4426                 return false;
4427             }
4428             if ( it.hasNext() ) {
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 testNodeRemoval() {
4440         try {
4441             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4442             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4443             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4444             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4445                 return false;
4446             }
4447             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4448             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4449             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4450                 return false;
4451             }
4452             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4453             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4454             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4455                 return false;
4456             }
4457         }
4458         catch ( final Exception e ) {
4459             e.printStackTrace( System.out );
4460             return false;
4461         }
4462         return true;
4463     }
4464
4465     private static boolean testMidpointrooting() {
4466         try {
4467             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4468             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4469             PhylogenyMethods.midpointRoot( t0 );
4470             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4471                 return false;
4472             }
4473             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4474                 return false;
4475             }
4476             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4477                            1 ) ) {
4478                 return false;
4479             }
4480             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",
4481                                                  new NHXParser() )[ 0 ];
4482             if ( !t1.isRooted() ) {
4483                 return false;
4484             }
4485             PhylogenyMethods.midpointRoot( t1 );
4486             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4487                 return false;
4488             }
4489             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4490                 return false;
4491             }
4492             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4493                 return false;
4494             }
4495             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4496                 return false;
4497             }
4498             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4499                 return false;
4500             }
4501             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4502                 return false;
4503             }
4504             t1.reRoot( t1.getNode( "A" ) );
4505             PhylogenyMethods.midpointRoot( t1 );
4506             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4507                 return false;
4508             }
4509             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4510                 return false;
4511             }
4512             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4513                 return false;
4514             }
4515             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4516                 return false;
4517             }
4518             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4519                 System.exit( -1 );
4520                 return false;
4521             }
4522             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4523                 return false;
4524             }
4525         }
4526         catch ( final Exception e ) {
4527             e.printStackTrace( System.out );
4528             return false;
4529         }
4530         return true;
4531     }
4532
4533     private static boolean testNexusCharactersParsing() {
4534         try {
4535             final NexusCharactersParser parser = new NexusCharactersParser();
4536             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4537             parser.parse();
4538             String[] labels = parser.getCharStateLabels();
4539             if ( labels.length != 7 ) {
4540                 return false;
4541             }
4542             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4543                 return false;
4544             }
4545             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4546                 return false;
4547             }
4548             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4549                 return false;
4550             }
4551             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4552                 return false;
4553             }
4554             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4555                 return false;
4556             }
4557             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4558                 return false;
4559             }
4560             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4561                 return false;
4562             }
4563             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4564             parser.parse();
4565             labels = parser.getCharStateLabels();
4566             if ( labels.length != 7 ) {
4567                 return false;
4568             }
4569             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4570                 return false;
4571             }
4572             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4573                 return false;
4574             }
4575             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4576                 return false;
4577             }
4578             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4579                 return false;
4580             }
4581             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4582                 return false;
4583             }
4584             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4585                 return false;
4586             }
4587             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4588                 return false;
4589             }
4590         }
4591         catch ( final Exception e ) {
4592             e.printStackTrace( System.out );
4593             return false;
4594         }
4595         return true;
4596     }
4597
4598     private static boolean testNexusMatrixParsing() {
4599         try {
4600             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4601             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4602             parser.parse();
4603             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4604             if ( m.getNumberOfCharacters() != 9 ) {
4605                 return false;
4606             }
4607             if ( m.getNumberOfIdentifiers() != 5 ) {
4608                 return false;
4609             }
4610             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4611                 return false;
4612             }
4613             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4614                 return false;
4615             }
4616             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4617                 return false;
4618             }
4619             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4620                 return false;
4621             }
4622             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4623                 return false;
4624             }
4625             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4626                 return false;
4627             }
4628             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4629                 return false;
4630             }
4631             //            if ( labels.length != 7 ) {
4632             //                return false;
4633             //            }
4634             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4635             //                return false;
4636             //            }
4637             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4638             //                return false;
4639             //            }
4640             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4641             //                return false;
4642             //            }
4643             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4644             //                return false;
4645             //            }
4646             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4647             //                return false;
4648             //            }
4649             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4650             //                return false;
4651             //            }
4652             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4653             //                return false;
4654             //            }
4655             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4656             //            parser.parse();
4657             //            labels = parser.getCharStateLabels();
4658             //            if ( labels.length != 7 ) {
4659             //                return false;
4660             //            }
4661             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4662             //                return false;
4663             //            }
4664             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4665             //                return false;
4666             //            }
4667             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4668             //                return false;
4669             //            }
4670             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4671             //                return false;
4672             //            }
4673             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4674             //                return false;
4675             //            }
4676             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4677             //                return false;
4678             //            }
4679             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4680             //                return false;
4681             //            }
4682         }
4683         catch ( final Exception e ) {
4684             e.printStackTrace( System.out );
4685             return false;
4686         }
4687         return true;
4688     }
4689
4690     private static boolean testNexusTreeParsing() {
4691         try {
4692             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4693             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4694             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4695             if ( phylogenies.length != 1 ) {
4696                 return false;
4697             }
4698             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4699                 return false;
4700             }
4701             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4702                 return false;
4703             }
4704             phylogenies = null;
4705             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4706             if ( phylogenies.length != 1 ) {
4707                 return false;
4708             }
4709             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4710                 return false;
4711             }
4712             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4713                 return false;
4714             }
4715             phylogenies = null;
4716             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4717             if ( phylogenies.length != 1 ) {
4718                 return false;
4719             }
4720             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4721                 return false;
4722             }
4723             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4724                 return false;
4725             }
4726             if ( phylogenies[ 0 ].isRooted() ) {
4727                 return false;
4728             }
4729             phylogenies = null;
4730             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4731             if ( phylogenies.length != 18 ) {
4732                 return false;
4733             }
4734             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4735                 return false;
4736             }
4737             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4738                 return false;
4739             }
4740             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4741                 return false;
4742             }
4743             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4744                 return false;
4745             }
4746             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4747                 return false;
4748             }
4749             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4750                 return false;
4751             }
4752             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4753                 return false;
4754             }
4755             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4756                 return false;
4757             }
4758             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4759                 return false;
4760             }
4761             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4762                 return false;
4763             }
4764             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4765                 return false;
4766             }
4767             if ( phylogenies[ 8 ].isRooted() ) {
4768                 return false;
4769             }
4770             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4771                 return false;
4772             }
4773             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4774                 return false;
4775             }
4776             if ( !phylogenies[ 9 ].isRooted() ) {
4777                 return false;
4778             }
4779             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4780                 return false;
4781             }
4782             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4783                 return false;
4784             }
4785             if ( !phylogenies[ 10 ].isRooted() ) {
4786                 return false;
4787             }
4788             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4789                 return false;
4790             }
4791             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4792                 return false;
4793             }
4794             if ( phylogenies[ 11 ].isRooted() ) {
4795                 return false;
4796             }
4797             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4798                 return false;
4799             }
4800             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4801                 return false;
4802             }
4803             if ( !phylogenies[ 12 ].isRooted() ) {
4804                 return false;
4805             }
4806             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4807                 return false;
4808             }
4809             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4810                 return false;
4811             }
4812             if ( !phylogenies[ 13 ].isRooted() ) {
4813                 return false;
4814             }
4815             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4816                 return false;
4817             }
4818             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4819                 return false;
4820             }
4821             if ( !phylogenies[ 14 ].isRooted() ) {
4822                 return false;
4823             }
4824             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4825                 return false;
4826             }
4827             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4828                 return false;
4829             }
4830             if ( phylogenies[ 15 ].isRooted() ) {
4831                 return false;
4832             }
4833             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4834                 return false;
4835             }
4836             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4837                 return false;
4838             }
4839             if ( !phylogenies[ 16 ].isRooted() ) {
4840                 return false;
4841             }
4842             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4843                 return false;
4844             }
4845             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4846                 return false;
4847             }
4848             if ( phylogenies[ 17 ].isRooted() ) {
4849                 return false;
4850             }
4851             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4852                 return false;
4853             }
4854         }
4855         catch ( final Exception e ) {
4856             e.printStackTrace( System.out );
4857             return false;
4858         }
4859         return true;
4860     }
4861
4862     private static boolean testNexusTreeParsingIterating() {
4863         try {
4864             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4865             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4866             if ( !p.hasNext() ) {
4867                 return false;
4868             }
4869             Phylogeny phy = p.next();
4870             if ( phy == null ) {
4871                 return false;
4872             }
4873             if ( phy.getNumberOfExternalNodes() != 25 ) {
4874                 return false;
4875             }
4876             if ( !phy.getName().equals( "" ) ) {
4877                 return false;
4878             }
4879             if ( p.hasNext() ) {
4880                 return false;
4881             }
4882             phy = p.next();
4883             if ( phy != null ) {
4884                 return false;
4885             }
4886             //
4887             p.reset();
4888             if ( !p.hasNext() ) {
4889                 return false;
4890             }
4891             phy = p.next();
4892             if ( phy == null ) {
4893                 return false;
4894             }
4895             if ( phy.getNumberOfExternalNodes() != 25 ) {
4896                 return false;
4897             }
4898             if ( !phy.getName().equals( "" ) ) {
4899                 return false;
4900             }
4901             if ( p.hasNext() ) {
4902                 return false;
4903             }
4904             phy = p.next();
4905             if ( phy != null ) {
4906                 return false;
4907             }
4908             ////
4909             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4910             if ( !p.hasNext() ) {
4911                 return false;
4912             }
4913             phy = p.next();
4914             if ( phy == null ) {
4915                 return false;
4916             }
4917             if ( phy.getNumberOfExternalNodes() != 10 ) {
4918                 return false;
4919             }
4920             if ( !phy.getName().equals( "name" ) ) {
4921                 return false;
4922             }
4923             if ( p.hasNext() ) {
4924                 return false;
4925             }
4926             phy = p.next();
4927             if ( phy != null ) {
4928                 return false;
4929             }
4930             //
4931             p.reset();
4932             if ( !p.hasNext() ) {
4933                 return false;
4934             }
4935             phy = p.next();
4936             if ( phy == null ) {
4937                 return false;
4938             }
4939             if ( phy.getNumberOfExternalNodes() != 10 ) {
4940                 return false;
4941             }
4942             if ( !phy.getName().equals( "name" ) ) {
4943                 return false;
4944             }
4945             if ( p.hasNext() ) {
4946                 return false;
4947             }
4948             phy = p.next();
4949             if ( phy != null ) {
4950                 return false;
4951             }
4952             ////
4953             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4954             if ( !p.hasNext() ) {
4955                 return false;
4956             }
4957             phy = p.next();
4958             if ( phy == null ) {
4959                 return false;
4960             }
4961             if ( phy.getNumberOfExternalNodes() != 3 ) {
4962                 return false;
4963             }
4964             if ( !phy.getName().equals( "" ) ) {
4965                 return false;
4966             }
4967             if ( phy.isRooted() ) {
4968                 return false;
4969             }
4970             if ( p.hasNext() ) {
4971                 return false;
4972             }
4973             phy = p.next();
4974             if ( phy != null ) {
4975                 return false;
4976             }
4977             //
4978             p.reset();
4979             if ( !p.hasNext() ) {
4980                 return false;
4981             }
4982             phy = p.next();
4983             if ( phy == null ) {
4984                 return false;
4985             }
4986             if ( phy.getNumberOfExternalNodes() != 3 ) {
4987                 return false;
4988             }
4989             if ( !phy.getName().equals( "" ) ) {
4990                 return false;
4991             }
4992             if ( p.hasNext() ) {
4993                 return false;
4994             }
4995             phy = p.next();
4996             if ( phy != null ) {
4997                 return false;
4998             }
4999             ////
5000             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
5001             //            if ( phylogenies.length != 18 ) {
5002             //                return false;
5003             //            }
5004             //0
5005             if ( !p.hasNext() ) {
5006                 return false;
5007             }
5008             phy = p.next();
5009             if ( phy == null ) {
5010                 return false;
5011             }
5012             if ( phy.getNumberOfExternalNodes() != 10 ) {
5013                 return false;
5014             }
5015             if ( !phy.getName().equals( "tree 0" ) ) {
5016                 return false;
5017             }
5018             //1
5019             if ( !p.hasNext() ) {
5020                 return false;
5021             }
5022             phy = p.next();
5023             if ( phy == null ) {
5024                 return false;
5025             }
5026             if ( phy.getNumberOfExternalNodes() != 10 ) {
5027                 return false;
5028             }
5029             if ( !phy.getName().equals( "tree 1" ) ) {
5030                 return false;
5031             }
5032             //2
5033             if ( !p.hasNext() ) {
5034                 return false;
5035             }
5036             phy = p.next();
5037             if ( phy == null ) {
5038                 return false;
5039             }
5040             if ( phy.getNumberOfExternalNodes() != 3 ) {
5041                 return false;
5042             }
5043             if ( !phy.getName().equals( "" ) ) {
5044                 return false;
5045             }
5046             if ( phy.isRooted() ) {
5047                 return false;
5048             }
5049             //3
5050             if ( !p.hasNext() ) {
5051                 return false;
5052             }
5053             phy = p.next();
5054             if ( phy == null ) {
5055                 return false;
5056             }
5057             if ( phy.getNumberOfExternalNodes() != 4 ) {
5058                 return false;
5059             }
5060             if ( !phy.getName().equals( "" ) ) {
5061                 return false;
5062             }
5063             if ( !phy.isRooted() ) {
5064                 return false;
5065             }
5066             //4
5067             if ( !p.hasNext() ) {
5068                 return false;
5069             }
5070             phy = p.next();
5071             if ( phy == null ) {
5072                 return false;
5073             }
5074             if ( phy.getNumberOfExternalNodes() != 5 ) {
5075                 System.out.println( phy.getNumberOfExternalNodes() );
5076                 return false;
5077             }
5078             if ( !phy.getName().equals( "" ) ) {
5079                 return false;
5080             }
5081             if ( !phy.isRooted() ) {
5082                 return false;
5083             }
5084             //5
5085             if ( !p.hasNext() ) {
5086                 return false;
5087             }
5088             phy = p.next();
5089             if ( phy == null ) {
5090                 return false;
5091             }
5092             if ( phy.getNumberOfExternalNodes() != 3 ) {
5093                 return false;
5094             }
5095             if ( !phy.getName().equals( "" ) ) {
5096                 return false;
5097             }
5098             if ( phy.isRooted() ) {
5099                 return false;
5100             }
5101             //6
5102             if ( !p.hasNext() ) {
5103                 return false;
5104             }
5105             phy = p.next();
5106             if ( phy == null ) {
5107                 return false;
5108             }
5109             if ( phy.getNumberOfExternalNodes() != 2 ) {
5110                 return false;
5111             }
5112             if ( !phy.getName().equals( "" ) ) {
5113                 return false;
5114             }
5115             if ( !phy.isRooted() ) {
5116                 return false;
5117             }
5118             //7
5119             if ( !p.hasNext() ) {
5120                 return false;
5121             }
5122             phy = p.next();
5123             if ( phy.getNumberOfExternalNodes() != 3 ) {
5124                 return false;
5125             }
5126             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5127                 return false;
5128             }
5129             if ( !phy.isRooted() ) {
5130                 return false;
5131             }
5132             //8
5133             if ( !p.hasNext() ) {
5134                 return false;
5135             }
5136             phy = p.next();
5137             if ( phy.getNumberOfExternalNodes() != 3 ) {
5138                 return false;
5139             }
5140             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
5141                 return false;
5142             }
5143             if ( !phy.getName().equals( "tree 8" ) ) {
5144                 return false;
5145             }
5146             //9
5147             if ( !p.hasNext() ) {
5148                 return false;
5149             }
5150             phy = p.next();
5151             if ( phy.getNumberOfExternalNodes() != 3 ) {
5152                 return false;
5153             }
5154             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5155                 return false;
5156             }
5157             if ( !phy.getName().equals( "tree 9" ) ) {
5158                 return false;
5159             }
5160             //10
5161             if ( !p.hasNext() ) {
5162                 return false;
5163             }
5164             phy = p.next();
5165             if ( phy.getNumberOfExternalNodes() != 3 ) {
5166                 return false;
5167             }
5168             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5169                 return false;
5170             }
5171             if ( !phy.getName().equals( "tree 10" ) ) {
5172                 return false;
5173             }
5174             if ( !phy.isRooted() ) {
5175                 return false;
5176             }
5177             //11
5178             if ( !p.hasNext() ) {
5179                 return false;
5180             }
5181             phy = p.next();
5182             if ( phy.getNumberOfExternalNodes() != 3 ) {
5183                 return false;
5184             }
5185             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5186                 return false;
5187             }
5188             if ( !phy.getName().equals( "tree 11" ) ) {
5189                 return false;
5190             }
5191             if ( phy.isRooted() ) {
5192                 return false;
5193             }
5194             //12
5195             if ( !p.hasNext() ) {
5196                 return false;
5197             }
5198             phy = p.next();
5199             if ( phy.getNumberOfExternalNodes() != 3 ) {
5200                 return false;
5201             }
5202             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5203                 return false;
5204             }
5205             if ( !phy.getName().equals( "tree 12" ) ) {
5206                 return false;
5207             }
5208             if ( !phy.isRooted() ) {
5209                 return false;
5210             }
5211             //13
5212             if ( !p.hasNext() ) {
5213                 return false;
5214             }
5215             phy = p.next();
5216             if ( phy.getNumberOfExternalNodes() != 3 ) {
5217                 return false;
5218             }
5219             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5220                 return false;
5221             }
5222             if ( !phy.getName().equals( "tree 13" ) ) {
5223                 return false;
5224             }
5225             if ( !phy.isRooted() ) {
5226                 return false;
5227             }
5228             //14
5229             if ( !p.hasNext() ) {
5230                 return false;
5231             }
5232             phy = p.next();
5233             if ( phy.getNumberOfExternalNodes() != 10 ) {
5234                 System.out.println( phy.getNumberOfExternalNodes() );
5235                 return false;
5236             }
5237             if ( !phy
5238                     .toNewHampshire()
5239                     .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;" ) ) {
5240                 System.out.println( phy.toNewHampshire() );
5241                 return false;
5242             }
5243             if ( !phy.getName().equals( "tree 14" ) ) {
5244                 return false;
5245             }
5246             if ( !phy.isRooted() ) {
5247                 return false;
5248             }
5249             //15
5250             if ( !p.hasNext() ) {
5251                 return false;
5252             }
5253             phy = p.next();
5254             if ( phy.getNumberOfExternalNodes() != 10 ) {
5255                 System.out.println( phy.getNumberOfExternalNodes() );
5256                 return false;
5257             }
5258             if ( !phy
5259                     .toNewHampshire()
5260                     .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;" ) ) {
5261                 System.out.println( phy.toNewHampshire() );
5262                 return false;
5263             }
5264             if ( !phy.getName().equals( "tree 15" ) ) {
5265                 return false;
5266             }
5267             if ( phy.isRooted() ) {
5268                 return false;
5269             }
5270             //16
5271             if ( !p.hasNext() ) {
5272                 return false;
5273             }
5274             phy = p.next();
5275             if ( phy.getNumberOfExternalNodes() != 10 ) {
5276                 System.out.println( phy.getNumberOfExternalNodes() );
5277                 return false;
5278             }
5279             if ( !phy
5280                     .toNewHampshire()
5281                     .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;" ) ) {
5282                 System.out.println( phy.toNewHampshire() );
5283                 return false;
5284             }
5285             if ( !phy.getName().equals( "tree 16" ) ) {
5286                 return false;
5287             }
5288             if ( !phy.isRooted() ) {
5289                 return false;
5290             }
5291             //17
5292             if ( !p.hasNext() ) {
5293                 return false;
5294             }
5295             phy = p.next();
5296             if ( phy.getNumberOfExternalNodes() != 10 ) {
5297                 System.out.println( phy.getNumberOfExternalNodes() );
5298                 return false;
5299             }
5300             if ( !phy
5301                     .toNewHampshire()
5302                     .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;" ) ) {
5303                 System.out.println( phy.toNewHampshire() );
5304                 return false;
5305             }
5306             if ( !phy.getName().equals( "tree 17" ) ) {
5307                 return false;
5308             }
5309             if ( phy.isRooted() ) {
5310                 return false;
5311             }
5312             //
5313             if ( p.hasNext() ) {
5314                 return false;
5315             }
5316             phy = p.next();
5317             if ( phy != null ) {
5318                 return false;
5319             }
5320             p.reset();
5321             //0
5322             if ( !p.hasNext() ) {
5323                 return false;
5324             }
5325             phy = p.next();
5326             if ( phy == null ) {
5327                 return false;
5328             }
5329             if ( phy.getNumberOfExternalNodes() != 10 ) {
5330                 return false;
5331             }
5332             if ( !phy.getName().equals( "tree 0" ) ) {
5333                 return false;
5334             }
5335             //1
5336             if ( !p.hasNext() ) {
5337                 return false;
5338             }
5339             phy = p.next();
5340             if ( phy == null ) {
5341                 return false;
5342             }
5343             if ( phy.getNumberOfExternalNodes() != 10 ) {
5344                 return false;
5345             }
5346             if ( !phy.getName().equals( "tree 1" ) ) {
5347                 return false;
5348             }
5349             //2
5350             if ( !p.hasNext() ) {
5351                 return false;
5352             }
5353             phy = p.next();
5354             if ( phy == null ) {
5355                 return false;
5356             }
5357             if ( phy.getNumberOfExternalNodes() != 3 ) {
5358                 return false;
5359             }
5360             if ( !phy.getName().equals( "" ) ) {
5361                 return false;
5362             }
5363             if ( phy.isRooted() ) {
5364                 return false;
5365             }
5366             //3
5367             if ( !p.hasNext() ) {
5368                 return false;
5369             }
5370             phy = p.next();
5371             if ( phy == null ) {
5372                 return false;
5373             }
5374             if ( phy.getNumberOfExternalNodes() != 4 ) {
5375                 return false;
5376             }
5377             if ( !phy.getName().equals( "" ) ) {
5378                 return false;
5379             }
5380             if ( !phy.isRooted() ) {
5381                 return false;
5382             }
5383             //4
5384             if ( !p.hasNext() ) {
5385                 return false;
5386             }
5387             phy = p.next();
5388             if ( phy == null ) {
5389                 return false;
5390             }
5391             if ( phy.getNumberOfExternalNodes() != 5 ) {
5392                 System.out.println( phy.getNumberOfExternalNodes() );
5393                 return false;
5394             }
5395             if ( !phy.getName().equals( "" ) ) {
5396                 return false;
5397             }
5398             if ( !phy.isRooted() ) {
5399                 return false;
5400             }
5401             //5
5402             if ( !p.hasNext() ) {
5403                 return false;
5404             }
5405             phy = p.next();
5406             if ( phy == null ) {
5407                 return false;
5408             }
5409             if ( phy.getNumberOfExternalNodes() != 3 ) {
5410                 return false;
5411             }
5412             if ( !phy.getName().equals( "" ) ) {
5413                 return false;
5414             }
5415             if ( phy.isRooted() ) {
5416                 return false;
5417             }
5418         }
5419         catch ( final Exception e ) {
5420             e.printStackTrace( System.out );
5421             return false;
5422         }
5423         return true;
5424     }
5425
5426     private static boolean testNexusTreeParsingTranslating() {
5427         try {
5428             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5429             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5430             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5431             if ( phylogenies.length != 1 ) {
5432                 return false;
5433             }
5434             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5435                 return false;
5436             }
5437             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5438                 return false;
5439             }
5440             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5441                 return false;
5442             }
5443             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5444                 return false;
5445             }
5446             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5447                     .equals( "Aranaeus" ) ) {
5448                 return false;
5449             }
5450             phylogenies = null;
5451             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5452             if ( phylogenies.length != 3 ) {
5453                 return false;
5454             }
5455             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5456                 return false;
5457             }
5458             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5459                 return false;
5460             }
5461             if ( phylogenies[ 0 ].isRooted() ) {
5462                 return false;
5463             }
5464             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5465                 return false;
5466             }
5467             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5468                 return false;
5469             }
5470             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5471                     .equals( "Aranaeus" ) ) {
5472                 return false;
5473             }
5474             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5475                 return false;
5476             }
5477             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5478                 return false;
5479             }
5480             if ( phylogenies[ 1 ].isRooted() ) {
5481                 return false;
5482             }
5483             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5484                 return false;
5485             }
5486             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5487                 return false;
5488             }
5489             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5490                     .equals( "Aranaeus" ) ) {
5491                 return false;
5492             }
5493             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5494                 return false;
5495             }
5496             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5497                 return false;
5498             }
5499             if ( !phylogenies[ 2 ].isRooted() ) {
5500                 return false;
5501             }
5502             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5503                 return false;
5504             }
5505             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5506                 return false;
5507             }
5508             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5509                     .equals( "Aranaeus" ) ) {
5510                 return false;
5511             }
5512             phylogenies = null;
5513             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5514             if ( phylogenies.length != 3 ) {
5515                 return false;
5516             }
5517             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5518                 return false;
5519             }
5520             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5521                 return false;
5522             }
5523             if ( phylogenies[ 0 ].isRooted() ) {
5524                 return false;
5525             }
5526             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5527                 return false;
5528             }
5529             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5530                 return false;
5531             }
5532             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5533                     .equals( "Aranaeus" ) ) {
5534                 return false;
5535             }
5536             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5537                 return false;
5538             }
5539             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5540                 return false;
5541             }
5542             if ( phylogenies[ 1 ].isRooted() ) {
5543                 return false;
5544             }
5545             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5546                 return false;
5547             }
5548             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5549                 return false;
5550             }
5551             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5552                     .equals( "Aranaeus" ) ) {
5553                 return false;
5554             }
5555             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5556                 return false;
5557             }
5558             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5559                 return false;
5560             }
5561             if ( !phylogenies[ 2 ].isRooted() ) {
5562                 return false;
5563             }
5564             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5565                 return false;
5566             }
5567             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5568                 return false;
5569             }
5570             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5571                     .equals( "Aranaeus" ) ) {
5572                 return false;
5573             }
5574         }
5575         catch ( final Exception e ) {
5576             e.printStackTrace( System.out );
5577             return false;
5578         }
5579         return true;
5580     }
5581
5582     private static boolean testNHParsing() {
5583         try {
5584             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5585             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5586             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5587                 return false;
5588             }
5589             final NHXParser nhxp = new NHXParser();
5590             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5591             nhxp.setReplaceUnderscores( true );
5592             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5593             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5594                 return false;
5595             }
5596             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5597                 return false;
5598             }
5599             final Phylogeny p1b = factory
5600                     .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 ",
5601                              new NHXParser() )[ 0 ];
5602             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5603                 return false;
5604             }
5605             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5606                 return false;
5607             }
5608             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5609             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5610             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5611             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5612             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5613             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5614             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5615             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5616             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5617             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5618             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
5619                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5620                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
5621                                                     new NHXParser() );
5622             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5623                 return false;
5624             }
5625             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5626                 return false;
5627             }
5628             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5629                 return false;
5630             }
5631             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5632                 return false;
5633             }
5634             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5635             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5636             final String p16_S = "((A,B),C)";
5637             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5638             if ( p16.length != 1 ) {
5639                 return false;
5640             }
5641             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5642                 return false;
5643             }
5644             final String p17_S = "(C,(A,B))";
5645             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5646             if ( p17.length != 1 ) {
5647                 return false;
5648             }
5649             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5650                 return false;
5651             }
5652             final String p18_S = "((A,B),(C,D))";
5653             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5654             if ( p18.length != 1 ) {
5655                 return false;
5656             }
5657             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5658                 return false;
5659             }
5660             final String p19_S = "(((A,B),C),D)";
5661             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5662             if ( p19.length != 1 ) {
5663                 return false;
5664             }
5665             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5666                 return false;
5667             }
5668             final String p20_S = "(A,(B,(C,D)))";
5669             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5670             if ( p20.length != 1 ) {
5671                 return false;
5672             }
5673             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5674                 return false;
5675             }
5676             final String p21_S = "(A,(B,(C,(D,E))))";
5677             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5678             if ( p21.length != 1 ) {
5679                 return false;
5680             }
5681             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5682                 return false;
5683             }
5684             final String p22_S = "((((A,B),C),D),E)";
5685             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5686             if ( p22.length != 1 ) {
5687                 return false;
5688             }
5689             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5690                 return false;
5691             }
5692             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5693             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5694             if ( p23.length != 1 ) {
5695                 System.out.println( "xl=" + p23.length );
5696                 System.exit( -1 );
5697                 return false;
5698             }
5699             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5700                 return false;
5701             }
5702             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5703             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5704             if ( p24.length != 1 ) {
5705                 return false;
5706             }
5707             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5708                 return false;
5709             }
5710             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5711             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5712             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5713             if ( p241.length != 2 ) {
5714                 return false;
5715             }
5716             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5717                 return false;
5718             }
5719             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5720                 return false;
5721             }
5722             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5723                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5724                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5725                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5726                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5727                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5728                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5729                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5730             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5731             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5732                 return false;
5733             }
5734             final String p26_S = "(A,B)ab";
5735             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5736             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5737                 return false;
5738             }
5739             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5740             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5741             if ( p27s.length != 1 ) {
5742                 System.out.println( "xxl=" + p27s.length );
5743                 System.exit( -1 );
5744                 return false;
5745             }
5746             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5747                 System.out.println( p27s[ 0 ].toNewHampshireX() );
5748                 System.exit( -1 );
5749                 return false;
5750             }
5751             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5752                                                     new NHXParser() );
5753             if ( p27.length != 1 ) {
5754                 System.out.println( "yl=" + p27.length );
5755                 System.exit( -1 );
5756                 return false;
5757             }
5758             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5759                 System.out.println( p27[ 0 ].toNewHampshireX() );
5760                 System.exit( -1 );
5761                 return false;
5762             }
5763             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5764             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5765             final String p28_S3 = "(A,B)ab";
5766             final String p28_S4 = "((((A,B),C),D),;E;)";
5767             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5768                                                     new NHXParser() );
5769             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5770                 return false;
5771             }
5772             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5773                 return false;
5774             }
5775             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5776                 return false;
5777             }
5778             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5779                 return false;
5780             }
5781             if ( p28.length != 4 ) {
5782                 return false;
5783             }
5784             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";
5785             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5786             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5787                 return false;
5788             }
5789             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";
5790             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5791             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5792                 return false;
5793             }
5794             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
5795             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5796             if ( ( p32.length != 0 ) ) {
5797                 return false;
5798             }
5799             final String p33_S = "A";
5800             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5801             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5802                 return false;
5803             }
5804             final String p34_S = "B;";
5805             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5806             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5807                 return false;
5808             }
5809             final String p35_S = "B:0.2";
5810             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5811             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5812                 return false;
5813             }
5814             final String p36_S = "(A)";
5815             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5816             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5817                 return false;
5818             }
5819             final String p37_S = "((A))";
5820             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5821             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5822                 return false;
5823             }
5824             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5825             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5826             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5827                 return false;
5828             }
5829             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5830             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5831             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5832                 return false;
5833             }
5834             final String p40_S = "(A,B,C)";
5835             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5836             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5837                 return false;
5838             }
5839             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5840             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5841             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5842                 return false;
5843             }
5844             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5845             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5846             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5847                 return false;
5848             }
5849             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)";
5850             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5851             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5852                 return false;
5853             }
5854             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)))";
5855             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5856             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5857                 return false;
5858             }
5859             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5860             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5861             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5862                 return false;
5863             }
5864             final String p46_S = "";
5865             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5866             if ( p46.length != 0 ) {
5867                 return false;
5868             }
5869             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5870             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5871                 return false;
5872             }
5873             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5874             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5875                 return false;
5876             }
5877             final Phylogeny p49 = factory
5878                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5879                              new NHXParser() )[ 0 ];
5880             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5881                 return false;
5882             }
5883             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5884             if ( p50.getNode( "A" ) == null ) {
5885                 return false;
5886             }
5887             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5888                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
5889                 return false;
5890             }
5891             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5892                 return false;
5893             }
5894             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5895                     .equals( "((A,B)88:2.0,C);" ) ) {
5896                 return false;
5897             }
5898             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5899             if ( p51.getNode( "A(A" ) == null ) {
5900                 return false;
5901             }
5902             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5903             if ( p52.getNode( "A(A" ) == null ) {
5904                 return false;
5905             }
5906             final Phylogeny p53 = factory
5907                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5908                              new NHXParser() )[ 0 ];
5909             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5910                 return false;
5911             }
5912             // 
5913             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5914             if ( p54.getNode( "A" ) == null ) {
5915                 return false;
5916             }
5917             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5918                     .equals( "((A,B)[88],C);" ) ) {
5919                 return false;
5920             }
5921         }
5922         catch ( final Exception e ) {
5923             e.printStackTrace( System.out );
5924             return false;
5925         }
5926         return true;
5927     }
5928
5929     private static boolean testNHParsingIter() {
5930         try {
5931             final String p0_str = "(A,B);";
5932             final NHXParser p = new NHXParser();
5933             p.setSource( p0_str );
5934             if ( !p.hasNext() ) {
5935                 return false;
5936             }
5937             final Phylogeny p0 = p.next();
5938             if ( !p0.toNewHampshire().equals( p0_str ) ) {
5939                 System.out.println( p0.toNewHampshire() );
5940                 return false;
5941             }
5942             if ( p.hasNext() ) {
5943                 return false;
5944             }
5945             if ( p.next() != null ) {
5946                 return false;
5947             }
5948             //
5949             final String p00_str = "(A,B)root;";
5950             p.setSource( p00_str );
5951             final Phylogeny p00 = p.next();
5952             if ( !p00.toNewHampshire().equals( p00_str ) ) {
5953                 System.out.println( p00.toNewHampshire() );
5954                 return false;
5955             }
5956             //
5957             final String p000_str = "A;";
5958             p.setSource( p000_str );
5959             final Phylogeny p000 = p.next();
5960             if ( !p000.toNewHampshire().equals( p000_str ) ) {
5961                 System.out.println( p000.toNewHampshire() );
5962                 return false;
5963             }
5964             //
5965             final String p0000_str = "A";
5966             p.setSource( p0000_str );
5967             final Phylogeny p0000 = p.next();
5968             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5969                 System.out.println( p0000.toNewHampshire() );
5970                 return false;
5971             }
5972             //
5973             p.setSource( "(A)" );
5974             final Phylogeny p00000 = p.next();
5975             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5976                 System.out.println( p00000.toNewHampshire() );
5977                 return false;
5978             }
5979             //
5980             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5981             p.setSource( p1_str );
5982             if ( !p.hasNext() ) {
5983                 return false;
5984             }
5985             final Phylogeny p1_0 = p.next();
5986             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5987                 System.out.println( p1_0.toNewHampshire() );
5988                 return false;
5989             }
5990             if ( !p.hasNext() ) {
5991                 return false;
5992             }
5993             final Phylogeny p1_1 = p.next();
5994             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5995                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5996                 return false;
5997             }
5998             if ( !p.hasNext() ) {
5999                 return false;
6000             }
6001             final Phylogeny p1_2 = p.next();
6002             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
6003                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
6004                 return false;
6005             }
6006             if ( !p.hasNext() ) {
6007                 return false;
6008             }
6009             final Phylogeny p1_3 = p.next();
6010             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
6011                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
6012                 return false;
6013             }
6014             if ( p.hasNext() ) {
6015                 return false;
6016             }
6017             if ( p.next() != null ) {
6018                 return false;
6019             }
6020             //
6021             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
6022             p.setSource( p2_str );
6023             if ( !p.hasNext() ) {
6024                 return false;
6025             }
6026             Phylogeny p2_0 = p.next();
6027             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
6028                 System.out.println( p2_0.toNewHampshire() );
6029                 return false;
6030             }
6031             if ( !p.hasNext() ) {
6032                 return false;
6033             }
6034             Phylogeny p2_1 = p.next();
6035             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6036                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6037                 return false;
6038             }
6039             if ( !p.hasNext() ) {
6040                 return false;
6041             }
6042             Phylogeny p2_2 = p.next();
6043             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6044                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6045                 return false;
6046             }
6047             if ( !p.hasNext() ) {
6048                 return false;
6049             }
6050             Phylogeny p2_3 = p.next();
6051             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6052                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6053                 return false;
6054             }
6055             if ( !p.hasNext() ) {
6056                 return false;
6057             }
6058             Phylogeny p2_4 = p.next();
6059             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6060                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6061                 return false;
6062             }
6063             if ( p.hasNext() ) {
6064                 return false;
6065             }
6066             if ( p.next() != null ) {
6067                 return false;
6068             }
6069             ////
6070             p.reset();
6071             if ( !p.hasNext() ) {
6072                 return false;
6073             }
6074             p2_0 = p.next();
6075             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
6076                 System.out.println( p2_0.toNewHampshire() );
6077                 return false;
6078             }
6079             if ( !p.hasNext() ) {
6080                 return false;
6081             }
6082             p2_1 = p.next();
6083             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6084                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6085                 return false;
6086             }
6087             if ( !p.hasNext() ) {
6088                 return false;
6089             }
6090             p2_2 = p.next();
6091             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6092                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6093                 return false;
6094             }
6095             if ( !p.hasNext() ) {
6096                 return false;
6097             }
6098             p2_3 = p.next();
6099             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6100                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6101                 return false;
6102             }
6103             if ( !p.hasNext() ) {
6104                 return false;
6105             }
6106             p2_4 = p.next();
6107             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6108                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6109                 return false;
6110             }
6111             if ( p.hasNext() ) {
6112                 return false;
6113             }
6114             if ( p.next() != null ) {
6115                 return false;
6116             }
6117             //
6118             final String p3_str = "((A,B),C)abc";
6119             p.setSource( p3_str );
6120             if ( !p.hasNext() ) {
6121                 return false;
6122             }
6123             final Phylogeny p3_0 = p.next();
6124             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
6125                 return false;
6126             }
6127             if ( p.hasNext() ) {
6128                 return false;
6129             }
6130             if ( p.next() != null ) {
6131                 return false;
6132             }
6133             //
6134             final String p4_str = "((A,B)ab,C)abc";
6135             p.setSource( p4_str );
6136             if ( !p.hasNext() ) {
6137                 return false;
6138             }
6139             final Phylogeny p4_0 = p.next();
6140             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
6141                 return false;
6142             }
6143             if ( p.hasNext() ) {
6144                 return false;
6145             }
6146             if ( p.next() != null ) {
6147                 return false;
6148             }
6149             //
6150             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6151             p.setSource( p5_str );
6152             if ( !p.hasNext() ) {
6153                 return false;
6154             }
6155             final Phylogeny p5_0 = p.next();
6156             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6157                 return false;
6158             }
6159             if ( p.hasNext() ) {
6160                 return false;
6161             }
6162             if ( p.next() != null ) {
6163                 return false;
6164             }
6165             //
6166             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6167             p.setSource( p6_str );
6168             if ( !p.hasNext() ) {
6169                 return false;
6170             }
6171             Phylogeny p6_0 = p.next();
6172             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6173                 return false;
6174             }
6175             if ( p.hasNext() ) {
6176                 return false;
6177             }
6178             if ( p.next() != null ) {
6179                 return false;
6180             }
6181             p.reset();
6182             if ( !p.hasNext() ) {
6183                 return false;
6184             }
6185             p6_0 = p.next();
6186             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6187                 return false;
6188             }
6189             if ( p.hasNext() ) {
6190                 return false;
6191             }
6192             if ( p.next() != null ) {
6193                 return false;
6194             }
6195             //
6196             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6197             p.setSource( p7_str );
6198             if ( !p.hasNext() ) {
6199                 return false;
6200             }
6201             Phylogeny p7_0 = p.next();
6202             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6203                 return false;
6204             }
6205             if ( p.hasNext() ) {
6206                 return false;
6207             }
6208             if ( p.next() != null ) {
6209                 return false;
6210             }
6211             p.reset();
6212             if ( !p.hasNext() ) {
6213                 return false;
6214             }
6215             p7_0 = p.next();
6216             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6217                 return false;
6218             }
6219             if ( p.hasNext() ) {
6220                 return false;
6221             }
6222             if ( p.next() != null ) {
6223                 return false;
6224             }
6225             //
6226             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6227             p.setSource( p8_str );
6228             if ( !p.hasNext() ) {
6229                 return false;
6230             }
6231             Phylogeny p8_0 = p.next();
6232             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6233                 return false;
6234             }
6235             if ( !p.hasNext() ) {
6236                 return false;
6237             }
6238             if ( !p.hasNext() ) {
6239                 return false;
6240             }
6241             Phylogeny p8_1 = p.next();
6242             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6243                 return false;
6244             }
6245             if ( p.hasNext() ) {
6246                 return false;
6247             }
6248             if ( p.next() != null ) {
6249                 return false;
6250             }
6251             p.reset();
6252             if ( !p.hasNext() ) {
6253                 return false;
6254             }
6255             p8_0 = p.next();
6256             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6257                 return false;
6258             }
6259             if ( !p.hasNext() ) {
6260                 return false;
6261             }
6262             p8_1 = p.next();
6263             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6264                 return false;
6265             }
6266             if ( p.hasNext() ) {
6267                 return false;
6268             }
6269             if ( p.next() != null ) {
6270                 return false;
6271             }
6272             p.reset();
6273             //
6274             p.setSource( "" );
6275             if ( p.hasNext() ) {
6276                 return false;
6277             }
6278             //
6279             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6280             if ( !p.hasNext() ) {
6281                 return false;
6282             }
6283             Phylogeny p_27 = p.next();
6284             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6285                 System.out.println( p_27.toNewHampshireX() );
6286                 System.exit( -1 );
6287                 return false;
6288             }
6289             if ( p.hasNext() ) {
6290                 return false;
6291             }
6292             if ( p.next() != null ) {
6293                 return false;
6294             }
6295             p.reset();
6296             if ( !p.hasNext() ) {
6297                 return false;
6298             }
6299             p_27 = p.next();
6300             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6301                 System.out.println( p_27.toNewHampshireX() );
6302                 System.exit( -1 );
6303                 return false;
6304             }
6305             if ( p.hasNext() ) {
6306                 return false;
6307             }
6308             if ( p.next() != null ) {
6309                 return false;
6310             }
6311         }
6312         catch ( final Exception e ) {
6313             e.printStackTrace( System.out );
6314             return false;
6315         }
6316         return true;
6317     }
6318
6319     private static boolean testNHXconversion() {
6320         try {
6321             final PhylogenyNode n1 = new PhylogenyNode();
6322             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6323             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6324             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6325             final PhylogenyNode n5 = PhylogenyNode
6326                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6327             final PhylogenyNode n6 = PhylogenyNode
6328                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6329             if ( !n1.toNewHampshireX().equals( "" ) ) {
6330                 return false;
6331             }
6332             if ( !n2.toNewHampshireX().equals( "" ) ) {
6333                 return false;
6334             }
6335             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6336                 return false;
6337             }
6338             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6339                 return false;
6340             }
6341             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6342                 return false;
6343             }
6344             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6345                 System.out.println( n6.toNewHampshireX() );
6346                 return false;
6347             }
6348         }
6349         catch ( final Exception e ) {
6350             e.printStackTrace( System.out );
6351             return false;
6352         }
6353         return true;
6354     }
6355
6356     private static boolean testTaxonomyExtraction() {
6357         try {
6358             final PhylogenyNode n0 = PhylogenyNode
6359                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6360             if ( n0.getNodeData().isHasTaxonomy() ) {
6361                 return false;
6362             }
6363             final PhylogenyNode n1 = PhylogenyNode
6364                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6365             if ( n1.getNodeData().isHasTaxonomy() ) {
6366                 System.out.println( n1.toString() );
6367                 return false;
6368             }
6369             final PhylogenyNode n2x = PhylogenyNode
6370                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6371             if ( n2x.getNodeData().isHasTaxonomy() ) {
6372                 return false;
6373             }
6374             final PhylogenyNode n3 = PhylogenyNode
6375                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6376             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6377                 System.out.println( n3.toString() );
6378                 return false;
6379             }
6380             final PhylogenyNode n4 = PhylogenyNode
6381                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6382             if ( n4.getNodeData().isHasTaxonomy() ) {
6383                 System.out.println( n4.toString() );
6384                 return false;
6385             }
6386             final PhylogenyNode n5 = PhylogenyNode
6387                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6388             if ( n5.getNodeData().isHasTaxonomy() ) {
6389                 System.out.println( n5.toString() );
6390                 return false;
6391             }
6392             final PhylogenyNode n6 = PhylogenyNode
6393                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6394             if ( n6.getNodeData().isHasTaxonomy() ) {
6395                 System.out.println( n6.toString() );
6396                 return false;
6397             }
6398             final PhylogenyNode n7 = PhylogenyNode
6399                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6400             if ( n7.getNodeData().isHasTaxonomy() ) {
6401                 System.out.println( n7.toString() );
6402                 return false;
6403             }
6404             final PhylogenyNode n8 = PhylogenyNode
6405                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6406             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6407                 System.out.println( n8.toString() );
6408                 return false;
6409             }
6410             final PhylogenyNode n9 = PhylogenyNode
6411                     .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6412             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6413                 System.out.println( n9.toString() );
6414                 return false;
6415             }
6416             final PhylogenyNode n10x = PhylogenyNode
6417                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6418             if ( n10x.getNodeData().isHasTaxonomy() ) {
6419                 System.out.println( n10x.toString() );
6420                 return false;
6421             }
6422             final PhylogenyNode n10xx = PhylogenyNode
6423                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6424             if ( n10xx.getNodeData().isHasTaxonomy() ) {
6425                 System.out.println( n10xx.toString() );
6426                 return false;
6427             }
6428             final PhylogenyNode n10 = PhylogenyNode
6429                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6430             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6431                 System.out.println( n10.toString() );
6432                 return false;
6433             }
6434             final PhylogenyNode n11 = PhylogenyNode
6435                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6436             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6437                 System.out.println( n11.toString() );
6438                 return false;
6439             }
6440             final PhylogenyNode n12 = PhylogenyNode
6441                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
6442                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6443             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6444                 System.out.println( n12.toString() );
6445                 return false;
6446             }
6447             final PhylogenyNode n13 = PhylogenyNode
6448                     .createInstanceFromNhxString( "BLAG_Mus_musculus1",
6449                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6450             if ( n13.getNodeData().isHasTaxonomy() ) {
6451                 System.out.println( n13.toString() );
6452                 return false;
6453             }
6454             final PhylogenyNode n14 = PhylogenyNode
6455                     .createInstanceFromNhxString( "BLAG_Mus_musculus_11",
6456                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6457             if ( n14.getNodeData().isHasTaxonomy() ) {
6458                 System.out.println( n14.toString() );
6459                 return false;
6460             }
6461             final PhylogenyNode n16 = PhylogenyNode
6462                     .createInstanceFromNhxString( "BLAG_Mus_musculus_/11",
6463                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6464             if ( n16.getNodeData().isHasTaxonomy() ) {
6465                 System.out.println( n16.toString() );
6466                 return false;
6467             }
6468         }
6469         catch ( final Exception e ) {
6470             e.printStackTrace( System.out );
6471             return false;
6472         }
6473         return true;
6474     }
6475
6476     private static boolean testNHXNodeParsing() {
6477         try {
6478             final PhylogenyNode n1 = new PhylogenyNode();
6479             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6480             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6481             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6482             final PhylogenyNode n5 = PhylogenyNode
6483                     .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]" );
6484             if ( !n3.getName().equals( "n3" ) ) {
6485                 return false;
6486             }
6487             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6488                 return false;
6489             }
6490             if ( n3.isDuplication() ) {
6491                 return false;
6492             }
6493             if ( n3.isHasAssignedEvent() ) {
6494                 return false;
6495             }
6496             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6497                 return false;
6498             }
6499             if ( !n4.getName().equals( "n4" ) ) {
6500                 return false;
6501             }
6502             if ( n4.getDistanceToParent() != 0.01 ) {
6503                 return false;
6504             }
6505             if ( !n5.getName().equals( "n5" ) ) {
6506                 return false;
6507             }
6508             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6509                 return false;
6510             }
6511             if ( n5.getDistanceToParent() != 0.1 ) {
6512                 return false;
6513             }
6514             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6515                 return false;
6516             }
6517             if ( !n5.isDuplication() ) {
6518                 return false;
6519             }
6520             if ( !n5.isHasAssignedEvent() ) {
6521                 return false;
6522             }
6523             final PhylogenyNode n8 = PhylogenyNode
6524                     .createInstanceFromNhxString( "N8_ECOLI/1-2:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6525             if ( !n8.getName().equals( "N8_ECOLI/1-2" ) ) {
6526                 return false;
6527             }
6528             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6529                 return false;
6530             }
6531             final PhylogenyNode n9 = PhylogenyNode
6532                     .createInstanceFromNhxString( "N9_ECOLI/1-12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6533             if ( !n9.getName().equals( "N9_ECOLI/1-12" ) ) {
6534                 return false;
6535             }
6536             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6537                 return false;
6538             }
6539             final PhylogenyNode n10 = PhylogenyNode
6540                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6541             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6542                 return false;
6543             }
6544             final PhylogenyNode n20 = PhylogenyNode
6545                     .createInstanceFromNhxString( "N20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6546             if ( !n20.getName().equals( "N20_ECOLI/1-2" ) ) {
6547                 return false;
6548             }
6549             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6550                 return false;
6551             }
6552             final PhylogenyNode n20x = PhylogenyNode
6553                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6554             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
6555                 return false;
6556             }
6557             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6558                 return false;
6559             }
6560             final PhylogenyNode n20xx = PhylogenyNode
6561                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6562             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
6563                 return false;
6564             }
6565             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6566                 return false;
6567             }
6568             final PhylogenyNode n20xxx = PhylogenyNode
6569                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6570             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6571                 return false;
6572             }
6573             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6574                 return false;
6575             }
6576             final PhylogenyNode n20xxxx = PhylogenyNode
6577                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6578             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6579                 return false;
6580             }
6581             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6582                 return false;
6583             }
6584             final PhylogenyNode n21 = PhylogenyNode
6585                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6586             if ( !n21.getName().equals( "N21_PIG" ) ) {
6587                 return false;
6588             }
6589             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6590                 return false;
6591             }
6592             final PhylogenyNode n21x = PhylogenyNode
6593                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6594             if ( !n21x.getName().equals( "n21_PIG" ) ) {
6595                 return false;
6596             }
6597             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6598                 return false;
6599             }
6600             final PhylogenyNode n22 = PhylogenyNode
6601                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6602             if ( !n22.getName().equals( "n22/PIG" ) ) {
6603                 return false;
6604             }
6605             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6606                 return false;
6607             }
6608             final PhylogenyNode n23 = PhylogenyNode
6609                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6610             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6611                 return false;
6612             }
6613             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6614                 return false;
6615             }
6616             final PhylogenyNode a = PhylogenyNode
6617                     .createInstanceFromNhxString( "N10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6618             if ( !a.getName().equals( "N10_ECOLI/1-2" ) ) {
6619                 return false;
6620             }
6621             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6622                 return false;
6623             }
6624             final PhylogenyNode c1 = PhylogenyNode
6625                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6626                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6627             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6628                 return false;
6629             }
6630             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6631                 return false;
6632             }
6633             final PhylogenyNode c2 = PhylogenyNode
6634                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6635                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6636             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6637                 return false;
6638             }
6639             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6640                 return false;
6641             }
6642             final PhylogenyNode e3 = PhylogenyNode
6643                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6644             if ( !e3.getName().equals( "n10_RAT~" ) ) {
6645                 return false;
6646             }
6647             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6648                 return false;
6649             }
6650             final PhylogenyNode n11 = PhylogenyNode
6651                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
6652                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6653             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
6654                 return false;
6655             }
6656             if ( n11.getDistanceToParent() != 0.4 ) {
6657                 return false;
6658             }
6659             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6660                 return false;
6661             }
6662             final PhylogenyNode n12 = PhylogenyNode
6663                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6664                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6665             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6666                 return false;
6667             }
6668             if ( n12.getDistanceToParent() != 0.4 ) {
6669                 return false;
6670             }
6671             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6672                 return false;
6673             }
6674             final PhylogenyNode o = PhylogenyNode
6675                     .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6676             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6677                 return false;
6678             }
6679             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6680                 return false;
6681             }
6682             if ( n1.getName().compareTo( "" ) != 0 ) {
6683                 return false;
6684             }
6685             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6686                 return false;
6687             }
6688             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6689                 return false;
6690             }
6691             if ( n2.getName().compareTo( "" ) != 0 ) {
6692                 return false;
6693             }
6694             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6695                 return false;
6696             }
6697             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6698                 return false;
6699             }
6700             final PhylogenyNode n00 = PhylogenyNode
6701                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6702             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6703                 return false;
6704             }
6705             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6706                 return false;
6707             }
6708             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6709             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6710                 return false;
6711             }
6712             final PhylogenyNode n13 = PhylogenyNode
6713                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6714             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6715                 return false;
6716             }
6717             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6718                 return false;
6719             }
6720             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6721                 return false;
6722             }
6723             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6724                 return false;
6725             }
6726             final PhylogenyNode n14 = PhylogenyNode
6727                     .createInstanceFromNhxString( "BLA_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6728             if ( !n14.getName().equals( "BLA_9QX45/1-2" ) ) {
6729                 return false;
6730             }
6731             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6732                 return false;
6733             }
6734             final PhylogenyNode n15 = PhylogenyNode
6735                     .createInstanceFromNhxString( "something_wicked[123]",
6736                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6737             if ( !n15.getName().equals( "something_wicked" ) ) {
6738                 return false;
6739             }
6740             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6741                 return false;
6742             }
6743             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6744                 return false;
6745             }
6746             final PhylogenyNode n16 = PhylogenyNode
6747                     .createInstanceFromNhxString( "something_wicked2[9]",
6748                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6749             if ( !n16.getName().equals( "something_wicked2" ) ) {
6750                 return false;
6751             }
6752             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6753                 return false;
6754             }
6755             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6756                 return false;
6757             }
6758             final PhylogenyNode n17 = PhylogenyNode
6759                     .createInstanceFromNhxString( "something_wicked3[a]",
6760                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6761             if ( !n17.getName().equals( "something_wicked3" ) ) {
6762                 return false;
6763             }
6764             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6765                 return false;
6766             }
6767             final PhylogenyNode n18 = PhylogenyNode
6768                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6769             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6770                 return false;
6771             }
6772             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6773                 return false;
6774             }
6775             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6776                 return false;
6777             }
6778             final PhylogenyNode n19 = PhylogenyNode
6779                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6780             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6781                 return false;
6782             }
6783             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6784                 return false;
6785             }
6786             final PhylogenyNode n30 = PhylogenyNode
6787                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
6788                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6789             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6790                 return false;
6791             }
6792             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6793                 return false;
6794             }
6795             final PhylogenyNode n31 = PhylogenyNode
6796                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
6797                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6798             if ( n31.getNodeData().isHasTaxonomy() ) {
6799                 return false;
6800             }
6801             final PhylogenyNode n32 = PhylogenyNode
6802                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6803             if ( n32.getNodeData().isHasTaxonomy() ) {
6804                 return false;
6805             }
6806             final PhylogenyNode n40 = PhylogenyNode
6807                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6808             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6809                 return false;
6810             }
6811             final PhylogenyNode n41 = PhylogenyNode
6812                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6813             if ( n41.getNodeData().isHasTaxonomy() ) {
6814                 return false;
6815             }
6816             final PhylogenyNode n42 = PhylogenyNode
6817                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6818             if ( n42.getNodeData().isHasTaxonomy() ) {
6819                 return false;
6820             }
6821             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
6822                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
6823             if ( n43.getNodeData().isHasTaxonomy() ) {
6824                 return false;
6825             }
6826             final PhylogenyNode n44 = PhylogenyNode
6827                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6828             if ( n44.getNodeData().isHasTaxonomy() ) {
6829                 return false;
6830             }
6831         }
6832         catch ( final Exception e ) {
6833             e.printStackTrace( System.out );
6834             return false;
6835         }
6836         return true;
6837     }
6838
6839     private static boolean testNHXParsing() {
6840         try {
6841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6842             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6843             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6844                 return false;
6845             }
6846             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]";
6847             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6848             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6849                 return false;
6850             }
6851             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]";
6852             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6853             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6854                 return false;
6855             }
6856             final Phylogeny[] p3 = factory
6857                     .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]",
6858                              new NHXParser() );
6859             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6860                 return false;
6861             }
6862             final Phylogeny[] p4 = factory
6863                     .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(]",
6864                              new NHXParser() );
6865             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6866                 return false;
6867             }
6868             final Phylogeny[] p5 = factory
6869                     .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(((]",
6870                              new NHXParser() );
6871             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6872                 return false;
6873             }
6874             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)";
6875             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)";
6876             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6877             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6878                 return false;
6879             }
6880             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)))";
6881             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)))";
6882             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6883             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6884                 return false;
6885             }
6886             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])   ))[,,, ])))))))";
6887             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6888             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6889             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6890                 return false;
6891             }
6892             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6893             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6894                 return false;
6895             }
6896             final Phylogeny p10 = factory
6897                     .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]",
6898                              new NHXParser() )[ 0 ];
6899             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6900                 return false;
6901             }
6902         }
6903         catch ( final Exception e ) {
6904             e.printStackTrace( System.out );
6905             return false;
6906         }
6907         return true;
6908     }
6909
6910     private static boolean testNHXParsingQuotes() {
6911         try {
6912             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6913             final NHXParser p = new NHXParser();
6914             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6915             if ( phylogenies_0.length != 5 ) {
6916                 return false;
6917             }
6918             final Phylogeny phy = phylogenies_0[ 4 ];
6919             if ( phy.getNumberOfExternalNodes() != 7 ) {
6920                 return false;
6921             }
6922             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6923                 return false;
6924             }
6925             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6926                 return false;
6927             }
6928             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6929                     .getScientificName().equals( "hsapiens" ) ) {
6930                 return false;
6931             }
6932             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6933                 return false;
6934             }
6935             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6936                 return false;
6937             }
6938             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6939                 return false;
6940             }
6941             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6942                 return false;
6943             }
6944             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
6945                 return false;
6946             }
6947             final NHXParser p1p = new NHXParser();
6948             p1p.setIgnoreQuotes( true );
6949             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6950             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6951                 return false;
6952             }
6953             final NHXParser p2p = new NHXParser();
6954             p1p.setIgnoreQuotes( false );
6955             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6956             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6957                 return false;
6958             }
6959             final NHXParser p3p = new NHXParser();
6960             p3p.setIgnoreQuotes( false );
6961             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6962             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6963                 return false;
6964             }
6965             final NHXParser p4p = new NHXParser();
6966             p4p.setIgnoreQuotes( false );
6967             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6968             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6969                 return false;
6970             }
6971             final Phylogeny p10 = factory
6972                     .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]",
6973                              new NHXParser() )[ 0 ];
6974             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]";
6975             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6976                 return false;
6977             }
6978             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6979             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6980                 return false;
6981             }
6982             //
6983             final Phylogeny p12 = factory
6984                     .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]",
6985                              new NHXParser() )[ 0 ];
6986             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]";
6987             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6988                 return false;
6989             }
6990             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6991             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6992                 return false;
6993             }
6994             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;";
6995             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6996                 return false;
6997             }
6998             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6999             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
7000                 return false;
7001             }
7002         }
7003         catch ( final Exception e ) {
7004             e.printStackTrace( System.out );
7005             return false;
7006         }
7007         return true;
7008     }
7009
7010     private static boolean testNHXParsingMB() {
7011         try {
7012             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7013             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7014                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7015                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7016                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7017                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7018                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7019                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7020                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7021                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
7022             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
7023                 return false;
7024             }
7025             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
7026                 return false;
7027             }
7028             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
7029                            0.1100000000000000e+00 ) ) {
7030                 return false;
7031             }
7032             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
7033                 return false;
7034             }
7035             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
7036                 return false;
7037             }
7038             final Phylogeny p2 = factory
7039                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
7040                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7041                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7042                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7043                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7044                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7045                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7046                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7047                                      + "7.369400000000000e-02}])",
7048                              new NHXParser() )[ 0 ];
7049             if ( p2.getNode( "1" ) == null ) {
7050                 return false;
7051             }
7052             if ( p2.getNode( "2" ) == null ) {
7053                 return false;
7054             }
7055         }
7056         catch ( final Exception e ) {
7057             e.printStackTrace( System.out );
7058             System.exit( -1 );
7059             return false;
7060         }
7061         return true;
7062     }
7063
7064     private static boolean testPhylogenyBranch() {
7065         try {
7066             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
7067             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
7068             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
7069             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
7070             if ( !a1b1.equals( a1b1 ) ) {
7071                 return false;
7072             }
7073             if ( !a1b1.equals( b1a1 ) ) {
7074                 return false;
7075             }
7076             if ( !b1a1.equals( a1b1 ) ) {
7077                 return false;
7078             }
7079             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
7080             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
7081             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
7082             if ( a1_b1.equals( b1_a1 ) ) {
7083                 return false;
7084             }
7085             if ( a1_b1.equals( a1_b1_ ) ) {
7086                 return false;
7087             }
7088             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
7089             if ( !a1_b1.equals( b1_a1_ ) ) {
7090                 return false;
7091             }
7092             if ( a1_b1_.equals( b1_a1_ ) ) {
7093                 return false;
7094             }
7095             if ( !a1_b1_.equals( b1_a1 ) ) {
7096                 return false;
7097             }
7098         }
7099         catch ( final Exception e ) {
7100             e.printStackTrace( System.out );
7101             return false;
7102         }
7103         return true;
7104     }
7105
7106     private static boolean testPhyloXMLparsingOfDistributionElement() {
7107         try {
7108             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7109             PhyloXmlParser xml_parser = null;
7110             try {
7111                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7112             }
7113             catch ( final Exception e ) {
7114                 // Do nothing -- means were not running from jar.
7115             }
7116             if ( xml_parser == null ) {
7117                 xml_parser = new PhyloXmlParser();
7118                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7119                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7120                 }
7121                 else {
7122                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7123                 }
7124             }
7125             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7126                                                               xml_parser );
7127             if ( xml_parser.getErrorCount() > 0 ) {
7128                 System.out.println( xml_parser.getErrorMessages().toString() );
7129                 return false;
7130             }
7131             if ( phylogenies_0.length != 1 ) {
7132                 return false;
7133             }
7134             final Phylogeny t1 = phylogenies_0[ 0 ];
7135             PhylogenyNode n = null;
7136             Distribution d = null;
7137             n = t1.getNode( "root node" );
7138             if ( !n.getNodeData().isHasDistribution() ) {
7139                 return false;
7140             }
7141             if ( n.getNodeData().getDistributions().size() != 1 ) {
7142                 return false;
7143             }
7144             d = n.getNodeData().getDistribution();
7145             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7146                 return false;
7147             }
7148             if ( d.getPoints().size() != 1 ) {
7149                 return false;
7150             }
7151             if ( d.getPolygons() != null ) {
7152                 return false;
7153             }
7154             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7155                 return false;
7156             }
7157             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7158                 return false;
7159             }
7160             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7161                 return false;
7162             }
7163             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7164                 return false;
7165             }
7166             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7167                 return false;
7168             }
7169             n = t1.getNode( "node a" );
7170             if ( !n.getNodeData().isHasDistribution() ) {
7171                 return false;
7172             }
7173             if ( n.getNodeData().getDistributions().size() != 2 ) {
7174                 return false;
7175             }
7176             d = n.getNodeData().getDistribution( 1 );
7177             if ( !d.getDesc().equals( "San Diego" ) ) {
7178                 return false;
7179             }
7180             if ( d.getPoints().size() != 1 ) {
7181                 return false;
7182             }
7183             if ( d.getPolygons() != null ) {
7184                 return false;
7185             }
7186             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7187                 return false;
7188             }
7189             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7190                 return false;
7191             }
7192             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7193                 return false;
7194             }
7195             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7196                 return false;
7197             }
7198             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7199                 return false;
7200             }
7201             n = t1.getNode( "node bb" );
7202             if ( !n.getNodeData().isHasDistribution() ) {
7203                 return false;
7204             }
7205             if ( n.getNodeData().getDistributions().size() != 1 ) {
7206                 return false;
7207             }
7208             d = n.getNodeData().getDistribution( 0 );
7209             if ( d.getPoints().size() != 3 ) {
7210                 return false;
7211             }
7212             if ( d.getPolygons().size() != 2 ) {
7213                 return false;
7214             }
7215             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7216                 return false;
7217             }
7218             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7219                 return false;
7220             }
7221             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7222                 return false;
7223             }
7224             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7225                 return false;
7226             }
7227             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7228                 return false;
7229             }
7230             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7231                 return false;
7232             }
7233             Polygon p = d.getPolygons().get( 0 );
7234             if ( p.getPoints().size() != 3 ) {
7235                 return false;
7236             }
7237             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7238                 return false;
7239             }
7240             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7241                 return false;
7242             }
7243             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7244                 return false;
7245             }
7246             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7247                 return false;
7248             }
7249             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7250                 return false;
7251             }
7252             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7253                 return false;
7254             }
7255             p = d.getPolygons().get( 1 );
7256             if ( p.getPoints().size() != 3 ) {
7257                 return false;
7258             }
7259             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7260                 return false;
7261             }
7262             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7263                 return false;
7264             }
7265             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7266                 return false;
7267             }
7268             // Roundtrip:
7269             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7270             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7271             if ( rt.length != 1 ) {
7272                 return false;
7273             }
7274             final Phylogeny t1_rt = rt[ 0 ];
7275             n = t1_rt.getNode( "root node" );
7276             if ( !n.getNodeData().isHasDistribution() ) {
7277                 return false;
7278             }
7279             if ( n.getNodeData().getDistributions().size() != 1 ) {
7280                 return false;
7281             }
7282             d = n.getNodeData().getDistribution();
7283             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7284                 return false;
7285             }
7286             if ( d.getPoints().size() != 1 ) {
7287                 return false;
7288             }
7289             if ( d.getPolygons() != null ) {
7290                 return false;
7291             }
7292             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7293                 return false;
7294             }
7295             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7296                 return false;
7297             }
7298             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7299                 return false;
7300             }
7301             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7302                 return false;
7303             }
7304             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7305                 return false;
7306             }
7307             n = t1_rt.getNode( "node a" );
7308             if ( !n.getNodeData().isHasDistribution() ) {
7309                 return false;
7310             }
7311             if ( n.getNodeData().getDistributions().size() != 2 ) {
7312                 return false;
7313             }
7314             d = n.getNodeData().getDistribution( 1 );
7315             if ( !d.getDesc().equals( "San Diego" ) ) {
7316                 return false;
7317             }
7318             if ( d.getPoints().size() != 1 ) {
7319                 return false;
7320             }
7321             if ( d.getPolygons() != null ) {
7322                 return false;
7323             }
7324             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7325                 return false;
7326             }
7327             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7328                 return false;
7329             }
7330             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7331                 return false;
7332             }
7333             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7334                 return false;
7335             }
7336             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7337                 return false;
7338             }
7339             n = t1_rt.getNode( "node bb" );
7340             if ( !n.getNodeData().isHasDistribution() ) {
7341                 return false;
7342             }
7343             if ( n.getNodeData().getDistributions().size() != 1 ) {
7344                 return false;
7345             }
7346             d = n.getNodeData().getDistribution( 0 );
7347             if ( d.getPoints().size() != 3 ) {
7348                 return false;
7349             }
7350             if ( d.getPolygons().size() != 2 ) {
7351                 return false;
7352             }
7353             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7354                 return false;
7355             }
7356             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7357                 return false;
7358             }
7359             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7360                 return false;
7361             }
7362             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7363                 return false;
7364             }
7365             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7366                 return false;
7367             }
7368             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7369                 return false;
7370             }
7371             p = d.getPolygons().get( 0 );
7372             if ( p.getPoints().size() != 3 ) {
7373                 return false;
7374             }
7375             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7376                 return false;
7377             }
7378             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7379                 return false;
7380             }
7381             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7382                 return false;
7383             }
7384             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7385                 return false;
7386             }
7387             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7388                 return false;
7389             }
7390             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7391                 return false;
7392             }
7393             p = d.getPolygons().get( 1 );
7394             if ( p.getPoints().size() != 3 ) {
7395                 return false;
7396             }
7397             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7398                 return false;
7399             }
7400             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7401                 return false;
7402             }
7403             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7404                 return false;
7405             }
7406         }
7407         catch ( final Exception e ) {
7408             e.printStackTrace( System.out );
7409             return false;
7410         }
7411         return true;
7412     }
7413
7414     private static boolean testPostOrderIterator() {
7415         try {
7416             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7417             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7418             PhylogenyNodeIterator it0;
7419             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7420                 it0.next();
7421             }
7422             for( it0.reset(); it0.hasNext(); ) {
7423                 it0.next();
7424             }
7425             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7426             final PhylogenyNodeIterator it = t1.iteratorPostorder();
7427             if ( !it.next().getName().equals( "A" ) ) {
7428                 return false;
7429             }
7430             if ( !it.next().getName().equals( "B" ) ) {
7431                 return false;
7432             }
7433             if ( !it.next().getName().equals( "ab" ) ) {
7434                 return false;
7435             }
7436             if ( !it.next().getName().equals( "C" ) ) {
7437                 return false;
7438             }
7439             if ( !it.next().getName().equals( "D" ) ) {
7440                 return false;
7441             }
7442             if ( !it.next().getName().equals( "cd" ) ) {
7443                 return false;
7444             }
7445             if ( !it.next().getName().equals( "abcd" ) ) {
7446                 return false;
7447             }
7448             if ( !it.next().getName().equals( "E" ) ) {
7449                 return false;
7450             }
7451             if ( !it.next().getName().equals( "F" ) ) {
7452                 return false;
7453             }
7454             if ( !it.next().getName().equals( "ef" ) ) {
7455                 return false;
7456             }
7457             if ( !it.next().getName().equals( "G" ) ) {
7458                 return false;
7459             }
7460             if ( !it.next().getName().equals( "H" ) ) {
7461                 return false;
7462             }
7463             if ( !it.next().getName().equals( "gh" ) ) {
7464                 return false;
7465             }
7466             if ( !it.next().getName().equals( "efgh" ) ) {
7467                 return false;
7468             }
7469             if ( !it.next().getName().equals( "r" ) ) {
7470                 return false;
7471             }
7472             if ( it.hasNext() ) {
7473                 return false;
7474             }
7475         }
7476         catch ( final Exception e ) {
7477             e.printStackTrace( System.out );
7478             return false;
7479         }
7480         return true;
7481     }
7482
7483     private static boolean testPreOrderIterator() {
7484         try {
7485             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7486             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7487             PhylogenyNodeIterator it0;
7488             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7489                 it0.next();
7490             }
7491             for( it0.reset(); it0.hasNext(); ) {
7492                 it0.next();
7493             }
7494             PhylogenyNodeIterator it = t0.iteratorPreorder();
7495             if ( !it.next().getName().equals( "r" ) ) {
7496                 return false;
7497             }
7498             if ( !it.next().getName().equals( "ab" ) ) {
7499                 return false;
7500             }
7501             if ( !it.next().getName().equals( "A" ) ) {
7502                 return false;
7503             }
7504             if ( !it.next().getName().equals( "B" ) ) {
7505                 return false;
7506             }
7507             if ( !it.next().getName().equals( "cd" ) ) {
7508                 return false;
7509             }
7510             if ( !it.next().getName().equals( "C" ) ) {
7511                 return false;
7512             }
7513             if ( !it.next().getName().equals( "D" ) ) {
7514                 return false;
7515             }
7516             if ( it.hasNext() ) {
7517                 return false;
7518             }
7519             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7520             it = t1.iteratorPreorder();
7521             if ( !it.next().getName().equals( "r" ) ) {
7522                 return false;
7523             }
7524             if ( !it.next().getName().equals( "abcd" ) ) {
7525                 return false;
7526             }
7527             if ( !it.next().getName().equals( "ab" ) ) {
7528                 return false;
7529             }
7530             if ( !it.next().getName().equals( "A" ) ) {
7531                 return false;
7532             }
7533             if ( !it.next().getName().equals( "B" ) ) {
7534                 return false;
7535             }
7536             if ( !it.next().getName().equals( "cd" ) ) {
7537                 return false;
7538             }
7539             if ( !it.next().getName().equals( "C" ) ) {
7540                 return false;
7541             }
7542             if ( !it.next().getName().equals( "D" ) ) {
7543                 return false;
7544             }
7545             if ( !it.next().getName().equals( "efgh" ) ) {
7546                 return false;
7547             }
7548             if ( !it.next().getName().equals( "ef" ) ) {
7549                 return false;
7550             }
7551             if ( !it.next().getName().equals( "E" ) ) {
7552                 return false;
7553             }
7554             if ( !it.next().getName().equals( "F" ) ) {
7555                 return false;
7556             }
7557             if ( !it.next().getName().equals( "gh" ) ) {
7558                 return false;
7559             }
7560             if ( !it.next().getName().equals( "G" ) ) {
7561                 return false;
7562             }
7563             if ( !it.next().getName().equals( "H" ) ) {
7564                 return false;
7565             }
7566             if ( it.hasNext() ) {
7567                 return false;
7568             }
7569         }
7570         catch ( final Exception e ) {
7571             e.printStackTrace( System.out );
7572             return false;
7573         }
7574         return true;
7575     }
7576
7577     private static boolean testPropertiesMap() {
7578         try {
7579             final PropertiesMap pm = new PropertiesMap();
7580             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7581             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7582             final Property p2 = new Property( "something:else",
7583                                               "?",
7584                                               "improbable:research",
7585                                               "xsd:decimal",
7586                                               AppliesTo.NODE );
7587             pm.addProperty( p0 );
7588             pm.addProperty( p1 );
7589             pm.addProperty( p2 );
7590             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7591                 return false;
7592             }
7593             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7594                 return false;
7595             }
7596             if ( pm.getProperties().size() != 3 ) {
7597                 return false;
7598             }
7599             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7600                 return false;
7601             }
7602             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7603                 return false;
7604             }
7605             if ( pm.getProperties().size() != 3 ) {
7606                 return false;
7607             }
7608             pm.removeProperty( "dimensions:diameter" );
7609             if ( pm.getProperties().size() != 2 ) {
7610                 return false;
7611             }
7612             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7613                 return false;
7614             }
7615             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7616                 return false;
7617             }
7618         }
7619         catch ( final Exception e ) {
7620             e.printStackTrace( System.out );
7621             return false;
7622         }
7623         return true;
7624     }
7625
7626     private static boolean testReIdMethods() {
7627         try {
7628             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7629             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7630             final long count = PhylogenyNode.getNodeCount();
7631             p.levelOrderReID();
7632             if ( p.getNode( "r" ).getId() != count ) {
7633                 return false;
7634             }
7635             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7636                 return false;
7637             }
7638             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7639                 return false;
7640             }
7641             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7642                 return false;
7643             }
7644             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7645                 return false;
7646             }
7647             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7648                 return false;
7649             }
7650             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7651                 return false;
7652             }
7653             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7654                 return false;
7655             }
7656             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7657                 return false;
7658             }
7659             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7660                 return false;
7661             }
7662             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7663                 return false;
7664             }
7665             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7666                 return false;
7667             }
7668             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7669                 return false;
7670             }
7671             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7672                 return false;
7673             }
7674             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7675                 return false;
7676             }
7677         }
7678         catch ( final Exception e ) {
7679             e.printStackTrace( System.out );
7680             return false;
7681         }
7682         return true;
7683     }
7684
7685     private static boolean testRerooting() {
7686         try {
7687             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7688             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",
7689                                                  new NHXParser() )[ 0 ];
7690             if ( !t1.isRooted() ) {
7691                 return false;
7692             }
7693             t1.reRoot( t1.getNode( "D" ) );
7694             t1.reRoot( t1.getNode( "CD" ) );
7695             t1.reRoot( t1.getNode( "A" ) );
7696             t1.reRoot( t1.getNode( "B" ) );
7697             t1.reRoot( t1.getNode( "AB" ) );
7698             t1.reRoot( t1.getNode( "D" ) );
7699             t1.reRoot( t1.getNode( "C" ) );
7700             t1.reRoot( t1.getNode( "CD" ) );
7701             t1.reRoot( t1.getNode( "A" ) );
7702             t1.reRoot( t1.getNode( "B" ) );
7703             t1.reRoot( t1.getNode( "AB" ) );
7704             t1.reRoot( t1.getNode( "D" ) );
7705             t1.reRoot( t1.getNode( "D" ) );
7706             t1.reRoot( t1.getNode( "C" ) );
7707             t1.reRoot( t1.getNode( "A" ) );
7708             t1.reRoot( t1.getNode( "B" ) );
7709             t1.reRoot( t1.getNode( "AB" ) );
7710             t1.reRoot( t1.getNode( "C" ) );
7711             t1.reRoot( t1.getNode( "D" ) );
7712             t1.reRoot( t1.getNode( "CD" ) );
7713             t1.reRoot( t1.getNode( "D" ) );
7714             t1.reRoot( t1.getNode( "A" ) );
7715             t1.reRoot( t1.getNode( "B" ) );
7716             t1.reRoot( t1.getNode( "AB" ) );
7717             t1.reRoot( t1.getNode( "C" ) );
7718             t1.reRoot( t1.getNode( "D" ) );
7719             t1.reRoot( t1.getNode( "CD" ) );
7720             t1.reRoot( t1.getNode( "D" ) );
7721             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7722                 return false;
7723             }
7724             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7725                 return false;
7726             }
7727             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7728                 return false;
7729             }
7730             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7731                 return false;
7732             }
7733             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7734                 return false;
7735             }
7736             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7737                 return false;
7738             }
7739             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",
7740                                                  new NHXParser() )[ 0 ];
7741             t2.reRoot( t2.getNode( "A" ) );
7742             t2.reRoot( t2.getNode( "D" ) );
7743             t2.reRoot( t2.getNode( "ABC" ) );
7744             t2.reRoot( t2.getNode( "A" ) );
7745             t2.reRoot( t2.getNode( "B" ) );
7746             t2.reRoot( t2.getNode( "D" ) );
7747             t2.reRoot( t2.getNode( "C" ) );
7748             t2.reRoot( t2.getNode( "ABC" ) );
7749             t2.reRoot( t2.getNode( "A" ) );
7750             t2.reRoot( t2.getNode( "B" ) );
7751             t2.reRoot( t2.getNode( "AB" ) );
7752             t2.reRoot( t2.getNode( "AB" ) );
7753             t2.reRoot( t2.getNode( "D" ) );
7754             t2.reRoot( t2.getNode( "C" ) );
7755             t2.reRoot( t2.getNode( "B" ) );
7756             t2.reRoot( t2.getNode( "AB" ) );
7757             t2.reRoot( t2.getNode( "D" ) );
7758             t2.reRoot( t2.getNode( "D" ) );
7759             t2.reRoot( t2.getNode( "ABC" ) );
7760             t2.reRoot( t2.getNode( "A" ) );
7761             t2.reRoot( t2.getNode( "B" ) );
7762             t2.reRoot( t2.getNode( "AB" ) );
7763             t2.reRoot( t2.getNode( "D" ) );
7764             t2.reRoot( t2.getNode( "C" ) );
7765             t2.reRoot( t2.getNode( "ABC" ) );
7766             t2.reRoot( t2.getNode( "A" ) );
7767             t2.reRoot( t2.getNode( "B" ) );
7768             t2.reRoot( t2.getNode( "AB" ) );
7769             t2.reRoot( t2.getNode( "D" ) );
7770             t2.reRoot( t2.getNode( "D" ) );
7771             t2.reRoot( t2.getNode( "C" ) );
7772             t2.reRoot( t2.getNode( "A" ) );
7773             t2.reRoot( t2.getNode( "B" ) );
7774             t2.reRoot( t2.getNode( "AB" ) );
7775             t2.reRoot( t2.getNode( "C" ) );
7776             t2.reRoot( t2.getNode( "D" ) );
7777             t2.reRoot( t2.getNode( "ABC" ) );
7778             t2.reRoot( t2.getNode( "D" ) );
7779             t2.reRoot( t2.getNode( "A" ) );
7780             t2.reRoot( t2.getNode( "B" ) );
7781             t2.reRoot( t2.getNode( "AB" ) );
7782             t2.reRoot( t2.getNode( "C" ) );
7783             t2.reRoot( t2.getNode( "D" ) );
7784             t2.reRoot( t2.getNode( "ABC" ) );
7785             t2.reRoot( t2.getNode( "D" ) );
7786             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7787                 return false;
7788             }
7789             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7790                 return false;
7791             }
7792             t2.reRoot( t2.getNode( "ABC" ) );
7793             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7794                 return false;
7795             }
7796             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7797                 return false;
7798             }
7799             t2.reRoot( t2.getNode( "AB" ) );
7800             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7801                 return false;
7802             }
7803             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7804                 return false;
7805             }
7806             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7807                 return false;
7808             }
7809             t2.reRoot( t2.getNode( "AB" ) );
7810             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7811                 return false;
7812             }
7813             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7814                 return false;
7815             }
7816             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7817                 return false;
7818             }
7819             t2.reRoot( t2.getNode( "D" ) );
7820             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7821                 return false;
7822             }
7823             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7824                 return false;
7825             }
7826             t2.reRoot( t2.getNode( "ABC" ) );
7827             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7828                 return false;
7829             }
7830             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7831                 return false;
7832             }
7833             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7834                                                  new NHXParser() )[ 0 ];
7835             t3.reRoot( t3.getNode( "B" ) );
7836             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7837                 return false;
7838             }
7839             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7840                 return false;
7841             }
7842             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7843                 return false;
7844             }
7845             t3.reRoot( t3.getNode( "B" ) );
7846             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7847                 return false;
7848             }
7849             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7850                 return false;
7851             }
7852             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7853                 return false;
7854             }
7855             t3.reRoot( t3.getRoot() );
7856             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7857                 return false;
7858             }
7859             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7860                 return false;
7861             }
7862             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7863                 return false;
7864             }
7865         }
7866         catch ( final Exception e ) {
7867             e.printStackTrace( System.out );
7868             return false;
7869         }
7870         return true;
7871     }
7872
7873     private static boolean testSDIse() {
7874         try {
7875             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7876             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7877             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7878             gene1.setRooted( true );
7879             species1.setRooted( true );
7880             final SDI sdi = new SDI( gene1, species1 );
7881             if ( !gene1.getRoot().isDuplication() ) {
7882                 return false;
7883             }
7884             final Phylogeny species2 = factory
7885                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7886                              new NHXParser() )[ 0 ];
7887             final Phylogeny gene2 = factory
7888                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7889                              new NHXParser() )[ 0 ];
7890             species2.setRooted( true );
7891             gene2.setRooted( true );
7892             final SDI sdi2 = new SDI( gene2, species2 );
7893             if ( sdi2.getDuplicationsSum() != 0 ) {
7894                 return false;
7895             }
7896             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7897                 return false;
7898             }
7899             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7900                 return false;
7901             }
7902             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7903                 return false;
7904             }
7905             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7906                 return false;
7907             }
7908             if ( !gene2.getNode( "r" ).isSpeciation() ) {
7909                 return false;
7910             }
7911             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7912                 return false;
7913             }
7914             final Phylogeny species3 = factory
7915                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7916                              new NHXParser() )[ 0 ];
7917             final Phylogeny gene3 = factory
7918                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7919                              new NHXParser() )[ 0 ];
7920             species3.setRooted( true );
7921             gene3.setRooted( true );
7922             final SDI sdi3 = new SDI( gene3, species3 );
7923             if ( sdi3.getDuplicationsSum() != 1 ) {
7924                 return false;
7925             }
7926             if ( !gene3.getNode( "aa" ).isDuplication() ) {
7927                 return false;
7928             }
7929             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7930                 return false;
7931             }
7932             final Phylogeny species4 = factory
7933                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7934                              new NHXParser() )[ 0 ];
7935             final Phylogeny gene4 = factory
7936                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7937                              new NHXParser() )[ 0 ];
7938             species4.setRooted( true );
7939             gene4.setRooted( true );
7940             final SDI sdi4 = new SDI( gene4, species4 );
7941             if ( sdi4.getDuplicationsSum() != 1 ) {
7942                 return false;
7943             }
7944             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7945                 return false;
7946             }
7947             if ( !gene4.getNode( "abc" ).isDuplication() ) {
7948                 return false;
7949             }
7950             if ( gene4.getNode( "abcd" ).isDuplication() ) {
7951                 return false;
7952             }
7953             if ( species4.getNumberOfExternalNodes() != 6 ) {
7954                 return false;
7955             }
7956             if ( gene4.getNumberOfExternalNodes() != 6 ) {
7957                 return false;
7958             }
7959             final Phylogeny species5 = factory
7960                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7961                              new NHXParser() )[ 0 ];
7962             final Phylogeny gene5 = factory
7963                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7964                              new NHXParser() )[ 0 ];
7965             species5.setRooted( true );
7966             gene5.setRooted( true );
7967             final SDI sdi5 = new SDI( gene5, species5 );
7968             if ( sdi5.getDuplicationsSum() != 2 ) {
7969                 return false;
7970             }
7971             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7972                 return false;
7973             }
7974             if ( !gene5.getNode( "adc" ).isDuplication() ) {
7975                 return false;
7976             }
7977             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7978                 return false;
7979             }
7980             if ( species5.getNumberOfExternalNodes() != 6 ) {
7981                 return false;
7982             }
7983             if ( gene5.getNumberOfExternalNodes() != 6 ) {
7984                 return false;
7985             }
7986             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7987             // Conjecture for Comparing Molecular Phylogenies"
7988             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7989             final Phylogeny species6 = factory
7990                     .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,"
7991                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7992                              new NHXParser() )[ 0 ];
7993             final Phylogeny gene6 = factory
7994                     .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,"
7995                                      + "((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,"
7996                                      + "(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;",
7997                              new NHXParser() )[ 0 ];
7998             species6.setRooted( true );
7999             gene6.setRooted( true );
8000             final SDI sdi6 = new SDI( gene6, species6 );
8001             if ( sdi6.getDuplicationsSum() != 3 ) {
8002                 return false;
8003             }
8004             if ( !gene6.getNode( "r" ).isDuplication() ) {
8005                 return false;
8006             }
8007             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
8008                 return false;
8009             }
8010             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
8011                 return false;
8012             }
8013             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
8014                 return false;
8015             }
8016             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
8017                 return false;
8018             }
8019             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
8020                 return false;
8021             }
8022             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
8023                 return false;
8024             }
8025             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
8026                 return false;
8027             }
8028             sdi6.computeMappingCostL();
8029             if ( sdi6.computeMappingCostL() != 17 ) {
8030                 return false;
8031             }
8032             if ( species6.getNumberOfExternalNodes() != 9 ) {
8033                 return false;
8034             }
8035             if ( gene6.getNumberOfExternalNodes() != 9 ) {
8036                 return false;
8037             }
8038             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
8039                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
8040                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
8041                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
8042                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
8043             species7.setRooted( true );
8044             final Phylogeny gene7_1 = Test
8045                     .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])" );
8046             gene7_1.setRooted( true );
8047             final SDI sdi7 = new SDI( gene7_1, species7 );
8048             if ( sdi7.getDuplicationsSum() != 0 ) {
8049                 return false;
8050             }
8051             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
8052                 return false;
8053             }
8054             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
8055                 return false;
8056             }
8057             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
8058                 return false;
8059             }
8060             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
8061                 return false;
8062             }
8063             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
8064                 return false;
8065             }
8066             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
8067                 return false;
8068             }
8069             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
8070                 return false;
8071             }
8072             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
8073                 return false;
8074             }
8075             final Phylogeny gene7_2 = Test
8076                     .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])" );
8077             gene7_2.setRooted( true );
8078             final SDI sdi7_2 = new SDI( gene7_2, species7 );
8079             if ( sdi7_2.getDuplicationsSum() != 1 ) {
8080                 return false;
8081             }
8082             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
8083                 return false;
8084             }
8085             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
8086                 return false;
8087             }
8088             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
8089                 return false;
8090             }
8091             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
8092                 return false;
8093             }
8094             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
8095                 return false;
8096             }
8097             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8098                 return false;
8099             }
8100             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8101                 return false;
8102             }
8103             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8104                 return false;
8105             }
8106             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8107                 return false;
8108             }
8109         }
8110         catch ( final Exception e ) {
8111             return false;
8112         }
8113         return true;
8114     }
8115
8116     private static boolean testSDIunrooted() {
8117         try {
8118             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8119             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8120             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8121             final Iterator<PhylogenyBranch> iter = l.iterator();
8122             PhylogenyBranch br = iter.next();
8123             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8124                 return false;
8125             }
8126             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8127                 return false;
8128             }
8129             br = iter.next();
8130             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8131                 return false;
8132             }
8133             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8134                 return false;
8135             }
8136             br = iter.next();
8137             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8138                 return false;
8139             }
8140             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8141                 return false;
8142             }
8143             br = iter.next();
8144             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8145                 return false;
8146             }
8147             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8148                 return false;
8149             }
8150             br = iter.next();
8151             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8152                 return false;
8153             }
8154             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8155                 return false;
8156             }
8157             br = iter.next();
8158             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8159                 return false;
8160             }
8161             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8162                 return false;
8163             }
8164             br = iter.next();
8165             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8166                 return false;
8167             }
8168             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8169                 return false;
8170             }
8171             br = iter.next();
8172             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8173                 return false;
8174             }
8175             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8176                 return false;
8177             }
8178             br = iter.next();
8179             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8180                 return false;
8181             }
8182             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8183                 return false;
8184             }
8185             br = iter.next();
8186             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8187                 return false;
8188             }
8189             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8190                 return false;
8191             }
8192             br = iter.next();
8193             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8194                 return false;
8195             }
8196             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8197                 return false;
8198             }
8199             br = iter.next();
8200             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8201                 return false;
8202             }
8203             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8204                 return false;
8205             }
8206             br = iter.next();
8207             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8208                 return false;
8209             }
8210             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8211                 return false;
8212             }
8213             br = iter.next();
8214             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8215                 return false;
8216             }
8217             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8218                 return false;
8219             }
8220             br = iter.next();
8221             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8222                 return false;
8223             }
8224             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8225                 return false;
8226             }
8227             if ( iter.hasNext() ) {
8228                 return false;
8229             }
8230             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8231             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8232             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8233             br = iter1.next();
8234             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8235                 return false;
8236             }
8237             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8238                 return false;
8239             }
8240             br = iter1.next();
8241             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8242                 return false;
8243             }
8244             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8245                 return false;
8246             }
8247             br = iter1.next();
8248             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8249                 return false;
8250             }
8251             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8252                 return false;
8253             }
8254             if ( iter1.hasNext() ) {
8255                 return false;
8256             }
8257             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8258             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8259             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8260             br = iter2.next();
8261             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8262                 return false;
8263             }
8264             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8265                 return false;
8266             }
8267             br = iter2.next();
8268             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8269                 return false;
8270             }
8271             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8272                 return false;
8273             }
8274             br = iter2.next();
8275             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8276                 return false;
8277             }
8278             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8279                 return false;
8280             }
8281             if ( iter2.hasNext() ) {
8282                 return false;
8283             }
8284             final Phylogeny species0 = factory
8285                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8286                              new NHXParser() )[ 0 ];
8287             final Phylogeny gene1 = factory
8288                     .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])",
8289                              new NHXParser() )[ 0 ];
8290             species0.setRooted( true );
8291             gene1.setRooted( true );
8292             final SDIR sdi_unrooted = new SDIR();
8293             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8294             if ( sdi_unrooted.getCount() != 1 ) {
8295                 return false;
8296             }
8297             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8298                 return false;
8299             }
8300             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8301                 return false;
8302             }
8303             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8304                 return false;
8305             }
8306             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8307                 return false;
8308             }
8309             final Phylogeny gene2 = factory
8310                     .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])",
8311                              new NHXParser() )[ 0 ];
8312             gene2.setRooted( true );
8313             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8314             if ( sdi_unrooted.getCount() != 1 ) {
8315                 return false;
8316             }
8317             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8318                 return false;
8319             }
8320             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8321                 return false;
8322             }
8323             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8324                 return false;
8325             }
8326             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8327                 return false;
8328             }
8329             final Phylogeny species6 = factory
8330                     .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,"
8331                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8332                              new NHXParser() )[ 0 ];
8333             final Phylogeny gene6 = factory
8334                     .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],"
8335                                      + "(((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],"
8336                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8337                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8338                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8339                              new NHXParser() )[ 0 ];
8340             species6.setRooted( true );
8341             gene6.setRooted( true );
8342             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8343             if ( sdi_unrooted.getCount() != 1 ) {
8344                 return false;
8345             }
8346             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8347                 return false;
8348             }
8349             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8350                 return false;
8351             }
8352             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8353                 return false;
8354             }
8355             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8356                 return false;
8357             }
8358             if ( !p6[ 0 ].getRoot().isDuplication() ) {
8359                 return false;
8360             }
8361             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8362                 return false;
8363             }
8364             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8365                 return false;
8366             }
8367             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8368                 return false;
8369             }
8370             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8371                 return false;
8372             }
8373             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8374                 return false;
8375             }
8376             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8377                 return false;
8378             }
8379             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8380                 return false;
8381             }
8382             p6 = null;
8383             final Phylogeny species7 = factory
8384                     .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,"
8385                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8386                              new NHXParser() )[ 0 ];
8387             final Phylogeny gene7 = factory
8388                     .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],"
8389                                      + "(((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],"
8390                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8391                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8392                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8393                              new NHXParser() )[ 0 ];
8394             species7.setRooted( true );
8395             gene7.setRooted( true );
8396             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8397             if ( sdi_unrooted.getCount() != 1 ) {
8398                 return false;
8399             }
8400             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8401                 return false;
8402             }
8403             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8404                 return false;
8405             }
8406             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8407                 return false;
8408             }
8409             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8410                 return false;
8411             }
8412             if ( !p7[ 0 ].getRoot().isDuplication() ) {
8413                 return false;
8414             }
8415             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8416                 return false;
8417             }
8418             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8419                 return false;
8420             }
8421             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8422                 return false;
8423             }
8424             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8425                 return false;
8426             }
8427             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8428                 return false;
8429             }
8430             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8431                 return false;
8432             }
8433             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8434                 return false;
8435             }
8436             p7 = null;
8437             final Phylogeny species8 = factory
8438                     .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,"
8439                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8440                              new NHXParser() )[ 0 ];
8441             final Phylogeny gene8 = factory
8442                     .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],"
8443                                      + "(((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],"
8444                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8445                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8446                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8447                              new NHXParser() )[ 0 ];
8448             species8.setRooted( true );
8449             gene8.setRooted( true );
8450             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8451             if ( sdi_unrooted.getCount() != 1 ) {
8452                 return false;
8453             }
8454             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8455                 return false;
8456             }
8457             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8458                 return false;
8459             }
8460             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8461                 return false;
8462             }
8463             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8464                 return false;
8465             }
8466             if ( !p8[ 0 ].getRoot().isDuplication() ) {
8467                 return false;
8468             }
8469             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8470                 return false;
8471             }
8472             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8473                 return false;
8474             }
8475             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8476                 return false;
8477             }
8478             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8479                 return false;
8480             }
8481             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8482                 return false;
8483             }
8484             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8485                 return false;
8486             }
8487             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8488                 return false;
8489             }
8490             p8 = null;
8491         }
8492         catch ( final Exception e ) {
8493             e.printStackTrace( System.out );
8494             return false;
8495         }
8496         return true;
8497     }
8498
8499     private static boolean testSplit() {
8500         try {
8501             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8502             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8503             //Archaeopteryx.createApplication( p0 );
8504             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8505             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8506             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8507             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8508             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8509             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8510             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8511             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8512             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8513             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8514             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8515             // System.out.println( s0.toString() );
8516             //
8517             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8520             if ( s0.match( query_nodes ) ) {
8521                 return false;
8522             }
8523             query_nodes = new HashSet<PhylogenyNode>();
8524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8526             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8527             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8531             if ( !s0.match( query_nodes ) ) {
8532                 return false;
8533             }
8534             //
8535             query_nodes = new HashSet<PhylogenyNode>();
8536             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8539             if ( !s0.match( query_nodes ) ) {
8540                 return false;
8541             }
8542             //
8543             query_nodes = new HashSet<PhylogenyNode>();
8544             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8545             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8548             if ( !s0.match( query_nodes ) ) {
8549                 return false;
8550             }
8551             //
8552             query_nodes = new HashSet<PhylogenyNode>();
8553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8557             if ( !s0.match( query_nodes ) ) {
8558                 return false;
8559             }
8560             //
8561             query_nodes = new HashSet<PhylogenyNode>();
8562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8565             if ( !s0.match( query_nodes ) ) {
8566                 return false;
8567             }
8568             //
8569             query_nodes = new HashSet<PhylogenyNode>();
8570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8572             if ( !s0.match( query_nodes ) ) {
8573                 return false;
8574             }
8575             //
8576             query_nodes = new HashSet<PhylogenyNode>();
8577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8582             if ( !s0.match( query_nodes ) ) {
8583                 return false;
8584             }
8585             //
8586             query_nodes = new HashSet<PhylogenyNode>();
8587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8590             if ( !s0.match( query_nodes ) ) {
8591                 return false;
8592             }
8593             //
8594             query_nodes = new HashSet<PhylogenyNode>();
8595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8599             if ( !s0.match( query_nodes ) ) {
8600                 return false;
8601             }
8602             //
8603             query_nodes = new HashSet<PhylogenyNode>();
8604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8606             if ( s0.match( query_nodes ) ) {
8607                 return false;
8608             }
8609             //
8610             query_nodes = new HashSet<PhylogenyNode>();
8611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8615             if ( s0.match( query_nodes ) ) {
8616                 return false;
8617             }
8618             //
8619             query_nodes = new HashSet<PhylogenyNode>();
8620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8625             if ( s0.match( query_nodes ) ) {
8626                 return false;
8627             }
8628             //
8629             query_nodes = new HashSet<PhylogenyNode>();
8630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8633             if ( s0.match( query_nodes ) ) {
8634                 return false;
8635             }
8636             //
8637             query_nodes = new HashSet<PhylogenyNode>();
8638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8640             if ( s0.match( query_nodes ) ) {
8641                 return false;
8642             }
8643             //
8644             query_nodes = new HashSet<PhylogenyNode>();
8645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8647             if ( s0.match( query_nodes ) ) {
8648                 return false;
8649             }
8650             //
8651             query_nodes = new HashSet<PhylogenyNode>();
8652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8654             if ( s0.match( query_nodes ) ) {
8655                 return false;
8656             }
8657             //
8658             query_nodes = new HashSet<PhylogenyNode>();
8659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8661             if ( s0.match( query_nodes ) ) {
8662                 return false;
8663             }
8664             //
8665             query_nodes = new HashSet<PhylogenyNode>();
8666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8668             if ( s0.match( query_nodes ) ) {
8669                 return false;
8670             }
8671             //
8672             query_nodes = new HashSet<PhylogenyNode>();
8673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8675             if ( s0.match( query_nodes ) ) {
8676                 return false;
8677             }
8678             //
8679             query_nodes = new HashSet<PhylogenyNode>();
8680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8683             if ( s0.match( query_nodes ) ) {
8684                 return false;
8685             }
8686             //
8687             query_nodes = new HashSet<PhylogenyNode>();
8688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8691             if ( s0.match( query_nodes ) ) {
8692                 return false;
8693             }
8694             //
8695             query_nodes = new HashSet<PhylogenyNode>();
8696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8699             if ( s0.match( query_nodes ) ) {
8700                 return false;
8701             }
8702             //
8703             query_nodes = new HashSet<PhylogenyNode>();
8704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8708             if ( s0.match( query_nodes ) ) {
8709                 return false;
8710             }
8711             /////////
8712             //            query_nodes = new HashSet<PhylogenyNode>();
8713             //            query_nodes.add( new PhylogenyNode( "X" ) );
8714             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8715             //            query_nodes.add( new PhylogenyNode( "A" ) );
8716             //            query_nodes.add( new PhylogenyNode( "B" ) );
8717             //            query_nodes.add( new PhylogenyNode( "C" ) );
8718             //            query_nodes.add( new PhylogenyNode( "D" ) );
8719             //            query_nodes.add( new PhylogenyNode( "E" ) );
8720             //            query_nodes.add( new PhylogenyNode( "F" ) );
8721             //            query_nodes.add( new PhylogenyNode( "G" ) );
8722             //            if ( !s0.match( query_nodes ) ) {
8723             //                return false;
8724             //            }
8725             //            query_nodes = new HashSet<PhylogenyNode>();
8726             //            query_nodes.add( new PhylogenyNode( "X" ) );
8727             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8728             //            query_nodes.add( new PhylogenyNode( "A" ) );
8729             //            query_nodes.add( new PhylogenyNode( "B" ) );
8730             //            query_nodes.add( new PhylogenyNode( "C" ) );
8731             //            if ( !s0.match( query_nodes ) ) {
8732             //                return false;
8733             //            }
8734             //            //
8735             //            query_nodes = new HashSet<PhylogenyNode>();
8736             //            query_nodes.add( new PhylogenyNode( "X" ) );
8737             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8738             //            query_nodes.add( new PhylogenyNode( "D" ) );
8739             //            query_nodes.add( new PhylogenyNode( "E" ) );
8740             //            query_nodes.add( new PhylogenyNode( "F" ) );
8741             //            query_nodes.add( new PhylogenyNode( "G" ) );
8742             //            if ( !s0.match( query_nodes ) ) {
8743             //                return false;
8744             //            }
8745             //            //
8746             //            query_nodes = new HashSet<PhylogenyNode>();
8747             //            query_nodes.add( new PhylogenyNode( "X" ) );
8748             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8749             //            query_nodes.add( new PhylogenyNode( "A" ) );
8750             //            query_nodes.add( new PhylogenyNode( "B" ) );
8751             //            query_nodes.add( new PhylogenyNode( "C" ) );
8752             //            query_nodes.add( new PhylogenyNode( "D" ) );
8753             //            if ( !s0.match( query_nodes ) ) {
8754             //                return false;
8755             //            }
8756             //            //
8757             //            query_nodes = new HashSet<PhylogenyNode>();
8758             //            query_nodes.add( new PhylogenyNode( "X" ) );
8759             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8760             //            query_nodes.add( new PhylogenyNode( "E" ) );
8761             //            query_nodes.add( new PhylogenyNode( "F" ) );
8762             //            query_nodes.add( new PhylogenyNode( "G" ) );
8763             //            if ( !s0.match( query_nodes ) ) {
8764             //                return false;
8765             //            }
8766             //            //
8767             //            query_nodes = new HashSet<PhylogenyNode>();
8768             //            query_nodes.add( new PhylogenyNode( "X" ) );
8769             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8770             //            query_nodes.add( new PhylogenyNode( "F" ) );
8771             //            query_nodes.add( new PhylogenyNode( "G" ) );
8772             //            if ( !s0.match( query_nodes ) ) {
8773             //                return false;
8774             //            }
8775             //
8776             query_nodes = new HashSet<PhylogenyNode>();
8777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8781             if ( s0.match( query_nodes ) ) {
8782                 return false;
8783             }
8784             //
8785             query_nodes = new HashSet<PhylogenyNode>();
8786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8790             if ( s0.match( query_nodes ) ) {
8791                 return false;
8792             }
8793             ///////////////////////////
8794             //
8795             query_nodes = new HashSet<PhylogenyNode>();
8796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8800             if ( s0.match( query_nodes ) ) {
8801                 return false;
8802             }
8803             //
8804             query_nodes = new HashSet<PhylogenyNode>();
8805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8808             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8809             if ( s0.match( query_nodes ) ) {
8810                 return false;
8811             }
8812             //
8813             query_nodes = new HashSet<PhylogenyNode>();
8814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8818             if ( s0.match( query_nodes ) ) {
8819                 return false;
8820             }
8821             //
8822             query_nodes = new HashSet<PhylogenyNode>();
8823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8826             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8827             if ( s0.match( query_nodes ) ) {
8828                 return false;
8829             }
8830             //
8831             query_nodes = new HashSet<PhylogenyNode>();
8832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8836             if ( s0.match( query_nodes ) ) {
8837                 return false;
8838             }
8839             //
8840             query_nodes = new HashSet<PhylogenyNode>();
8841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8844             if ( s0.match( query_nodes ) ) {
8845                 return false;
8846             }
8847             //
8848             query_nodes = new HashSet<PhylogenyNode>();
8849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8854             if ( s0.match( query_nodes ) ) {
8855                 return false;
8856             }
8857             //
8858             query_nodes = new HashSet<PhylogenyNode>();
8859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8864             if ( s0.match( query_nodes ) ) {
8865                 return false;
8866             }
8867             //
8868             query_nodes = new HashSet<PhylogenyNode>();
8869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8874             if ( s0.match( query_nodes ) ) {
8875                 return false;
8876             }
8877             //
8878             query_nodes = new HashSet<PhylogenyNode>();
8879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8885             if ( s0.match( query_nodes ) ) {
8886                 return false;
8887             }
8888         }
8889         catch ( final Exception e ) {
8890             e.printStackTrace();
8891             return false;
8892         }
8893         return true;
8894     }
8895
8896     private static boolean testSplitStrict() {
8897         try {
8898             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8899             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8900             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8901             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8902             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8903             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8904             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8905             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8906             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8907             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8908             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8909             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8912             if ( s0.match( query_nodes ) ) {
8913                 return false;
8914             }
8915             query_nodes = new HashSet<PhylogenyNode>();
8916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8923             if ( !s0.match( query_nodes ) ) {
8924                 return false;
8925             }
8926             //
8927             query_nodes = new HashSet<PhylogenyNode>();
8928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8931             if ( !s0.match( query_nodes ) ) {
8932                 return false;
8933             }
8934             //
8935             query_nodes = new HashSet<PhylogenyNode>();
8936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8940             if ( !s0.match( query_nodes ) ) {
8941                 return false;
8942             }
8943             //
8944             query_nodes = new HashSet<PhylogenyNode>();
8945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8949             if ( !s0.match( query_nodes ) ) {
8950                 return false;
8951             }
8952             //
8953             query_nodes = new HashSet<PhylogenyNode>();
8954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8957             if ( !s0.match( query_nodes ) ) {
8958                 return false;
8959             }
8960             //
8961             query_nodes = new HashSet<PhylogenyNode>();
8962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8964             if ( !s0.match( query_nodes ) ) {
8965                 return false;
8966             }
8967             //
8968             query_nodes = new HashSet<PhylogenyNode>();
8969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8974             if ( !s0.match( query_nodes ) ) {
8975                 return false;
8976             }
8977             //
8978             query_nodes = new HashSet<PhylogenyNode>();
8979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8982             if ( !s0.match( query_nodes ) ) {
8983                 return false;
8984             }
8985             //
8986             query_nodes = new HashSet<PhylogenyNode>();
8987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8991             if ( !s0.match( query_nodes ) ) {
8992                 return false;
8993             }
8994             //
8995             query_nodes = new HashSet<PhylogenyNode>();
8996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8998             if ( s0.match( query_nodes ) ) {
8999                 return false;
9000             }
9001             //
9002             query_nodes = new HashSet<PhylogenyNode>();
9003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9007             if ( s0.match( query_nodes ) ) {
9008                 return false;
9009             }
9010             //
9011             query_nodes = new HashSet<PhylogenyNode>();
9012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9017             if ( s0.match( query_nodes ) ) {
9018                 return false;
9019             }
9020             //
9021             query_nodes = new HashSet<PhylogenyNode>();
9022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9025             if ( s0.match( query_nodes ) ) {
9026                 return false;
9027             }
9028             //
9029             query_nodes = new HashSet<PhylogenyNode>();
9030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9032             if ( s0.match( query_nodes ) ) {
9033                 return false;
9034             }
9035             //
9036             query_nodes = new HashSet<PhylogenyNode>();
9037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9039             if ( s0.match( query_nodes ) ) {
9040                 return false;
9041             }
9042             //
9043             query_nodes = new HashSet<PhylogenyNode>();
9044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9046             if ( s0.match( query_nodes ) ) {
9047                 return false;
9048             }
9049             //
9050             query_nodes = new HashSet<PhylogenyNode>();
9051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9053             if ( s0.match( query_nodes ) ) {
9054                 return false;
9055             }
9056             //
9057             query_nodes = new HashSet<PhylogenyNode>();
9058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9060             if ( s0.match( query_nodes ) ) {
9061                 return false;
9062             }
9063             //
9064             query_nodes = new HashSet<PhylogenyNode>();
9065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9067             if ( s0.match( query_nodes ) ) {
9068                 return false;
9069             }
9070             //
9071             query_nodes = new HashSet<PhylogenyNode>();
9072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9075             if ( s0.match( query_nodes ) ) {
9076                 return false;
9077             }
9078             //
9079             query_nodes = new HashSet<PhylogenyNode>();
9080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9083             if ( s0.match( query_nodes ) ) {
9084                 return false;
9085             }
9086             //
9087             query_nodes = new HashSet<PhylogenyNode>();
9088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9091             if ( s0.match( query_nodes ) ) {
9092                 return false;
9093             }
9094             //
9095             query_nodes = new HashSet<PhylogenyNode>();
9096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9100             if ( s0.match( query_nodes ) ) {
9101                 return false;
9102             }
9103         }
9104         catch ( final Exception e ) {
9105             e.printStackTrace();
9106             return false;
9107         }
9108         return true;
9109     }
9110
9111     private static boolean testSubtreeDeletion() {
9112         try {
9113             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9114             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9115             t1.deleteSubtree( t1.getNode( "A" ), false );
9116             if ( t1.getNumberOfExternalNodes() != 5 ) {
9117                 return false;
9118             }
9119             t1.toNewHampshireX();
9120             t1.deleteSubtree( t1.getNode( "E" ), false );
9121             if ( t1.getNumberOfExternalNodes() != 4 ) {
9122                 return false;
9123             }
9124             t1.toNewHampshireX();
9125             t1.deleteSubtree( t1.getNode( "F" ), false );
9126             if ( t1.getNumberOfExternalNodes() != 3 ) {
9127                 return false;
9128             }
9129             t1.toNewHampshireX();
9130             t1.deleteSubtree( t1.getNode( "D" ), false );
9131             t1.toNewHampshireX();
9132             if ( t1.getNumberOfExternalNodes() != 3 ) {
9133                 return false;
9134             }
9135             t1.deleteSubtree( t1.getNode( "def" ), false );
9136             t1.toNewHampshireX();
9137             if ( t1.getNumberOfExternalNodes() != 2 ) {
9138                 return false;
9139             }
9140             t1.deleteSubtree( t1.getNode( "B" ), false );
9141             t1.toNewHampshireX();
9142             if ( t1.getNumberOfExternalNodes() != 1 ) {
9143                 return false;
9144             }
9145             t1.deleteSubtree( t1.getNode( "C" ), false );
9146             t1.toNewHampshireX();
9147             if ( t1.getNumberOfExternalNodes() != 1 ) {
9148                 return false;
9149             }
9150             t1.deleteSubtree( t1.getNode( "abc" ), false );
9151             t1.toNewHampshireX();
9152             if ( t1.getNumberOfExternalNodes() != 1 ) {
9153                 return false;
9154             }
9155             t1.deleteSubtree( t1.getNode( "r" ), false );
9156             if ( t1.getNumberOfExternalNodes() != 0 ) {
9157                 return false;
9158             }
9159             if ( !t1.isEmpty() ) {
9160                 return false;
9161             }
9162             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9163             t2.deleteSubtree( t2.getNode( "A" ), false );
9164             t2.toNewHampshireX();
9165             if ( t2.getNumberOfExternalNodes() != 5 ) {
9166                 return false;
9167             }
9168             t2.deleteSubtree( t2.getNode( "abc" ), false );
9169             t2.toNewHampshireX();
9170             if ( t2.getNumberOfExternalNodes() != 3 ) {
9171                 return false;
9172             }
9173             t2.deleteSubtree( t2.getNode( "def" ), false );
9174             t2.toNewHampshireX();
9175             if ( t2.getNumberOfExternalNodes() != 1 ) {
9176                 return false;
9177             }
9178         }
9179         catch ( final Exception e ) {
9180             e.printStackTrace( System.out );
9181             return false;
9182         }
9183         return true;
9184     }
9185
9186     private static boolean testSupportCount() {
9187         try {
9188             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9189             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9190             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9191                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9192                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9193                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9194                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9195                                                               new NHXParser() );
9196             SupportCount.count( t0_1, phylogenies_1, true, false );
9197             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9198             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9199                                                                       + "(((((A,B),C),D),E),((F,G),X))"
9200                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
9201                                                                       + "(((((A,B),C),D),E),(F,G))"
9202                                                                       + "(((((A,B),C),D),E),(F,G))"
9203                                                                       + "(((((A,B),C),D),E),(F,G))"
9204                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
9205                                                                       + "(((((A,B),C),D),E),(F,G))"
9206                                                                       + "((((((A,B),C),D),E),F),G)"
9207                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
9208                                                               new NHXParser() );
9209             SupportCount.count( t0_2, phylogenies_2, true, false );
9210             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9211             while ( it.hasNext() ) {
9212                 final PhylogenyNode n = it.next();
9213                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9214                     return false;
9215                 }
9216             }
9217             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9218             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9219                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9220             SupportCount.count( t0_3, phylogenies_3, true, false );
9221             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9222             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9223                 return false;
9224             }
9225             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9226                 return false;
9227             }
9228             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9229                 return false;
9230             }
9231             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9232                 return false;
9233             }
9234             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9235                 return false;
9236             }
9237             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9238                 return false;
9239             }
9240             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9241                 return false;
9242             }
9243             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9244                 return false;
9245             }
9246             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9247                 return false;
9248             }
9249             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9250                 return false;
9251             }
9252             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9253             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9254                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9255             SupportCount.count( t0_4, phylogenies_4, true, false );
9256             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9257             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9258                 return false;
9259             }
9260             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9261                 return false;
9262             }
9263             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9264                 return false;
9265             }
9266             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9267                 return false;
9268             }
9269             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9270                 return false;
9271             }
9272             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9273                 return false;
9274             }
9275             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9276                 return false;
9277             }
9278             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9279                 return false;
9280             }
9281             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9282                 return false;
9283             }
9284             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9285                 return false;
9286             }
9287             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9288             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9289             double d = SupportCount.compare( b1, a, true, true, true );
9290             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9291                 return false;
9292             }
9293             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9294             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9295             d = SupportCount.compare( b2, a, true, true, true );
9296             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9297                 return false;
9298             }
9299             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9300             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9301             d = SupportCount.compare( b3, a, true, true, true );
9302             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9303                 return false;
9304             }
9305             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9306             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9307             d = SupportCount.compare( b4, a, true, true, false );
9308             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9309                 return false;
9310             }
9311         }
9312         catch ( final Exception e ) {
9313             e.printStackTrace( System.out );
9314             return false;
9315         }
9316         return true;
9317     }
9318
9319     private static boolean testSupportTransfer() {
9320         try {
9321             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9322             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)",
9323                                                  new NHXParser() )[ 0 ];
9324             final Phylogeny p2 = factory
9325                     .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 ];
9326             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9327                 return false;
9328             }
9329             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9330                 return false;
9331             }
9332             support_transfer.moveBranchLengthsToBootstrap( p1 );
9333             support_transfer.transferSupportValues( p1, p2 );
9334             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9335                 return false;
9336             }
9337             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9338                 return false;
9339             }
9340             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9341                 return false;
9342             }
9343             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9344                 return false;
9345             }
9346             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9347                 return false;
9348             }
9349             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9350                 return false;
9351             }
9352             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9353                 return false;
9354             }
9355             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9356                 return false;
9357             }
9358         }
9359         catch ( final Exception e ) {
9360             e.printStackTrace( System.out );
9361             return false;
9362         }
9363         return true;
9364     }
9365
9366     private static boolean testUniprotTaxonomySearch() {
9367         try {
9368             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9369                                                                                                  10 );
9370             if ( results.size() != 1 ) {
9371                 return false;
9372             }
9373             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9374                 return false;
9375             }
9376             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9377                 return false;
9378             }
9379             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9380                 return false;
9381             }
9382             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9383                 return false;
9384             }
9385             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9386                 return false;
9387             }
9388             results = null;
9389             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9390             if ( results.size() != 1 ) {
9391                 return false;
9392             }
9393             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9394                 return false;
9395             }
9396             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9397                 return false;
9398             }
9399             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9400                 return false;
9401             }
9402             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9403                 return false;
9404             }
9405             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9406                 return false;
9407             }
9408             results = null;
9409             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9410             if ( results.size() != 1 ) {
9411                 return false;
9412             }
9413             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9414                 return false;
9415             }
9416             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9417                 return false;
9418             }
9419             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9420                 return false;
9421             }
9422             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9423                 return false;
9424             }
9425             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9426                 return false;
9427             }
9428             results = null;
9429             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9430             if ( results.size() != 1 ) {
9431                 return false;
9432             }
9433             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9434                 return false;
9435             }
9436             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9437                 return false;
9438             }
9439             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9440                 return false;
9441             }
9442             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9443                 return false;
9444             }
9445             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9446                 return false;
9447             }
9448             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9449                 return false;
9450             }
9451             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9452                 return false;
9453             }
9454             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9455                     .equals( "Nematostella vectensis" ) ) {
9456                 System.out.println( results.get( 0 ).getLineage() );
9457                 return false;
9458             }
9459         }
9460         catch ( final IOException e ) {
9461             System.out.println();
9462             System.out.println( "the following might be due to absence internet connection:" );
9463             e.printStackTrace( System.out );
9464             return true;
9465         }
9466         catch ( final Exception e ) {
9467             return false;
9468         }
9469         return true;
9470     }
9471
9472     private static boolean testEmblEntryRetrieval() {
9473         //The format for GenBank Accession numbers are:
9474         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9475         //Protein:    3 letters + 5 numerals
9476         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9477         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9478             return false;
9479         }
9480         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
9481             return false;
9482         }
9483         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
9484             return false;
9485         }
9486         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9487             return false;
9488         }
9489         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9490             return false;
9491         }
9492         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9493             return false;
9494         }
9495         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9496             return false;
9497         }
9498         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9499             return false;
9500         }
9501         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9502             return false;
9503         }
9504         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9505             return false;
9506         }
9507         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9508             return false;
9509         }
9510         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9511             return false;
9512         }
9513         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9514             return false;
9515         }
9516         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9517             return false;
9518         }
9519         return true;
9520     }
9521
9522     private static boolean testUniprotEntryRetrieval() {
9523         try {
9524             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9525             if ( !entry.getAccession().equals( "P12345" ) ) {
9526                 return false;
9527             }
9528             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9529                 return false;
9530             }
9531             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9532                 return false;
9533             }
9534             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9535                 return false;
9536             }
9537         }
9538         catch ( final IOException e ) {
9539             System.out.println();
9540             System.out.println( "the following might be due to absence internet connection:" );
9541             e.printStackTrace( System.out );
9542             return true;
9543         }
9544         catch ( final Exception e ) {
9545             return false;
9546         }
9547         return true;
9548     }
9549
9550     private static boolean testWabiTxSearch() {
9551         try {
9552             String result = "";
9553             result = TxSearch.searchSimple( "nematostella" );
9554             result = TxSearch.getTxId( "nematostella" );
9555             if ( !result.equals( "45350" ) ) {
9556                 return false;
9557             }
9558             result = TxSearch.getTxName( "45350" );
9559             if ( !result.equals( "Nematostella" ) ) {
9560                 return false;
9561             }
9562             result = TxSearch.getTxId( "nematostella vectensis" );
9563             if ( !result.equals( "45351" ) ) {
9564                 return false;
9565             }
9566             result = TxSearch.getTxName( "45351" );
9567             if ( !result.equals( "Nematostella vectensis" ) ) {
9568                 return false;
9569             }
9570             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9571             if ( !result.equals( "536089" ) ) {
9572                 return false;
9573             }
9574             result = TxSearch.getTxName( "536089" );
9575             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9576                 return false;
9577             }
9578             final List<String> queries = new ArrayList<String>();
9579             queries.add( "Campylobacter coli" );
9580             queries.add( "Escherichia coli" );
9581             queries.add( "Arabidopsis" );
9582             queries.add( "Trichoplax" );
9583             queries.add( "Samanea saman" );
9584             queries.add( "Kluyveromyces marxianus" );
9585             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9586             queries.add( "Bornavirus parrot/PDD/2008" );
9587             final List<RANKS> ranks = new ArrayList<RANKS>();
9588             ranks.add( RANKS.SUPERKINGDOM );
9589             ranks.add( RANKS.KINGDOM );
9590             ranks.add( RANKS.FAMILY );
9591             ranks.add( RANKS.GENUS );
9592             ranks.add( RANKS.TRIBE );
9593             result = TxSearch.searchLineage( queries, ranks );
9594             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9595             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9596         }
9597         catch ( final Exception e ) {
9598             System.out.println();
9599             System.out.println( "the following might be due to absence internet connection:" );
9600             e.printStackTrace( System.out );
9601             return false;
9602         }
9603         return true;
9604     }
9605
9606     private static boolean testAminoAcidSequence() {
9607         try {
9608             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9609             if ( aa1.getLength() != 13 ) {
9610                 return false;
9611             }
9612             if ( aa1.getResidueAt( 0 ) != 'A' ) {
9613                 return false;
9614             }
9615             if ( aa1.getResidueAt( 2 ) != 'K' ) {
9616                 return false;
9617             }
9618             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9619                 return false;
9620             }
9621             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9622             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9623                 return false;
9624             }
9625             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9626             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9627                 return false;
9628             }
9629             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9630             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9631                 return false;
9632             }
9633         }
9634         catch ( final Exception e ) {
9635             e.printStackTrace();
9636             return false;
9637         }
9638         return true;
9639     }
9640
9641     private static boolean testSequenceWriter() {
9642         try {
9643             final String n = ForesterUtil.LINE_SEPARATOR;
9644             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9645                 return false;
9646             }
9647             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9648                 return false;
9649             }
9650             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9651                 return false;
9652             }
9653             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9654                 return false;
9655             }
9656             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9657                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9658                 return false;
9659             }
9660             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9661                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9662                 return false;
9663             }
9664         }
9665         catch ( final Exception e ) {
9666             e.printStackTrace();
9667             return false;
9668         }
9669         return true;
9670     }
9671
9672     private static boolean testCreateBalancedPhylogeny() {
9673         try {
9674             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9675             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9676                 return false;
9677             }
9678             if ( p0.getNumberOfExternalNodes() != 15625 ) {
9679                 return false;
9680             }
9681             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9682             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9683                 return false;
9684             }
9685             if ( p1.getNumberOfExternalNodes() != 100 ) {
9686                 return false;
9687             }
9688         }
9689         catch ( final Exception e ) {
9690             e.printStackTrace();
9691             return false;
9692         }
9693         return true;
9694     }
9695
9696     private static boolean testFastaParser() {
9697         try {
9698             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9699                 return false;
9700             }
9701             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9702                 return false;
9703             }
9704             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9705             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9706                 return false;
9707             }
9708             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9709                 return false;
9710             }
9711             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9712                 return false;
9713             }
9714             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9715                 return false;
9716             }
9717             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9718                 return false;
9719             }
9720             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9721                 return false;
9722             }
9723         }
9724         catch ( final Exception e ) {
9725             e.printStackTrace();
9726             return false;
9727         }
9728         return true;
9729     }
9730
9731     private static boolean testGeneralMsaParser() {
9732         try {
9733             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9734             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9735             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9736             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9737             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9738             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9739             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9740             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9741             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9742                 return false;
9743             }
9744             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9745                 return false;
9746             }
9747             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9748                 return false;
9749             }
9750             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9751                 return false;
9752             }
9753             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9754                 return false;
9755             }
9756             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9757                 return false;
9758             }
9759             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9760                 return false;
9761             }
9762             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9763                 return false;
9764             }
9765             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9766                 return false;
9767             }
9768             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9769                 return false;
9770             }
9771             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9772                 return false;
9773             }
9774             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9775                 return false;
9776             }
9777             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9778             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9779                 return false;
9780             }
9781             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9782                 return false;
9783             }
9784             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9785                 return false;
9786             }
9787             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9788             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9789                 return false;
9790             }
9791             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9792                 return false;
9793             }
9794             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9795                 return false;
9796             }
9797             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9798             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9799                 return false;
9800             }
9801             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9802                 return false;
9803             }
9804             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9805                 return false;
9806             }
9807         }
9808         catch ( final Exception e ) {
9809             e.printStackTrace();
9810             return false;
9811         }
9812         return true;
9813     }
9814
9815     private static boolean testMafft( final String path ) {
9816         try {
9817             final List<String> opts = new ArrayList<String>();
9818             opts.add( "--maxiterate" );
9819             opts.add( "1000" );
9820             opts.add( "--localpair" );
9821             opts.add( "--quiet" );
9822             Msa msa = null;
9823             final MsaInferrer mafft = Mafft.createInstance( path );
9824             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9825             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9826                 return false;
9827             }
9828             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9829                 return false;
9830             }
9831         }
9832         catch ( final Exception e ) {
9833             e.printStackTrace( System.out );
9834             return false;
9835         }
9836         return true;
9837     }
9838
9839     private static boolean testNextNodeWithCollapsing() {
9840         try {
9841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9842             PhylogenyNode n;
9843             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9844             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9845             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9846             t0.getNode( "cd" ).setCollapse( true );
9847             t0.getNode( "cde" ).setCollapse( true );
9848             n = t0.getFirstExternalNode();
9849             while ( n != null ) {
9850                 ext.add( n );
9851                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9852             }
9853             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9854                 return false;
9855             }
9856             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9857                 return false;
9858             }
9859             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9860                 return false;
9861             }
9862             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9863                 return false;
9864             }
9865             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9866                 return false;
9867             }
9868             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9869                 return false;
9870             }
9871             ext.clear();
9872             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9873             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9874             t1.getNode( "ab" ).setCollapse( true );
9875             t1.getNode( "cd" ).setCollapse( true );
9876             t1.getNode( "cde" ).setCollapse( true );
9877             n = t1.getNode( "ab" );
9878             ext = new ArrayList<PhylogenyNode>();
9879             while ( n != null ) {
9880                 ext.add( n );
9881                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9882             }
9883             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9884                 return false;
9885             }
9886             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9887                 return false;
9888             }
9889             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9890                 return false;
9891             }
9892             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9893                 return false;
9894             }
9895             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9896                 return false;
9897             }
9898             //
9899             //
9900             ext.clear();
9901             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9902             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9903             t2.getNode( "ab" ).setCollapse( true );
9904             t2.getNode( "cd" ).setCollapse( true );
9905             t2.getNode( "cde" ).setCollapse( true );
9906             t2.getNode( "c" ).setCollapse( true );
9907             t2.getNode( "d" ).setCollapse( true );
9908             t2.getNode( "e" ).setCollapse( true );
9909             t2.getNode( "gh" ).setCollapse( true );
9910             n = t2.getNode( "ab" );
9911             ext = new ArrayList<PhylogenyNode>();
9912             while ( n != null ) {
9913                 ext.add( n );
9914                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9915             }
9916             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9917                 return false;
9918             }
9919             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9920                 return false;
9921             }
9922             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9923                 return false;
9924             }
9925             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9926                 return false;
9927             }
9928             //
9929             //
9930             ext.clear();
9931             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9932             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9933             t3.getNode( "ab" ).setCollapse( true );
9934             t3.getNode( "cd" ).setCollapse( true );
9935             t3.getNode( "cde" ).setCollapse( true );
9936             t3.getNode( "c" ).setCollapse( true );
9937             t3.getNode( "d" ).setCollapse( true );
9938             t3.getNode( "e" ).setCollapse( true );
9939             t3.getNode( "gh" ).setCollapse( true );
9940             t3.getNode( "fgh" ).setCollapse( true );
9941             n = t3.getNode( "ab" );
9942             ext = new ArrayList<PhylogenyNode>();
9943             while ( n != null ) {
9944                 ext.add( n );
9945                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9946             }
9947             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9948                 return false;
9949             }
9950             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9951                 return false;
9952             }
9953             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9954                 return false;
9955             }
9956             //
9957             //
9958             ext.clear();
9959             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9960             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9961             t4.getNode( "ab" ).setCollapse( true );
9962             t4.getNode( "cd" ).setCollapse( true );
9963             t4.getNode( "cde" ).setCollapse( true );
9964             t4.getNode( "c" ).setCollapse( true );
9965             t4.getNode( "d" ).setCollapse( true );
9966             t4.getNode( "e" ).setCollapse( true );
9967             t4.getNode( "gh" ).setCollapse( true );
9968             t4.getNode( "fgh" ).setCollapse( true );
9969             t4.getNode( "abcdefgh" ).setCollapse( true );
9970             n = t4.getNode( "abcdefgh" );
9971             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9972                 return false;
9973             }
9974             //
9975             //
9976             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9977             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9978             ext.clear();
9979             n = t5.getFirstExternalNode();
9980             while ( n != null ) {
9981                 ext.add( n );
9982                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9983             }
9984             if ( ext.size() != 8 ) {
9985                 return false;
9986             }
9987             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9988                 return false;
9989             }
9990             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9991                 return false;
9992             }
9993             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9994                 return false;
9995             }
9996             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9997                 return false;
9998             }
9999             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10000                 return false;
10001             }
10002             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10003                 return false;
10004             }
10005             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
10006                 return false;
10007             }
10008             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
10009                 return false;
10010             }
10011             //
10012             //
10013             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10014             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
10015             ext.clear();
10016             t6.getNode( "ab" ).setCollapse( true );
10017             n = t6.getNode( "ab" );
10018             while ( n != null ) {
10019                 ext.add( n );
10020                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10021             }
10022             if ( ext.size() != 7 ) {
10023                 return false;
10024             }
10025             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10026                 return false;
10027             }
10028             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10029                 return false;
10030             }
10031             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10032                 return false;
10033             }
10034             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10035                 return false;
10036             }
10037             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10038                 return false;
10039             }
10040             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10041                 return false;
10042             }
10043             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10044                 return false;
10045             }
10046             //
10047             //
10048             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10049             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
10050             ext.clear();
10051             t7.getNode( "cd" ).setCollapse( true );
10052             n = t7.getNode( "a" );
10053             while ( n != null ) {
10054                 ext.add( n );
10055                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10056             }
10057             if ( ext.size() != 7 ) {
10058                 return false;
10059             }
10060             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10061                 return false;
10062             }
10063             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10064                 return false;
10065             }
10066             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10067                 return false;
10068             }
10069             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10070                 return false;
10071             }
10072             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10073                 return false;
10074             }
10075             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10076                 return false;
10077             }
10078             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10079                 return false;
10080             }
10081             //
10082             //
10083             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10084             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
10085             ext.clear();
10086             t8.getNode( "cd" ).setCollapse( true );
10087             t8.getNode( "c" ).setCollapse( true );
10088             t8.getNode( "d" ).setCollapse( true );
10089             n = t8.getNode( "a" );
10090             while ( n != null ) {
10091                 ext.add( n );
10092                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10093             }
10094             if ( ext.size() != 7 ) {
10095                 return false;
10096             }
10097             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10098                 return false;
10099             }
10100             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10101                 return false;
10102             }
10103             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10104                 System.out.println( "2 fail" );
10105                 return false;
10106             }
10107             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10108                 return false;
10109             }
10110             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10111                 return false;
10112             }
10113             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10114                 return false;
10115             }
10116             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10117                 return false;
10118             }
10119             //
10120             //
10121             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10122             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10123             ext.clear();
10124             t9.getNode( "gh" ).setCollapse( true );
10125             n = t9.getNode( "a" );
10126             while ( n != null ) {
10127                 ext.add( n );
10128                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10129             }
10130             if ( ext.size() != 7 ) {
10131                 return false;
10132             }
10133             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10134                 return false;
10135             }
10136             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10137                 return false;
10138             }
10139             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10140                 return false;
10141             }
10142             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10143                 return false;
10144             }
10145             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10146                 return false;
10147             }
10148             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10149                 return false;
10150             }
10151             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10152                 return false;
10153             }
10154             //
10155             //
10156             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10157             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10158             ext.clear();
10159             t10.getNode( "gh" ).setCollapse( true );
10160             t10.getNode( "g" ).setCollapse( true );
10161             t10.getNode( "h" ).setCollapse( true );
10162             n = t10.getNode( "a" );
10163             while ( n != null ) {
10164                 ext.add( n );
10165                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10166             }
10167             if ( ext.size() != 7 ) {
10168                 return false;
10169             }
10170             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10171                 return false;
10172             }
10173             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10174                 return false;
10175             }
10176             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10177                 return false;
10178             }
10179             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10180                 return false;
10181             }
10182             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10183                 return false;
10184             }
10185             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10186                 return false;
10187             }
10188             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10189                 return false;
10190             }
10191             //
10192             //
10193             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10194             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10195             ext.clear();
10196             t11.getNode( "gh" ).setCollapse( true );
10197             t11.getNode( "fgh" ).setCollapse( true );
10198             n = t11.getNode( "a" );
10199             while ( n != null ) {
10200                 ext.add( n );
10201                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10202             }
10203             if ( ext.size() != 6 ) {
10204                 return false;
10205             }
10206             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10207                 return false;
10208             }
10209             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10210                 return false;
10211             }
10212             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10213                 return false;
10214             }
10215             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10216                 return false;
10217             }
10218             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10219                 return false;
10220             }
10221             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10222                 return false;
10223             }
10224             //
10225             //
10226             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10227             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10228             ext.clear();
10229             t12.getNode( "gh" ).setCollapse( true );
10230             t12.getNode( "fgh" ).setCollapse( true );
10231             t12.getNode( "g" ).setCollapse( true );
10232             t12.getNode( "h" ).setCollapse( true );
10233             t12.getNode( "f" ).setCollapse( true );
10234             n = t12.getNode( "a" );
10235             while ( n != null ) {
10236                 ext.add( n );
10237                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10238             }
10239             if ( ext.size() != 6 ) {
10240                 return false;
10241             }
10242             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10243                 return false;
10244             }
10245             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10246                 return false;
10247             }
10248             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10249                 return false;
10250             }
10251             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10252                 return false;
10253             }
10254             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10255                 return false;
10256             }
10257             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10258                 return false;
10259             }
10260             //
10261             //
10262             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10263             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10264             ext.clear();
10265             t13.getNode( "ab" ).setCollapse( true );
10266             t13.getNode( "b" ).setCollapse( true );
10267             t13.getNode( "fgh" ).setCollapse( true );
10268             t13.getNode( "gh" ).setCollapse( true );
10269             n = t13.getNode( "ab" );
10270             while ( n != null ) {
10271                 ext.add( n );
10272                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10273             }
10274             if ( ext.size() != 5 ) {
10275                 return false;
10276             }
10277             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10278                 return false;
10279             }
10280             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10281                 return false;
10282             }
10283             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10284                 return false;
10285             }
10286             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10287                 return false;
10288             }
10289             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10290                 return false;
10291             }
10292             //
10293             //
10294             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10295             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10296             ext.clear();
10297             t14.getNode( "ab" ).setCollapse( true );
10298             t14.getNode( "a" ).setCollapse( true );
10299             t14.getNode( "fgh" ).setCollapse( true );
10300             t14.getNode( "gh" ).setCollapse( true );
10301             n = t14.getNode( "ab" );
10302             while ( n != null ) {
10303                 ext.add( n );
10304                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10305             }
10306             if ( ext.size() != 5 ) {
10307                 return false;
10308             }
10309             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10310                 return false;
10311             }
10312             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10313                 return false;
10314             }
10315             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10316                 return false;
10317             }
10318             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10319                 return false;
10320             }
10321             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10322                 return false;
10323             }
10324             //
10325             //
10326             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" );
10327             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10328             ext.clear();
10329             t15.getNode( "ab" ).setCollapse( true );
10330             t15.getNode( "a" ).setCollapse( true );
10331             t15.getNode( "fgh" ).setCollapse( true );
10332             t15.getNode( "gh" ).setCollapse( true );
10333             n = t15.getNode( "ab" );
10334             while ( n != null ) {
10335                 ext.add( n );
10336                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10337             }
10338             if ( ext.size() != 6 ) {
10339                 return false;
10340             }
10341             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10342                 return false;
10343             }
10344             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10345                 return false;
10346             }
10347             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10348                 return false;
10349             }
10350             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10351                 return false;
10352             }
10353             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10354                 return false;
10355             }
10356             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10357                 return false;
10358             }
10359             //
10360             //
10361             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" );
10362             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10363             ext.clear();
10364             t16.getNode( "ab" ).setCollapse( true );
10365             t16.getNode( "a" ).setCollapse( true );
10366             t16.getNode( "fgh" ).setCollapse( true );
10367             t16.getNode( "gh" ).setCollapse( true );
10368             t16.getNode( "cd" ).setCollapse( true );
10369             t16.getNode( "cde" ).setCollapse( true );
10370             t16.getNode( "d" ).setCollapse( true );
10371             t16.getNode( "x" ).setCollapse( true );
10372             n = t16.getNode( "ab" );
10373             while ( n != null ) {
10374                 ext.add( n );
10375                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10376             }
10377             if ( ext.size() != 4 ) {
10378                 return false;
10379             }
10380             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10381                 return false;
10382             }
10383             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10384                 return false;
10385             }
10386             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10387                 return false;
10388             }
10389             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10390                 return false;
10391             }
10392         }
10393         catch ( final Exception e ) {
10394             e.printStackTrace( System.out );
10395             return false;
10396         }
10397         return true;
10398     }
10399
10400     private static boolean testMsaQualityMethod() {
10401         try {
10402             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10403             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10404             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10405             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10406             final List<Sequence> l = new ArrayList<Sequence>();
10407             l.add( s0 );
10408             l.add( s1 );
10409             l.add( s2 );
10410             l.add( s3 );
10411             final Msa msa = BasicMsa.createInstance( l );
10412             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10413                 return false;
10414             }
10415             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10416                 return false;
10417             }
10418             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10419                 return false;
10420             }
10421             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10422                 return false;
10423             }
10424         }
10425         catch ( final Exception e ) {
10426             e.printStackTrace( System.out );
10427             return false;
10428         }
10429         return true;
10430     }
10431
10432     private static boolean testSequenceIdParsing() {
10433         try {
10434             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10435             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10436                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10437                 if ( id != null ) {
10438                     System.out.println( "value   =" + id.getValue() );
10439                     System.out.println( "provider=" + id.getProvider() );
10440                 }
10441                 return false;
10442             }
10443             //
10444             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10445             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10446                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10447                 if ( id != null ) {
10448                     System.out.println( "value   =" + id.getValue() );
10449                     System.out.println( "provider=" + id.getProvider() );
10450                 }
10451                 return false;
10452             }
10453             //
10454             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10455             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10456                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10457                 if ( id != null ) {
10458                     System.out.println( "value   =" + id.getValue() );
10459                     System.out.println( "provider=" + id.getProvider() );
10460                 }
10461                 return false;
10462             }
10463             // 
10464             id = SequenceIdParser.parse( "gb_AAA96518_1" );
10465             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10466                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10467                 if ( id != null ) {
10468                     System.out.println( "value   =" + id.getValue() );
10469                     System.out.println( "provider=" + id.getProvider() );
10470                 }
10471                 return false;
10472             }
10473             // 
10474             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10475             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10476                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10477                 if ( id != null ) {
10478                     System.out.println( "value   =" + id.getValue() );
10479                     System.out.println( "provider=" + id.getProvider() );
10480                 }
10481                 return false;
10482             }
10483             // 
10484             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10485             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10486                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10487                 if ( id != null ) {
10488                     System.out.println( "value   =" + id.getValue() );
10489                     System.out.println( "provider=" + id.getProvider() );
10490                 }
10491                 return false;
10492             }
10493             // 
10494             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10495             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10496                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10497                 if ( id != null ) {
10498                     System.out.println( "value   =" + id.getValue() );
10499                     System.out.println( "provider=" + id.getProvider() );
10500                 }
10501                 return false;
10502             }
10503             // 
10504             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10505             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10506                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10507                 if ( id != null ) {
10508                     System.out.println( "value   =" + id.getValue() );
10509                     System.out.println( "provider=" + id.getProvider() );
10510                 }
10511                 return false;
10512             }
10513             // 
10514             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10515             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10516                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10517                 if ( id != null ) {
10518                     System.out.println( "value   =" + id.getValue() );
10519                     System.out.println( "provider=" + id.getProvider() );
10520                 }
10521                 return false;
10522             }
10523             // 
10524             id = SequenceIdParser.parse( "P4A123" );
10525             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10526                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10527                 if ( id != null ) {
10528                     System.out.println( "value   =" + id.getValue() );
10529                     System.out.println( "provider=" + id.getProvider() );
10530                 }
10531                 return false;
10532             }
10533             // 
10534             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10535             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10536                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10537                 if ( id != null ) {
10538                     System.out.println( "value   =" + id.getValue() );
10539                     System.out.println( "provider=" + id.getProvider() );
10540                 }
10541                 return false;
10542             }
10543             // 
10544             id = SequenceIdParser.parse( "XP_12345" );
10545             if ( id != null ) {
10546                 System.out.println( "value   =" + id.getValue() );
10547                 System.out.println( "provider=" + id.getProvider() );
10548                 return false;
10549             }
10550             // lcl_91970_unknown_
10551         }
10552         catch ( final Exception e ) {
10553             e.printStackTrace( System.out );
10554             return false;
10555         }
10556         return true;
10557     }
10558 }