remove single node root
[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: www.phylosoft.org/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.development.DevelopmentTools;
42 import org.forester.evoinference.TestPhylogenyReconstruction;
43 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
45 import org.forester.go.TestGo;
46 import org.forester.io.parsers.FastaParser;
47 import org.forester.io.parsers.GeneralMsaParser;
48 import org.forester.io.parsers.HmmscanPerDomainTableParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
50 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
51 import org.forester.io.parsers.nexus.NexusCharactersParser;
52 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
53 import org.forester.io.parsers.nhx.NHXParser;
54 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
55 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
56 import org.forester.io.parsers.tol.TolParser;
57 import org.forester.io.parsers.util.ParserUtils;
58 import org.forester.io.writers.PhylogenyWriter;
59 import org.forester.msa.BasicMsa;
60 import org.forester.msa.Mafft;
61 import org.forester.msa.Msa;
62 import org.forester.msa.MsaInferrer;
63 import org.forester.msa.MsaMethods;
64 import org.forester.pccx.TestPccx;
65 import org.forester.phylogeny.Phylogeny;
66 import org.forester.phylogeny.PhylogenyBranch;
67 import org.forester.phylogeny.PhylogenyMethods;
68 import org.forester.phylogeny.PhylogenyNode;
69 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
70 import org.forester.phylogeny.data.BinaryCharacters;
71 import org.forester.phylogeny.data.BranchWidth;
72 import org.forester.phylogeny.data.Confidence;
73 import org.forester.phylogeny.data.Distribution;
74 import org.forester.phylogeny.data.DomainArchitecture;
75 import org.forester.phylogeny.data.Event;
76 import org.forester.phylogeny.data.Identifier;
77 import org.forester.phylogeny.data.PhylogenyData;
78 import org.forester.phylogeny.data.PhylogenyDataUtil;
79 import org.forester.phylogeny.data.Polygon;
80 import org.forester.phylogeny.data.PropertiesMap;
81 import org.forester.phylogeny.data.Property;
82 import org.forester.phylogeny.data.Property.AppliesTo;
83 import org.forester.phylogeny.data.ProteinDomain;
84 import org.forester.phylogeny.data.Taxonomy;
85 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
86 import org.forester.phylogeny.factories.PhylogenyFactory;
87 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
88 import org.forester.protein.Protein;
89 import org.forester.rio.TestRIO;
90 import org.forester.sdi.SDI;
91 import org.forester.sdi.SDIR;
92 import org.forester.sdi.TestGSDI;
93 import org.forester.sequence.BasicSequence;
94 import org.forester.sequence.Sequence;
95 import org.forester.surfacing.TestSurfacing;
96 import org.forester.tools.ConfidenceAssessor;
97 import org.forester.tools.SupportCount;
98 import org.forester.tools.TreeSplitMatrix;
99 import org.forester.util.AsciiHistogram;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterConstants;
105 import org.forester.util.ForesterUtil;
106 import org.forester.util.GeneralTable;
107 import org.forester.util.SequenceIdParser;
108 import org.forester.ws.seqdb.SequenceDatabaseEntry;
109 import org.forester.ws.seqdb.SequenceDbWsTools;
110 import org.forester.ws.seqdb.UniProtTaxonomy;
111 import org.forester.ws.wabi.TxSearch;
112 import org.forester.ws.wabi.TxSearch.RANKS;
113 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
114 import org.forester.ws.wabi.TxSearch.TAX_RANK;
115
116 @SuppressWarnings( "unused")
117 public final class Test {
118
119     private final static double  ZERO_DIFF                 = 1.0E-9;
120     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
121                                                                    + ForesterUtil.getFileSeparator() + "test_data"
122                                                                    + ForesterUtil.getFileSeparator();
123     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
124                                                                    + ForesterUtil.getFileSeparator() + "resources"
125                                                                    + ForesterUtil.getFileSeparator();
126     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
127     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
128                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
129                                                                    + ForesterConstants.PHYLO_XML_XSD;
130     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
131                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
132                                                                    + ForesterConstants.PHYLO_XML_XSD;
133
134     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
135         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
136         return p;
137     }
138
139     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
140         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
141     }
142
143     public static boolean isEqual( final double a, final double b ) {
144         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
145     }
146
147     public static void main( final String[] args ) {
148         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
149         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
150                 + "]" );
151         Locale.setDefault( Locale.US );
152         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
153         int failed = 0;
154         int succeeded = 0;
155         System.out.print( "[Test if directory with files for testing exists/is readable: " );
156         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
157             System.out.println( "OK.]" );
158         }
159         else {
160             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
161             System.out.println( "Testing aborted." );
162             System.exit( -1 );
163         }
164         System.out.print( "[Test if resources directory exists/is readable: " );
165         if ( testDir( PATH_TO_RESOURCES ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         final long start_time = new Date().getTime();
174         System.out.print( "Sequence id parsing: " );
175         if ( testSequenceIdParsing() ) {
176             System.out.println( "OK." );
177             succeeded++;
178         }
179         else {
180             System.out.println( "failed." );
181             failed++;
182         }
183         System.out.print( "Hmmscan output parser: " );
184         if ( testHmmscanOutputParser() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.out.print( "Basic node methods: " );
193         if ( Test.testBasicNodeMethods() ) {
194             System.out.println( "OK." );
195             succeeded++;
196         }
197         else {
198             System.out.println( "failed." );
199             failed++;
200         }
201         System.out.print( "Taxonomy extraction: " );
202         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
203             System.out.println( "OK." );
204             succeeded++;
205         }
206         else {
207             System.out.println( "failed." );
208             failed++;
209         }
210         System.out.print( "Basic node construction and parsing of NHX (node level): " );
211         if ( Test.testNHXNodeParsing() ) {
212             System.out.println( "OK." );
213             succeeded++;
214         }
215         else {
216             System.out.println( "failed." );
217             failed++;
218         }
219         System.out.print( "NH parsing: " );
220         if ( Test.testNHParsing() ) {
221             System.out.println( "OK." );
222             succeeded++;
223         }
224         else {
225             System.out.println( "failed." );
226             failed++;
227         }
228         System.out.print( "Conversion to NHX (node level): " );
229         if ( Test.testNHXconversion() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "NHX parsing: " );
238         if ( Test.testNHXParsing() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "NHX parsing with quotes: " );
247         if ( Test.testNHXParsingQuotes() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "NHX parsing (MrBayes): " );
256         if ( Test.testNHXParsingMB() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Nexus characters parsing: " );
265         if ( Test.testNexusCharactersParsing() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "Nexus tree parsing: " );
274         if ( Test.testNexusTreeParsing() ) {
275             System.out.println( "OK." );
276             succeeded++;
277         }
278         else {
279             System.out.println( "failed." );
280             failed++;
281         }
282         System.out.print( "Nexus tree parsing (translating): " );
283         if ( Test.testNexusTreeParsingTranslating() ) {
284             System.out.println( "OK." );
285             succeeded++;
286         }
287         else {
288             System.out.println( "failed." );
289             failed++;
290         }
291         System.out.print( "Nexus matrix parsing: " );
292         if ( Test.testNexusMatrixParsing() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "Basic phyloXML parsing: " );
301         if ( Test.testBasicPhyloXMLparsing() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Basic phyloXML parsing (validating against schema): " );
310         if ( testBasicPhyloXMLparsingValidating() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
319         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "phyloXML Distribution Element: " );
328         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "Tol XML parsing: " );
337         if ( Test.testBasicTolXMLparsing() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "Copying of node data: " );
346         if ( Test.testCopyOfNodeData() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Basic tree methods: " );
355         if ( Test.testBasicTreeMethods() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "Postorder Iterator: " );
364         if ( Test.testPostOrderIterator() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "Preorder Iterator: " );
373         if ( Test.testPreOrderIterator() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "Levelorder Iterator: " );
382         if ( Test.testLevelOrderIterator() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Re-id methods: " );
391         if ( Test.testReIdMethods() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Methods on last external nodes: " );
400         if ( Test.testLastExternalNodeMethods() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Methods on external nodes: " );
409         if ( Test.testExternalNodeRelatedMethods() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Deletion of external nodes: " );
418         if ( Test.testDeletionOfExternalNodes() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Subtree deletion: " );
427         if ( Test.testSubtreeDeletion() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Phylogeny branch: " );
436         if ( Test.testPhylogenyBranch() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Rerooting: " );
445         if ( Test.testRerooting() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Mipoint rooting: " );
454         if ( Test.testMidpointrooting() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "Support count: " );
463         if ( Test.testSupportCount() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Support transfer: " );
472         if ( Test.testSupportTransfer() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Finding of LCA: " );
481         if ( Test.testGetLCA() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Finding of LCA 2: " );
490         if ( Test.testGetLCA2() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Calculation of distance between nodes: " );
499         if ( Test.testGetDistance() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Descriptive statistics: " );
508         if ( Test.testDescriptiveStatistics() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Data objects and methods: " );
517         if ( Test.testDataObjects() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Properties map: " );
526         if ( Test.testPropertiesMap() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "SDIse: " );
535         if ( Test.testSDIse() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "SDIunrooted: " );
544         if ( Test.testSDIunrooted() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "GSDI: " );
553         if ( TestGSDI.test() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "RIO: " );
562         if ( TestRIO.test() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Phylogeny reconstruction:" );
571         System.out.println();
572         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Analysis of domain architectures: " );
581         System.out.println();
582         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "GO: " );
591         System.out.println();
592         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
593             System.out.println( "OK." );
594             succeeded++;
595         }
596         else {
597             System.out.println( "failed." );
598             failed++;
599         }
600         System.out.print( "Modeling tools: " );
601         if ( TestPccx.test() ) {
602             System.out.println( "OK." );
603             succeeded++;
604         }
605         else {
606             System.out.println( "failed." );
607             failed++;
608         }
609         System.out.print( "Split Matrix strict: " );
610         if ( Test.testSplitStrict() ) {
611             System.out.println( "OK." );
612             succeeded++;
613         }
614         else {
615             System.out.println( "failed." );
616             failed++;
617         }
618         System.out.print( "Split Matrix: " );
619         if ( Test.testSplit() ) {
620             System.out.println( "OK." );
621             succeeded++;
622         }
623         else {
624             System.out.println( "failed." );
625             failed++;
626         }
627         System.out.print( "Confidence Assessor: " );
628         if ( Test.testConfidenceAssessor() ) {
629             System.out.println( "OK." );
630             succeeded++;
631         }
632         else {
633             System.out.println( "failed." );
634             failed++;
635         }
636         System.out.print( "Basic table: " );
637         if ( Test.testBasicTable() ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "General table: " );
646         if ( Test.testGeneralTable() ) {
647             System.out.println( "OK." );
648             succeeded++;
649         }
650         else {
651             System.out.println( "failed." );
652             failed++;
653         }
654         System.out.print( "Amino acid sequence: " );
655         if ( Test.testAminoAcidSequence() ) {
656             System.out.println( "OK." );
657             succeeded++;
658         }
659         else {
660             System.out.println( "failed." );
661             failed++;
662         }
663         System.out.print( "General MSA parser: " );
664         if ( Test.testGeneralMsaParser() ) {
665             System.out.println( "OK." );
666             succeeded++;
667         }
668         else {
669             System.out.println( "failed." );
670             failed++;
671         }
672         System.out.print( "Fasta parser for msa: " );
673         if ( Test.testFastaParser() ) {
674             System.out.println( "OK." );
675             succeeded++;
676         }
677         else {
678             System.out.println( "failed." );
679             failed++;
680         }
681         System.out.print( "Creation of balanced phylogeny: " );
682         if ( Test.testCreateBalancedPhylogeny() ) {
683             System.out.println( "OK." );
684             succeeded++;
685         }
686         else {
687             System.out.println( "failed." );
688             failed++;
689         }
690         System.out.print( "EMBL Entry Retrieval: " );
691         if ( Test.testEmblEntryRetrieval() ) {
692             System.out.println( "OK." );
693             succeeded++;
694         }
695         else {
696             System.out.println( "failed." );
697             failed++;
698         }
699         System.out.print( "Uniprot Entry Retrieval: " );
700         if ( Test.testUniprotEntryRetrieval() ) {
701             System.out.println( "OK." );
702             succeeded++;
703         }
704         else {
705             System.out.println( "failed." );
706             failed++;
707         }
708         System.out.print( "Uniprot Taxonomy Search: " );
709         if ( Test.testUniprotTaxonomySearch() ) {
710             System.out.println( "OK." );
711             succeeded++;
712         }
713         else {
714             System.out.println( "failed." );
715             failed++;
716         }
717         //----
718         String path = "";
719         final String os = ForesterUtil.OS_NAME.toLowerCase();
720         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
721             path = "/usr/local/bin/mafft";
722         }
723         else if ( os.indexOf( "win" ) >= 0 ) {
724             path = "C:\\Program Files\\mafft-win\\mafft.bat";
725         }
726         else {
727             path = "/home/czmasek/bin/mafft";
728         }
729         if ( !MsaInferrer.isInstalled( path ) ) {
730             path = "mafft";
731         }
732         if ( !MsaInferrer.isInstalled( path ) ) {
733             path = "/usr/local/bin/mafft";
734         }
735         if ( MsaInferrer.isInstalled( path ) ) {
736             System.out.print( "MAFFT (external program): " );
737             if ( Test.testMafft( path ) ) {
738                 System.out.println( "OK." );
739                 succeeded++;
740             }
741             else {
742                 System.out.println( "failed [will not count towards failed tests]" );
743             }
744         }
745         //----
746         System.out.print( "Next nodes with collapsed: " );
747         if ( Test.testNextNodeWithCollapsing() ) {
748             System.out.println( "OK." );
749             succeeded++;
750         }
751         else {
752             System.out.println( "failed." );
753             failed++;
754         }
755         System.out.print( "Simple MSA quality: " );
756         if ( Test.testMsaQualityMethod() ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.println();
765         final Runtime rt = java.lang.Runtime.getRuntime();
766         final long free_memory = rt.freeMemory() / 1000000;
767         final long total_memory = rt.totalMemory() / 1000000;
768         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
769                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
770         System.out.println();
771         System.out.println( "Successful tests: " + succeeded );
772         System.out.println( "Failed     tests: " + failed );
773         System.out.println();
774         if ( failed < 1 ) {
775             System.out.println( "OK." );
776         }
777         else {
778             System.out.println( "Not OK." );
779         }
780     }
781
782     private static boolean testExtractTaxonomyCodeFromNodeName() {
783         try {
784             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.YES ).equals( "MOUSE" ) ) {
785                 return false;
786             }
787             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
788                 return false;
789             }
790             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.YES ) != null ) {
791                 return false;
792             }
793             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", TAXONOMY_EXTRACTION.YES )
794                     .equals( "MOUSE" ) ) {
795                 return false;
796             }
797             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445", TAXONOMY_EXTRACTION.YES )
798                     .equals( "MOUSE" ) ) {
799                 return false;
800             }
801             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", TAXONOMY_EXTRACTION.YES )
802                     .equals( "MOUSE" ) ) {
803                 return false;
804             }
805             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
806                 return false;
807             }
808             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
809                 return false;
810             }
811             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", TAXONOMY_EXTRACTION.YES )
812                     .equals( "RAT" ) ) {
813                 return false;
814             }
815             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445", TAXONOMY_EXTRACTION.YES )
816                     .equals( "RAT" ) ) {
817                 return false;
818             }
819             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", TAXONOMY_EXTRACTION.YES )
820                     .equals( "RAT" ) ) {
821                 return false;
822             }
823             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
824                 return false;
825             }
826             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
827                 return false;
828             }
829             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
830                 return false;
831             }
832             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
833                     .equals( "PIG" ) ) {
834                 return false;
835             }
836             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.YES )
837                     .equals( "MOUSE" ) ) {
838                 return false;
839             }
840             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
841                     .equals( "MOUSE" ) ) {
842                 return false;
843             }
844         }
845         catch ( final Exception e ) {
846             e.printStackTrace( System.out );
847             return false;
848         }
849         return true;
850     }
851
852     private static boolean testBasicNodeMethods() {
853         try {
854             if ( PhylogenyNode.getNodeCount() != 0 ) {
855                 return false;
856             }
857             final PhylogenyNode n1 = new PhylogenyNode();
858             final PhylogenyNode n2 = PhylogenyNode
859                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
860             final PhylogenyNode n3 = PhylogenyNode
861                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
862             final PhylogenyNode n4 = PhylogenyNode
863                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
864             if ( n1.isHasAssignedEvent() ) {
865                 return false;
866             }
867             if ( PhylogenyNode.getNodeCount() != 4 ) {
868                 return false;
869             }
870             if ( n3.getIndicator() != 0 ) {
871                 return false;
872             }
873             if ( n3.getNumberOfExternalNodes() != 1 ) {
874                 return false;
875             }
876             if ( !n3.isExternal() ) {
877                 return false;
878             }
879             if ( !n3.isRoot() ) {
880                 return false;
881             }
882             if ( !n4.getName().equals( "n4" ) ) {
883                 return false;
884             }
885         }
886         catch ( final Exception e ) {
887             e.printStackTrace( System.out );
888             return false;
889         }
890         return true;
891     }
892
893     private static boolean testBasicPhyloXMLparsing() {
894         try {
895             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
896             final PhyloXmlParser xml_parser = new PhyloXmlParser();
897             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
898                                                               xml_parser );
899             if ( xml_parser.getErrorCount() > 0 ) {
900                 System.out.println( xml_parser.getErrorMessages().toString() );
901                 return false;
902             }
903             if ( phylogenies_0.length != 4 ) {
904                 return false;
905             }
906             final Phylogeny t1 = phylogenies_0[ 0 ];
907             final Phylogeny t2 = phylogenies_0[ 1 ];
908             final Phylogeny t3 = phylogenies_0[ 2 ];
909             final Phylogeny t4 = phylogenies_0[ 3 ];
910             if ( t1.getNumberOfExternalNodes() != 1 ) {
911                 return false;
912             }
913             if ( !t1.isRooted() ) {
914                 return false;
915             }
916             if ( t1.isRerootable() ) {
917                 return false;
918             }
919             if ( !t1.getType().equals( "gene_tree" ) ) {
920                 return false;
921             }
922             if ( t2.getNumberOfExternalNodes() != 2 ) {
923                 return false;
924             }
925             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
926                 return false;
927             }
928             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
929                 return false;
930             }
931             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
932                 return false;
933             }
934             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
935                 return false;
936             }
937             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
938                 return false;
939             }
940             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
941                 return false;
942             }
943             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
944                     .startsWith( "actgtgggggt" ) ) {
945                 return false;
946             }
947             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
948                     .startsWith( "ctgtgatgcat" ) ) {
949                 return false;
950             }
951             if ( t3.getNumberOfExternalNodes() != 4 ) {
952                 return false;
953             }
954             if ( !t1.getName().equals( "t1" ) ) {
955                 return false;
956             }
957             if ( !t2.getName().equals( "t2" ) ) {
958                 return false;
959             }
960             if ( !t3.getName().equals( "t3" ) ) {
961                 return false;
962             }
963             if ( !t4.getName().equals( "t4" ) ) {
964                 return false;
965             }
966             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
967                 return false;
968             }
969             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
970                 return false;
971             }
972             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
973                 return false;
974             }
975             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
976                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
977                 return false;
978             }
979             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
980                 return false;
981             }
982             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
983                 return false;
984             }
985             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
986                 return false;
987             }
988             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
989                     .equals( "apoptosis" ) ) {
990                 return false;
991             }
992             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
993                     .equals( "GO:0006915" ) ) {
994                 return false;
995             }
996             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
997                     .equals( "UniProtKB" ) ) {
998                 return false;
999             }
1000             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1001                     .equals( "experimental" ) ) {
1002                 return false;
1003             }
1004             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1005                     .equals( "function" ) ) {
1006                 return false;
1007             }
1008             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1009                     .getValue() != 1 ) {
1010                 return false;
1011             }
1012             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1013                     .getType().equals( "ml" ) ) {
1014                 return false;
1015             }
1016             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1017                     .equals( "apoptosis" ) ) {
1018                 return false;
1019             }
1020             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1021                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1022                 return false;
1023             }
1024             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1025                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1026                 return false;
1027             }
1028             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1029                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1030                 return false;
1031             }
1032             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1033                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1034                 return false;
1035             }
1036             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1037                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1038                 return false;
1039             }
1040             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1041                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1042                 return false;
1043             }
1044             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1045                     .equals( "GO:0005829" ) ) {
1046                 return false;
1047             }
1048             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1049                     .equals( "intracellular organelle" ) ) {
1050                 return false;
1051             }
1052             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1053                 return false;
1054             }
1055             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1056                     .equals( "UniProt link" ) ) ) {
1057                 return false;
1058             }
1059             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1060                 return false;
1061             }
1062         }
1063         catch ( final Exception e ) {
1064             e.printStackTrace( System.out );
1065             return false;
1066         }
1067         return true;
1068     }
1069
1070     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1071         try {
1072             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1073             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1074             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1075                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1076             }
1077             else {
1078                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1079             }
1080             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1081                                                               xml_parser );
1082             if ( xml_parser.getErrorCount() > 0 ) {
1083                 System.out.println( xml_parser.getErrorMessages().toString() );
1084                 return false;
1085             }
1086             if ( phylogenies_0.length != 4 ) {
1087                 return false;
1088             }
1089             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1090             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1091             if ( phylogenies_t1.length != 1 ) {
1092                 return false;
1093             }
1094             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1095             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1096                 return false;
1097             }
1098             if ( !t1_rt.isRooted() ) {
1099                 return false;
1100             }
1101             if ( t1_rt.isRerootable() ) {
1102                 return false;
1103             }
1104             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1105                 return false;
1106             }
1107             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1108             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1109             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1110             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1111                 return false;
1112             }
1113             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1114                 return false;
1115             }
1116             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1117                 return false;
1118             }
1119             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1120                 return false;
1121             }
1122             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1123                     .startsWith( "actgtgggggt" ) ) {
1124                 return false;
1125             }
1126             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1127                     .startsWith( "ctgtgatgcat" ) ) {
1128                 return false;
1129             }
1130             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1131             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1132             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1133             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1134             if ( phylogenies_1.length != 1 ) {
1135                 return false;
1136             }
1137             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1138             if ( !t3_rt.getName().equals( "t3" ) ) {
1139                 return false;
1140             }
1141             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1142                 return false;
1143             }
1144             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1145                 return false;
1146             }
1147             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1148                 return false;
1149             }
1150             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1151                 return false;
1152             }
1153             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1154                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1155                 return false;
1156             }
1157             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1158                 return false;
1159             }
1160             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1161                 return false;
1162             }
1163             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1164                     .equals( "UniProtKB" ) ) {
1165                 return false;
1166             }
1167             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1168                     .equals( "apoptosis" ) ) {
1169                 return false;
1170             }
1171             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1172                     .equals( "GO:0006915" ) ) {
1173                 return false;
1174             }
1175             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1176                     .equals( "UniProtKB" ) ) {
1177                 return false;
1178             }
1179             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1180                     .equals( "experimental" ) ) {
1181                 return false;
1182             }
1183             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1184                     .equals( "function" ) ) {
1185                 return false;
1186             }
1187             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1188                     .getValue() != 1 ) {
1189                 return false;
1190             }
1191             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1192                     .getType().equals( "ml" ) ) {
1193                 return false;
1194             }
1195             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1196                     .equals( "apoptosis" ) ) {
1197                 return false;
1198             }
1199             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1200                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1201                 return false;
1202             }
1203             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1204                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1205                 return false;
1206             }
1207             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1208                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1209                 return false;
1210             }
1211             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1212                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1213                 return false;
1214             }
1215             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1216                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1217                 return false;
1218             }
1219             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1220                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1221                 return false;
1222             }
1223             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1224                     .equals( "GO:0005829" ) ) {
1225                 return false;
1226             }
1227             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1228                     .equals( "intracellular organelle" ) ) {
1229                 return false;
1230             }
1231             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1232                 return false;
1233             }
1234             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1235                     .equals( "UniProt link" ) ) ) {
1236                 return false;
1237             }
1238             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1239                 return false;
1240             }
1241             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1242                 return false;
1243             }
1244             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1245                     .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." ) ) ) {
1246                 return false;
1247             }
1248             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1249                 return false;
1250             }
1251             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1252                 return false;
1253             }
1254             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1255                 return false;
1256             }
1257             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1258                 return false;
1259             }
1260             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1261                     .equals( "ncbi" ) ) {
1262                 return false;
1263             }
1264             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1265                 return false;
1266             }
1267             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1268                     .getName().equals( "B" ) ) {
1269                 return false;
1270             }
1271             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1272                     .getFrom() != 21 ) {
1273                 return false;
1274             }
1275             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1276                 return false;
1277             }
1278             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1279                     .getLength() != 24 ) {
1280                 return false;
1281             }
1282             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1283                     .getConfidence() != 2144 ) {
1284                 return false;
1285             }
1286             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1287                     .equals( "pfam" ) ) {
1288                 return false;
1289             }
1290             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1291                 return false;
1292             }
1293             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1294                 return false;
1295             }
1296             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1297                 return false;
1298             }
1299             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1300                 return false;
1301             }
1302             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1303             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1304                 return false;
1305             }
1306             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1307                 return false;
1308             }
1309             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1310                 return false;
1311             }
1312             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1313                 return false;
1314             }
1315             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1316                 return false;
1317             }
1318             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1319                 return false;
1320             }
1321             if ( taxbb.getSynonyms().size() != 2 ) {
1322                 return false;
1323             }
1324             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1325                 return false;
1326             }
1327             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1328                 return false;
1329             }
1330             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1331                 return false;
1332             }
1333             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1334                 return false;
1335             }
1336             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1337                 return false;
1338             }
1339             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1340                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1341                 ;
1342                 return false;
1343             }
1344             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1345                 return false;
1346             }
1347             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1348                 return false;
1349             }
1350             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1351                 return false;
1352             }
1353             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1354                 return false;
1355             }
1356             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1357                 return false;
1358             }
1359             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1360                 return false;
1361             }
1362             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1363                 return false;
1364             }
1365             //
1366             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1367                 return false;
1368             }
1369             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1370                     .equalsIgnoreCase( "435" ) ) {
1371                 return false;
1372             }
1373             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1374                 return false;
1375             }
1376             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1377                     .equalsIgnoreCase( "443.7" ) ) {
1378                 return false;
1379             }
1380             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1381                 return false;
1382             }
1383             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1384                 return false;
1385             }
1386             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1387                     .equalsIgnoreCase( "433" ) ) {
1388                 return false;
1389             }
1390         }
1391         catch ( final Exception e ) {
1392             e.printStackTrace( System.out );
1393             return false;
1394         }
1395         return true;
1396     }
1397
1398     private static boolean testBasicPhyloXMLparsingValidating() {
1399         try {
1400             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1401             PhyloXmlParser xml_parser = null;
1402             try {
1403                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1404             }
1405             catch ( final Exception e ) {
1406                 // Do nothing -- means were not running from jar.
1407             }
1408             if ( xml_parser == null ) {
1409                 xml_parser = new PhyloXmlParser();
1410                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1411                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1412                 }
1413                 else {
1414                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1415                 }
1416             }
1417             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1418                                                               xml_parser );
1419             if ( xml_parser.getErrorCount() > 0 ) {
1420                 System.out.println( xml_parser.getErrorMessages().toString() );
1421                 return false;
1422             }
1423             if ( phylogenies_0.length != 4 ) {
1424                 return false;
1425             }
1426             final Phylogeny t1 = phylogenies_0[ 0 ];
1427             final Phylogeny t2 = phylogenies_0[ 1 ];
1428             final Phylogeny t3 = phylogenies_0[ 2 ];
1429             final Phylogeny t4 = phylogenies_0[ 3 ];
1430             if ( !t1.getName().equals( "t1" ) ) {
1431                 return false;
1432             }
1433             if ( !t2.getName().equals( "t2" ) ) {
1434                 return false;
1435             }
1436             if ( !t3.getName().equals( "t3" ) ) {
1437                 return false;
1438             }
1439             if ( !t4.getName().equals( "t4" ) ) {
1440                 return false;
1441             }
1442             if ( t1.getNumberOfExternalNodes() != 1 ) {
1443                 return false;
1444             }
1445             if ( t2.getNumberOfExternalNodes() != 2 ) {
1446                 return false;
1447             }
1448             if ( t3.getNumberOfExternalNodes() != 4 ) {
1449                 return false;
1450             }
1451             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1452             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1453             if ( xml_parser.getErrorCount() > 0 ) {
1454                 System.out.println( "errors:" );
1455                 System.out.println( xml_parser.getErrorMessages().toString() );
1456                 return false;
1457             }
1458             if ( phylogenies_1.length != 4 ) {
1459                 return false;
1460             }
1461             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1462                                                               xml_parser );
1463             if ( xml_parser.getErrorCount() > 0 ) {
1464                 System.out.println( "errors:" );
1465                 System.out.println( xml_parser.getErrorMessages().toString() );
1466                 return false;
1467             }
1468             if ( phylogenies_2.length != 1 ) {
1469                 return false;
1470             }
1471             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1472                 return false;
1473             }
1474             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1475                                                               xml_parser );
1476             if ( xml_parser.getErrorCount() > 0 ) {
1477                 System.out.println( xml_parser.getErrorMessages().toString() );
1478                 return false;
1479             }
1480             if ( phylogenies_3.length != 2 ) {
1481                 return false;
1482             }
1483             final Phylogeny a = phylogenies_3[ 0 ];
1484             if ( !a.getName().equals( "tree 4" ) ) {
1485                 return false;
1486             }
1487             if ( a.getNumberOfExternalNodes() != 3 ) {
1488                 return false;
1489             }
1490             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1491                 return false;
1492             }
1493             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1494                 return false;
1495             }
1496             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1497                                                               xml_parser );
1498             if ( xml_parser.getErrorCount() > 0 ) {
1499                 System.out.println( xml_parser.getErrorMessages().toString() );
1500                 return false;
1501             }
1502             if ( phylogenies_4.length != 1 ) {
1503                 return false;
1504             }
1505             final Phylogeny s = phylogenies_4[ 0 ];
1506             if ( s.getNumberOfExternalNodes() != 6 ) {
1507                 return false;
1508             }
1509             s.getNode( "first" );
1510             s.getNode( "<>" );
1511             s.getNode( "\"<a'b&c'd\">\"" );
1512             s.getNode( "'''\"" );
1513             s.getNode( "\"\"\"" );
1514             s.getNode( "dick & doof" );
1515         }
1516         catch ( final Exception e ) {
1517             e.printStackTrace( System.out );
1518             return false;
1519         }
1520         return true;
1521     }
1522
1523     private static boolean testBasicTable() {
1524         try {
1525             final BasicTable<String> t0 = new BasicTable<String>();
1526             if ( t0.getNumberOfColumns() != 0 ) {
1527                 return false;
1528             }
1529             if ( t0.getNumberOfRows() != 0 ) {
1530                 return false;
1531             }
1532             t0.setValue( 3, 2, "23" );
1533             t0.setValue( 10, 1, "error" );
1534             t0.setValue( 10, 1, "110" );
1535             t0.setValue( 9, 1, "19" );
1536             t0.setValue( 1, 10, "101" );
1537             t0.setValue( 10, 10, "1010" );
1538             t0.setValue( 100, 10, "10100" );
1539             t0.setValue( 0, 0, "00" );
1540             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1541                 return false;
1542             }
1543             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1544                 return false;
1545             }
1546             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1547                 return false;
1548             }
1549             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1550                 return false;
1551             }
1552             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1553                 return false;
1554             }
1555             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1556                 return false;
1557             }
1558             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1559                 return false;
1560             }
1561             if ( t0.getNumberOfColumns() != 101 ) {
1562                 return false;
1563             }
1564             if ( t0.getNumberOfRows() != 11 ) {
1565                 return false;
1566             }
1567             if ( t0.getValueAsString( 49, 4 ) != null ) {
1568                 return false;
1569             }
1570             final String l = ForesterUtil.getLineSeparator();
1571             final StringBuffer source = new StringBuffer();
1572             source.append( "" + l );
1573             source.append( "# 1 1 1 1 1 1 1 1" + l );
1574             source.append( " 00 01 02 03" + l );
1575             source.append( "   10 11 12 13  " + l );
1576             source.append( "20 21 22 23 " + l );
1577             source.append( "    30  31    32 33" + l );
1578             source.append( "40 41 42 43" + l );
1579             source.append( "  # 1 1 1 1 1 " + l );
1580             source.append( "50 51 52 53 54" + l );
1581             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1582             if ( t1.getNumberOfColumns() != 5 ) {
1583                 return false;
1584             }
1585             if ( t1.getNumberOfRows() != 6 ) {
1586                 return false;
1587             }
1588             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1589                 return false;
1590             }
1591             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1592                 return false;
1593             }
1594             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1595                 return false;
1596             }
1597             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1598                 return false;
1599             }
1600             final StringBuffer source1 = new StringBuffer();
1601             source1.append( "" + l );
1602             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1603             source1.append( " 00; 01 ;02;03" + l );
1604             source1.append( "   10; 11; 12; 13  " + l );
1605             source1.append( "20; 21; 22; 23 " + l );
1606             source1.append( "    30;  31;    32; 33" + l );
1607             source1.append( "40;41;42;43" + l );
1608             source1.append( "  # 1 1 1 1 1 " + l );
1609             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
1610             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1611             if ( t2.getNumberOfColumns() != 5 ) {
1612                 return false;
1613             }
1614             if ( t2.getNumberOfRows() != 6 ) {
1615                 return false;
1616             }
1617             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1618                 return false;
1619             }
1620             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1621                 return false;
1622             }
1623             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1624                 return false;
1625             }
1626             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1627                 return false;
1628             }
1629             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1630                 return false;
1631             }
1632             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1633                 return false;
1634             }
1635             final StringBuffer source2 = new StringBuffer();
1636             source2.append( "" + l );
1637             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1638             source2.append( " 00; 01 ;02;03" + l );
1639             source2.append( "   10; 11; 12; 13  " + l );
1640             source2.append( "20; 21; 22; 23 " + l );
1641             source2.append( "                     " + l );
1642             source2.append( "    30;  31;    32; 33" + l );
1643             source2.append( "40;41;42;43" + l );
1644             source2.append( "  comment: 1 1 1 1 1 " + l );
1645             source2.append( ";;;50  ;   52; 53;;54   " + l );
1646             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1647                                                                         ";",
1648                                                                         false,
1649                                                                         false,
1650                                                                         "comment:",
1651                                                                         false );
1652             if ( tl.size() != 2 ) {
1653                 return false;
1654             }
1655             final BasicTable<String> t3 = tl.get( 0 );
1656             final BasicTable<String> t4 = tl.get( 1 );
1657             if ( t3.getNumberOfColumns() != 4 ) {
1658                 return false;
1659             }
1660             if ( t3.getNumberOfRows() != 3 ) {
1661                 return false;
1662             }
1663             if ( t4.getNumberOfColumns() != 4 ) {
1664                 return false;
1665             }
1666             if ( t4.getNumberOfRows() != 3 ) {
1667                 return false;
1668             }
1669             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1670                 return false;
1671             }
1672             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1673                 return false;
1674             }
1675         }
1676         catch ( final Exception e ) {
1677             e.printStackTrace( System.out );
1678             return false;
1679         }
1680         return true;
1681     }
1682
1683     private static boolean testBasicTolXMLparsing() {
1684         try {
1685             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1686             final TolParser parser = new TolParser();
1687             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1688             if ( parser.getErrorCount() > 0 ) {
1689                 System.out.println( parser.getErrorMessages().toString() );
1690                 return false;
1691             }
1692             if ( phylogenies_0.length != 1 ) {
1693                 return false;
1694             }
1695             final Phylogeny t1 = phylogenies_0[ 0 ];
1696             if ( t1.getNumberOfExternalNodes() != 5 ) {
1697                 return false;
1698             }
1699             if ( !t1.isRooted() ) {
1700                 return false;
1701             }
1702             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
1703                 return false;
1704             }
1705             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
1706                 return false;
1707             }
1708             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
1709                 return false;
1710             }
1711             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
1712                 return false;
1713             }
1714             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
1715             if ( parser.getErrorCount() > 0 ) {
1716                 System.out.println( parser.getErrorMessages().toString() );
1717                 return false;
1718             }
1719             if ( phylogenies_1.length != 1 ) {
1720                 return false;
1721             }
1722             final Phylogeny t2 = phylogenies_1[ 0 ];
1723             if ( t2.getNumberOfExternalNodes() != 664 ) {
1724                 return false;
1725             }
1726             if ( !t2.isRooted() ) {
1727                 return false;
1728             }
1729             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
1730                 return false;
1731             }
1732             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
1733                 return false;
1734             }
1735             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1736                 return false;
1737             }
1738             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1739                 return false;
1740             }
1741             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
1742                 return false;
1743             }
1744             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
1745                     .equals( "Aquifex" ) ) {
1746                 return false;
1747             }
1748             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
1749             if ( parser.getErrorCount() > 0 ) {
1750                 System.out.println( parser.getErrorMessages().toString() );
1751                 return false;
1752             }
1753             if ( phylogenies_2.length != 1 ) {
1754                 return false;
1755             }
1756             final Phylogeny t3 = phylogenies_2[ 0 ];
1757             if ( t3.getNumberOfExternalNodes() != 184 ) {
1758                 return false;
1759             }
1760             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
1761                 return false;
1762             }
1763             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
1764                 return false;
1765             }
1766             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
1767                 return false;
1768             }
1769             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
1770             if ( parser.getErrorCount() > 0 ) {
1771                 System.out.println( parser.getErrorMessages().toString() );
1772                 return false;
1773             }
1774             if ( phylogenies_3.length != 1 ) {
1775                 return false;
1776             }
1777             final Phylogeny t4 = phylogenies_3[ 0 ];
1778             if ( t4.getNumberOfExternalNodes() != 1 ) {
1779                 return false;
1780             }
1781             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
1782                 return false;
1783             }
1784             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
1785                 return false;
1786             }
1787             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
1788                 return false;
1789             }
1790             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
1791             if ( parser.getErrorCount() > 0 ) {
1792                 System.out.println( parser.getErrorMessages().toString() );
1793                 return false;
1794             }
1795             if ( phylogenies_4.length != 1 ) {
1796                 return false;
1797             }
1798             final Phylogeny t5 = phylogenies_4[ 0 ];
1799             if ( t5.getNumberOfExternalNodes() != 13 ) {
1800                 return false;
1801             }
1802             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
1803                 return false;
1804             }
1805             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
1806                 return false;
1807             }
1808             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
1809                 return false;
1810             }
1811         }
1812         catch ( final Exception e ) {
1813             e.printStackTrace( System.out );
1814             return false;
1815         }
1816         return true;
1817     }
1818
1819     private static boolean testBasicTreeMethods() {
1820         try {
1821             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1822             final Phylogeny t1 = factory.create();
1823             if ( !t1.isEmpty() ) {
1824                 return false;
1825             }
1826             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
1827             if ( t2.getNumberOfExternalNodes() != 4 ) {
1828                 return false;
1829             }
1830             if ( t2.getHeight() != 8.5 ) {
1831                 return false;
1832             }
1833             if ( !t2.isCompletelyBinary() ) {
1834                 return false;
1835             }
1836             if ( t2.isEmpty() ) {
1837                 return false;
1838             }
1839             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
1840             if ( t3.getNumberOfExternalNodes() != 5 ) {
1841                 return false;
1842             }
1843             if ( t3.getHeight() != 11 ) {
1844                 return false;
1845             }
1846             if ( t3.isCompletelyBinary() ) {
1847                 return false;
1848             }
1849             final PhylogenyNode n = t3.getNode( "ABC" );
1850             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 ];
1851             if ( t4.getNumberOfExternalNodes() != 9 ) {
1852                 return false;
1853             }
1854             if ( t4.getHeight() != 11 ) {
1855                 return false;
1856             }
1857             if ( t4.isCompletelyBinary() ) {
1858                 return false;
1859             }
1860             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)" );
1861             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
1862             if ( t5.getNumberOfExternalNodes() != 8 ) {
1863                 return false;
1864             }
1865             if ( t5.getHeight() != 15 ) {
1866                 return false;
1867             }
1868             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)" );
1869             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
1870             if ( t6.getHeight() != 15 ) {
1871                 return false;
1872             }
1873             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)" );
1874             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
1875             if ( t7.getHeight() != 15 ) {
1876                 return false;
1877             }
1878             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)" );
1879             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
1880             if ( t8.getNumberOfExternalNodes() != 10 ) {
1881                 return false;
1882             }
1883             if ( t8.getHeight() != 15 ) {
1884                 return false;
1885             }
1886             final char[] a9 = new char[] {};
1887             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
1888             if ( t9.getHeight() != 0 ) {
1889                 return false;
1890             }
1891             final char[] a10 = new char[] { 'a', ':', '6' };
1892             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
1893             if ( t10.getHeight() != 6 ) {
1894                 return false;
1895             }
1896         }
1897         catch ( final Exception e ) {
1898             e.printStackTrace( System.out );
1899             return false;
1900         }
1901         return true;
1902     }
1903
1904     private static boolean testConfidenceAssessor() {
1905         try {
1906             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1907             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1908             final Phylogeny[] ev0 = factory
1909                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
1910                              new NHXParser() );
1911             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
1912             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1913                 return false;
1914             }
1915             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1916                 return false;
1917             }
1918             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1919             final Phylogeny[] ev1 = factory
1920                     .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)));",
1921                              new NHXParser() );
1922             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
1923             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
1924                 return false;
1925             }
1926             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1927                 return false;
1928             }
1929             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1930             final Phylogeny[] ev_b = factory
1931                     .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",
1932                              new NHXParser() );
1933             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
1934             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
1935                 return false;
1936             }
1937             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1938                 return false;
1939             }
1940             //
1941             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1942             final Phylogeny[] ev1x = factory
1943                     .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)));",
1944                              new NHXParser() );
1945             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
1946             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1947                 return false;
1948             }
1949             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1950                 return false;
1951             }
1952             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1953             final Phylogeny[] ev_bx = factory
1954                     .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",
1955                              new NHXParser() );
1956             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
1957             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1958                 return false;
1959             }
1960             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1961                 return false;
1962             }
1963             //
1964             final Phylogeny[] t2 = factory
1965                     .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);",
1966                              new NHXParser() );
1967             final Phylogeny[] ev2 = factory
1968                     .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);",
1969                              new NHXParser() );
1970             for( final Phylogeny target : t2 ) {
1971                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
1972             }
1973             //
1974             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
1975                                                  new NHXParser() )[ 0 ];
1976             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
1977             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
1978             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1979                 return false;
1980             }
1981             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
1982                 return false;
1983             }
1984             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1985                 return false;
1986             }
1987         }
1988         catch ( final Exception e ) {
1989             e.printStackTrace();
1990             return false;
1991         }
1992         return true;
1993     }
1994
1995     private static boolean testCopyOfNodeData() {
1996         try {
1997             final PhylogenyNode n1 = PhylogenyNode
1998                     .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]" );
1999             final PhylogenyNode n2 = n1.copyNodeData();
2000             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2001                 return false;
2002             }
2003         }
2004         catch ( final Exception e ) {
2005             e.printStackTrace();
2006             return false;
2007         }
2008         return true;
2009     }
2010
2011     private static boolean testDataObjects() {
2012         try {
2013             final Confidence s0 = new Confidence();
2014             final Confidence s1 = new Confidence();
2015             if ( !s0.isEqual( s1 ) ) {
2016                 return false;
2017             }
2018             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2019             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2020             if ( s2.isEqual( s1 ) ) {
2021                 return false;
2022             }
2023             if ( !s2.isEqual( s3 ) ) {
2024                 return false;
2025             }
2026             final Confidence s4 = ( Confidence ) s3.copy();
2027             if ( !s4.isEqual( s3 ) ) {
2028                 return false;
2029             }
2030             s3.asSimpleText();
2031             s3.asText();
2032             // Taxonomy
2033             // ----------
2034             final Taxonomy t1 = new Taxonomy();
2035             final Taxonomy t2 = new Taxonomy();
2036             final Taxonomy t3 = new Taxonomy();
2037             final Taxonomy t4 = new Taxonomy();
2038             final Taxonomy t5 = new Taxonomy();
2039             t1.setIdentifier( new Identifier( "ecoli" ) );
2040             t1.setTaxonomyCode( "ECOLI" );
2041             t1.setScientificName( "E. coli" );
2042             t1.setCommonName( "coli" );
2043             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2044             if ( !t1.isEqual( t0 ) ) {
2045                 return false;
2046             }
2047             t2.setIdentifier( new Identifier( "ecoli" ) );
2048             t2.setTaxonomyCode( "OTHER" );
2049             t2.setScientificName( "what" );
2050             t2.setCommonName( "something" );
2051             if ( !t1.isEqual( t2 ) ) {
2052                 return false;
2053             }
2054             t2.setIdentifier( new Identifier( "nemve" ) );
2055             if ( t1.isEqual( t2 ) ) {
2056                 return false;
2057             }
2058             t1.setIdentifier( null );
2059             t3.setTaxonomyCode( "ECOLI" );
2060             t3.setScientificName( "what" );
2061             t3.setCommonName( "something" );
2062             if ( !t1.isEqual( t3 ) ) {
2063                 return false;
2064             }
2065             t1.setIdentifier( null );
2066             t1.setTaxonomyCode( "" );
2067             t4.setScientificName( "E. ColI" );
2068             t4.setCommonName( "something" );
2069             if ( !t1.isEqual( t4 ) ) {
2070                 return false;
2071             }
2072             t4.setScientificName( "B. subtilis" );
2073             t4.setCommonName( "something" );
2074             if ( t1.isEqual( t4 ) ) {
2075                 return false;
2076             }
2077             t1.setIdentifier( null );
2078             t1.setTaxonomyCode( "" );
2079             t1.setScientificName( "" );
2080             t5.setCommonName( "COLI" );
2081             if ( !t1.isEqual( t5 ) ) {
2082                 return false;
2083             }
2084             t5.setCommonName( "vibrio" );
2085             if ( t1.isEqual( t5 ) ) {
2086                 return false;
2087             }
2088             // Identifier
2089             // ----------
2090             final Identifier id0 = new Identifier( "123", "pfam" );
2091             final Identifier id1 = ( Identifier ) id0.copy();
2092             if ( !id1.isEqual( id1 ) ) {
2093                 return false;
2094             }
2095             if ( !id1.isEqual( id0 ) ) {
2096                 return false;
2097             }
2098             if ( !id0.isEqual( id1 ) ) {
2099                 return false;
2100             }
2101             id1.asSimpleText();
2102             id1.asText();
2103             // ProteinDomain
2104             // ---------------
2105             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2106             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2107             if ( !pd1.isEqual( pd1 ) ) {
2108                 return false;
2109             }
2110             if ( !pd1.isEqual( pd0 ) ) {
2111                 return false;
2112             }
2113             pd1.asSimpleText();
2114             pd1.asText();
2115             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2116             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2117             if ( !pd3.isEqual( pd3 ) ) {
2118                 return false;
2119             }
2120             if ( !pd2.isEqual( pd3 ) ) {
2121                 return false;
2122             }
2123             if ( !pd0.isEqual( pd3 ) ) {
2124                 return false;
2125             }
2126             pd3.asSimpleText();
2127             pd3.asText();
2128             // DomainArchitecture
2129             // ------------------
2130             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2131             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2132             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2133             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2134             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2135             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2136             domains0.add( d2 );
2137             domains0.add( d0 );
2138             domains0.add( d3 );
2139             domains0.add( d1 );
2140             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2141             if ( ds0.getNumberOfDomains() != 4 ) {
2142                 return false;
2143             }
2144             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2145             if ( !ds0.isEqual( ds0 ) ) {
2146                 return false;
2147             }
2148             if ( !ds0.isEqual( ds1 ) ) {
2149                 return false;
2150             }
2151             if ( ds1.getNumberOfDomains() != 4 ) {
2152                 return false;
2153             }
2154             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2155             domains1.add( d1 );
2156             domains1.add( d2 );
2157             domains1.add( d4 );
2158             domains1.add( d0 );
2159             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2160             if ( ds0.isEqual( ds2 ) ) {
2161                 return false;
2162             }
2163             ds1.asSimpleText();
2164             ds1.asText();
2165             ds1.toNHX();
2166             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2167             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2168                 System.out.println( ds3.toNHX() );
2169                 return false;
2170             }
2171             if ( ds3.getNumberOfDomains() != 3 ) {
2172                 return false;
2173             }
2174             // Event
2175             // -----
2176             final Event e1 = new Event( Event.EventType.fusion );
2177             if ( e1.isDuplication() ) {
2178                 return false;
2179             }
2180             if ( !e1.isFusion() ) {
2181                 return false;
2182             }
2183             if ( !e1.asText().toString().equals( "fusion" ) ) {
2184                 return false;
2185             }
2186             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2187                 return false;
2188             }
2189             final Event e11 = new Event( Event.EventType.fusion );
2190             if ( !e11.isEqual( e1 ) ) {
2191                 return false;
2192             }
2193             if ( !e11.toNHX().toString().equals( "" ) ) {
2194                 return false;
2195             }
2196             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2197             if ( e2.isDuplication() ) {
2198                 return false;
2199             }
2200             if ( !e2.isSpeciationOrDuplication() ) {
2201                 return false;
2202             }
2203             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2204                 return false;
2205             }
2206             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2207                 return false;
2208             }
2209             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2210                 return false;
2211             }
2212             if ( e11.isEqual( e2 ) ) {
2213                 return false;
2214             }
2215             final Event e2c = ( Event ) e2.copy();
2216             if ( !e2c.isEqual( e2 ) ) {
2217                 return false;
2218             }
2219             Event e3 = new Event( 1, 2, 3 );
2220             if ( e3.isDuplication() ) {
2221                 return false;
2222             }
2223             if ( e3.isSpeciation() ) {
2224                 return false;
2225             }
2226             if ( e3.isGeneLoss() ) {
2227                 return false;
2228             }
2229             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2230                 return false;
2231             }
2232             final Event e3c = ( Event ) e3.copy();
2233             final Event e3cc = ( Event ) e3c.copy();
2234             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2235                 return false;
2236             }
2237             e3 = null;
2238             if ( !e3c.isEqual( e3cc ) ) {
2239                 return false;
2240             }
2241             Event e4 = new Event( 1, 2, 3 );
2242             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2243                 return false;
2244             }
2245             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2246                 return false;
2247             }
2248             final Event e4c = ( Event ) e4.copy();
2249             e4 = null;
2250             final Event e4cc = ( Event ) e4c.copy();
2251             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2252                 return false;
2253             }
2254             if ( !e4c.isEqual( e4cc ) ) {
2255                 return false;
2256             }
2257             final Event e5 = new Event();
2258             if ( !e5.isUnassigned() ) {
2259                 return false;
2260             }
2261             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2262                 return false;
2263             }
2264             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2265                 return false;
2266             }
2267             final Event e6 = new Event( 1, 0, 0 );
2268             if ( !e6.asText().toString().equals( "duplication" ) ) {
2269                 return false;
2270             }
2271             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2272                 return false;
2273             }
2274             final Event e7 = new Event( 0, 1, 0 );
2275             if ( !e7.asText().toString().equals( "speciation" ) ) {
2276                 return false;
2277             }
2278             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2279                 return false;
2280             }
2281             final Event e8 = new Event( 0, 0, 1 );
2282             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2283                 return false;
2284             }
2285             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2286                 return false;
2287             }
2288         }
2289         catch ( final Exception e ) {
2290             e.printStackTrace( System.out );
2291             return false;
2292         }
2293         return true;
2294     }
2295
2296     private static boolean testDeletionOfExternalNodes() {
2297         try {
2298             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2299             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2300             final PhylogenyWriter w = new PhylogenyWriter();
2301             if ( t0.isEmpty() ) {
2302                 return false;
2303             }
2304             if ( t0.getNumberOfExternalNodes() != 1 ) {
2305                 return false;
2306             }
2307             t0.deleteSubtree( t0.getNode( "A" ), false );
2308             if ( t0.getNumberOfExternalNodes() != 0 ) {
2309                 return false;
2310             }
2311             if ( !t0.isEmpty() ) {
2312                 return false;
2313             }
2314             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2315             if ( t1.getNumberOfExternalNodes() != 2 ) {
2316                 return false;
2317             }
2318             t1.deleteSubtree( t1.getNode( "A" ), false );
2319             if ( t1.getNumberOfExternalNodes() != 1 ) {
2320                 return false;
2321             }
2322             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2323                 return false;
2324             }
2325             t1.deleteSubtree( t1.getNode( "B" ), false );
2326             if ( t1.getNumberOfExternalNodes() != 1 ) {
2327                 return false;
2328             }
2329             t1.deleteSubtree( t1.getNode( "r" ), false );
2330             if ( !t1.isEmpty() ) {
2331                 return false;
2332             }
2333             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2334             if ( t2.getNumberOfExternalNodes() != 3 ) {
2335                 return false;
2336             }
2337             t2.deleteSubtree( t2.getNode( "B" ), false );
2338             if ( t2.getNumberOfExternalNodes() != 2 ) {
2339                 return false;
2340             }
2341             t2.toNewHampshireX();
2342             PhylogenyNode n = t2.getNode( "A" );
2343             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2344                 return false;
2345             }
2346             t2.deleteSubtree( t2.getNode( "A" ), false );
2347             if ( t2.getNumberOfExternalNodes() != 2 ) {
2348                 return false;
2349             }
2350             t2.deleteSubtree( t2.getNode( "C" ), true );
2351             if ( t2.getNumberOfExternalNodes() != 1 ) {
2352                 return false;
2353             }
2354             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2355             if ( t3.getNumberOfExternalNodes() != 4 ) {
2356                 return false;
2357             }
2358             t3.deleteSubtree( t3.getNode( "B" ), true );
2359             if ( t3.getNumberOfExternalNodes() != 3 ) {
2360                 return false;
2361             }
2362             n = t3.getNode( "A" );
2363             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2364                 return false;
2365             }
2366             n = n.getNextExternalNode();
2367             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2368                 return false;
2369             }
2370             t3.deleteSubtree( t3.getNode( "A" ), true );
2371             if ( t3.getNumberOfExternalNodes() != 2 ) {
2372                 return false;
2373             }
2374             n = t3.getNode( "C" );
2375             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2376                 return false;
2377             }
2378             t3.deleteSubtree( t3.getNode( "C" ), true );
2379             if ( t3.getNumberOfExternalNodes() != 1 ) {
2380                 return false;
2381             }
2382             t3.deleteSubtree( t3.getNode( "D" ), true );
2383             if ( t3.getNumberOfExternalNodes() != 0 ) {
2384                 return false;
2385             }
2386             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2387             if ( t4.getNumberOfExternalNodes() != 6 ) {
2388                 return false;
2389             }
2390             t4.deleteSubtree( t4.getNode( "B2" ), true );
2391             if ( t4.getNumberOfExternalNodes() != 5 ) {
2392                 return false;
2393             }
2394             String s = w.toNewHampshire( t4, false, true ).toString();
2395             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2396                 return false;
2397             }
2398             t4.deleteSubtree( t4.getNode( "B11" ), true );
2399             if ( t4.getNumberOfExternalNodes() != 4 ) {
2400                 return false;
2401             }
2402             t4.deleteSubtree( t4.getNode( "C" ), true );
2403             if ( t4.getNumberOfExternalNodes() != 3 ) {
2404                 return false;
2405             }
2406             n = t4.getNode( "A" );
2407             n = n.getNextExternalNode();
2408             if ( !n.getName().equals( "B12" ) ) {
2409                 return false;
2410             }
2411             n = n.getNextExternalNode();
2412             if ( !n.getName().equals( "D" ) ) {
2413                 return false;
2414             }
2415             s = w.toNewHampshire( t4, false, true ).toString();
2416             if ( !s.equals( "((A,B12),D);" ) ) {
2417                 return false;
2418             }
2419             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2420             t5.deleteSubtree( t5.getNode( "A" ), true );
2421             if ( t5.getNumberOfExternalNodes() != 5 ) {
2422                 return false;
2423             }
2424             s = w.toNewHampshire( t5, false, true ).toString();
2425             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2426                 return false;
2427             }
2428             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2429             t6.deleteSubtree( t6.getNode( "B11" ), true );
2430             if ( t6.getNumberOfExternalNodes() != 5 ) {
2431                 return false;
2432             }
2433             s = w.toNewHampshire( t6, false, false ).toString();
2434             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2435                 return false;
2436             }
2437             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2438             t7.deleteSubtree( t7.getNode( "B12" ), true );
2439             if ( t7.getNumberOfExternalNodes() != 5 ) {
2440                 return false;
2441             }
2442             s = w.toNewHampshire( t7, false, true ).toString();
2443             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2444                 return false;
2445             }
2446             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2447             t8.deleteSubtree( t8.getNode( "B2" ), true );
2448             if ( t8.getNumberOfExternalNodes() != 5 ) {
2449                 return false;
2450             }
2451             s = w.toNewHampshire( t8, false, false ).toString();
2452             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2453                 return false;
2454             }
2455             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2456             t9.deleteSubtree( t9.getNode( "C" ), true );
2457             if ( t9.getNumberOfExternalNodes() != 5 ) {
2458                 return false;
2459             }
2460             s = w.toNewHampshire( t9, false, true ).toString();
2461             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2462                 return false;
2463             }
2464             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2465             t10.deleteSubtree( t10.getNode( "D" ), true );
2466             if ( t10.getNumberOfExternalNodes() != 5 ) {
2467                 return false;
2468             }
2469             s = w.toNewHampshire( t10, false, true ).toString();
2470             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2471                 return false;
2472             }
2473             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2474             t11.deleteSubtree( t11.getNode( "A" ), true );
2475             if ( t11.getNumberOfExternalNodes() != 2 ) {
2476                 return false;
2477             }
2478             s = w.toNewHampshire( t11, false, true ).toString();
2479             if ( !s.equals( "(B,C);" ) ) {
2480                 return false;
2481             }
2482             t11.deleteSubtree( t11.getNode( "C" ), true );
2483             if ( t11.getNumberOfExternalNodes() != 1 ) {
2484                 return false;
2485             }
2486             s = w.toNewHampshire( t11, false, false ).toString();
2487             if ( !s.equals( "B;" ) ) {
2488                 return false;
2489             }
2490             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2491             t12.deleteSubtree( t12.getNode( "B2" ), true );
2492             if ( t12.getNumberOfExternalNodes() != 8 ) {
2493                 return false;
2494             }
2495             s = w.toNewHampshire( t12, false, true ).toString();
2496             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2497                 return false;
2498             }
2499             t12.deleteSubtree( t12.getNode( "B3" ), true );
2500             if ( t12.getNumberOfExternalNodes() != 7 ) {
2501                 return false;
2502             }
2503             s = w.toNewHampshire( t12, false, true ).toString();
2504             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2505                 return false;
2506             }
2507             t12.deleteSubtree( t12.getNode( "C3" ), true );
2508             if ( t12.getNumberOfExternalNodes() != 6 ) {
2509                 return false;
2510             }
2511             s = w.toNewHampshire( t12, false, true ).toString();
2512             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2513                 return false;
2514             }
2515             t12.deleteSubtree( t12.getNode( "A1" ), true );
2516             if ( t12.getNumberOfExternalNodes() != 5 ) {
2517                 return false;
2518             }
2519             s = w.toNewHampshire( t12, false, true ).toString();
2520             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2521                 return false;
2522             }
2523             t12.deleteSubtree( t12.getNode( "B1" ), true );
2524             if ( t12.getNumberOfExternalNodes() != 4 ) {
2525                 return false;
2526             }
2527             s = w.toNewHampshire( t12, false, true ).toString();
2528             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2529                 return false;
2530             }
2531             t12.deleteSubtree( t12.getNode( "A3" ), true );
2532             if ( t12.getNumberOfExternalNodes() != 3 ) {
2533                 return false;
2534             }
2535             s = w.toNewHampshire( t12, false, true ).toString();
2536             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2537                 return false;
2538             }
2539             t12.deleteSubtree( t12.getNode( "A2" ), true );
2540             if ( t12.getNumberOfExternalNodes() != 2 ) {
2541                 return false;
2542             }
2543             s = w.toNewHampshire( t12, false, true ).toString();
2544             if ( !s.equals( "(C1,C2);" ) ) {
2545                 return false;
2546             }
2547             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2548             t13.deleteSubtree( t13.getNode( "D" ), true );
2549             if ( t13.getNumberOfExternalNodes() != 4 ) {
2550                 return false;
2551             }
2552             s = w.toNewHampshire( t13, false, true ).toString();
2553             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2554                 return false;
2555             }
2556             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2557             t14.deleteSubtree( t14.getNode( "E" ), true );
2558             if ( t14.getNumberOfExternalNodes() != 5 ) {
2559                 return false;
2560             }
2561             s = w.toNewHampshire( t14, false, true ).toString();
2562             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2563                 return false;
2564             }
2565             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2566             t15.deleteSubtree( t15.getNode( "B2" ), true );
2567             if ( t15.getNumberOfExternalNodes() != 11 ) {
2568                 return false;
2569             }
2570             t15.deleteSubtree( t15.getNode( "B1" ), true );
2571             if ( t15.getNumberOfExternalNodes() != 10 ) {
2572                 return false;
2573             }
2574             t15.deleteSubtree( t15.getNode( "B3" ), true );
2575             if ( t15.getNumberOfExternalNodes() != 9 ) {
2576                 return false;
2577             }
2578             t15.deleteSubtree( t15.getNode( "B4" ), true );
2579             if ( t15.getNumberOfExternalNodes() != 8 ) {
2580                 return false;
2581             }
2582             t15.deleteSubtree( t15.getNode( "A1" ), true );
2583             if ( t15.getNumberOfExternalNodes() != 7 ) {
2584                 return false;
2585             }
2586             t15.deleteSubtree( t15.getNode( "C4" ), true );
2587             if ( t15.getNumberOfExternalNodes() != 6 ) {
2588                 return false;
2589             }
2590         }
2591         catch ( final Exception e ) {
2592             e.printStackTrace( System.out );
2593             return false;
2594         }
2595         return true;
2596     }
2597
2598     private static boolean testDescriptiveStatistics() {
2599         try {
2600             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2601             dss1.addValue( 82 );
2602             dss1.addValue( 78 );
2603             dss1.addValue( 70 );
2604             dss1.addValue( 58 );
2605             dss1.addValue( 42 );
2606             if ( dss1.getN() != 5 ) {
2607                 return false;
2608             }
2609             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2610                 return false;
2611             }
2612             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2613                 return false;
2614             }
2615             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2616                 return false;
2617             }
2618             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2619                 return false;
2620             }
2621             if ( !Test.isEqual( dss1.median(), 70 ) ) {
2622                 return false;
2623             }
2624             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2625                 return false;
2626             }
2627             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2628                 return false;
2629             }
2630             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2631                 return false;
2632             }
2633             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2634                 return false;
2635             }
2636             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2637                 return false;
2638             }
2639             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2640                 return false;
2641             }
2642             dss1.addValue( 123 );
2643             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2644                 return false;
2645             }
2646             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2647                 return false;
2648             }
2649             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2650                 return false;
2651             }
2652             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2653             dss2.addValue( -1.85 );
2654             dss2.addValue( 57.5 );
2655             dss2.addValue( 92.78 );
2656             dss2.addValue( 57.78 );
2657             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2658                 return false;
2659             }
2660             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2661                 return false;
2662             }
2663             final double[] a = dss2.getDataAsDoubleArray();
2664             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2665                 return false;
2666             }
2667             dss2.addValue( -100 );
2668             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
2669                 return false;
2670             }
2671             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
2672                 return false;
2673             }
2674             final double[] ds = new double[ 14 ];
2675             ds[ 0 ] = 34;
2676             ds[ 1 ] = 23;
2677             ds[ 2 ] = 1;
2678             ds[ 3 ] = 32;
2679             ds[ 4 ] = 11;
2680             ds[ 5 ] = 2;
2681             ds[ 6 ] = 12;
2682             ds[ 7 ] = 33;
2683             ds[ 8 ] = 13;
2684             ds[ 9 ] = 22;
2685             ds[ 10 ] = 21;
2686             ds[ 11 ] = 35;
2687             ds[ 12 ] = 24;
2688             ds[ 13 ] = 31;
2689             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
2690             if ( bins.length != 4 ) {
2691                 return false;
2692             }
2693             if ( bins[ 0 ] != 2 ) {
2694                 return false;
2695             }
2696             if ( bins[ 1 ] != 3 ) {
2697                 return false;
2698             }
2699             if ( bins[ 2 ] != 4 ) {
2700                 return false;
2701             }
2702             if ( bins[ 3 ] != 5 ) {
2703                 return false;
2704             }
2705             final double[] ds1 = new double[ 9 ];
2706             ds1[ 0 ] = 10.0;
2707             ds1[ 1 ] = 19.0;
2708             ds1[ 2 ] = 9.999;
2709             ds1[ 3 ] = 0.0;
2710             ds1[ 4 ] = 39.9;
2711             ds1[ 5 ] = 39.999;
2712             ds1[ 6 ] = 30.0;
2713             ds1[ 7 ] = 19.999;
2714             ds1[ 8 ] = 30.1;
2715             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
2716             if ( bins1.length != 4 ) {
2717                 return false;
2718             }
2719             if ( bins1[ 0 ] != 2 ) {
2720                 return false;
2721             }
2722             if ( bins1[ 1 ] != 3 ) {
2723                 return false;
2724             }
2725             if ( bins1[ 2 ] != 0 ) {
2726                 return false;
2727             }
2728             if ( bins1[ 3 ] != 4 ) {
2729                 return false;
2730             }
2731             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
2732             if ( bins1_1.length != 3 ) {
2733                 return false;
2734             }
2735             if ( bins1_1[ 0 ] != 3 ) {
2736                 return false;
2737             }
2738             if ( bins1_1[ 1 ] != 2 ) {
2739                 return false;
2740             }
2741             if ( bins1_1[ 2 ] != 4 ) {
2742                 return false;
2743             }
2744             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
2745             if ( bins1_2.length != 3 ) {
2746                 return false;
2747             }
2748             if ( bins1_2[ 0 ] != 2 ) {
2749                 return false;
2750             }
2751             if ( bins1_2[ 1 ] != 2 ) {
2752                 return false;
2753             }
2754             if ( bins1_2[ 2 ] != 2 ) {
2755                 return false;
2756             }
2757             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
2758             dss3.addValue( 1 );
2759             dss3.addValue( 1 );
2760             dss3.addValue( 1 );
2761             dss3.addValue( 2 );
2762             dss3.addValue( 3 );
2763             dss3.addValue( 4 );
2764             dss3.addValue( 5 );
2765             dss3.addValue( 5 );
2766             dss3.addValue( 5 );
2767             dss3.addValue( 6 );
2768             dss3.addValue( 7 );
2769             dss3.addValue( 8 );
2770             dss3.addValue( 9 );
2771             dss3.addValue( 10 );
2772             dss3.addValue( 10 );
2773             dss3.addValue( 10 );
2774             final AsciiHistogram histo = new AsciiHistogram( dss3 );
2775             histo.toStringBuffer( 10, '=', 40, 5 );
2776             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
2777         }
2778         catch ( final Exception e ) {
2779             e.printStackTrace( System.out );
2780             return false;
2781         }
2782         return true;
2783     }
2784
2785     private static boolean testDir( final String file ) {
2786         try {
2787             final File f = new File( file );
2788             if ( !f.exists() ) {
2789                 return false;
2790             }
2791             if ( !f.isDirectory() ) {
2792                 return false;
2793             }
2794             if ( !f.canRead() ) {
2795                 return false;
2796             }
2797         }
2798         catch ( final Exception e ) {
2799             return false;
2800         }
2801         return true;
2802     }
2803
2804     private static boolean testExternalNodeRelatedMethods() {
2805         try {
2806             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2807             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2808             PhylogenyNode n = t1.getNode( "A" );
2809             n = n.getNextExternalNode();
2810             if ( !n.getName().equals( "B" ) ) {
2811                 return false;
2812             }
2813             n = n.getNextExternalNode();
2814             if ( !n.getName().equals( "C" ) ) {
2815                 return false;
2816             }
2817             n = n.getNextExternalNode();
2818             if ( !n.getName().equals( "D" ) ) {
2819                 return false;
2820             }
2821             n = t1.getNode( "B" );
2822             while ( !n.isLastExternalNode() ) {
2823                 n = n.getNextExternalNode();
2824             }
2825             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
2826             n = t2.getNode( "A" );
2827             n = n.getNextExternalNode();
2828             if ( !n.getName().equals( "B" ) ) {
2829                 return false;
2830             }
2831             n = n.getNextExternalNode();
2832             if ( !n.getName().equals( "C" ) ) {
2833                 return false;
2834             }
2835             n = n.getNextExternalNode();
2836             if ( !n.getName().equals( "D" ) ) {
2837                 return false;
2838             }
2839             n = t2.getNode( "B" );
2840             while ( !n.isLastExternalNode() ) {
2841                 n = n.getNextExternalNode();
2842             }
2843             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2844             n = t3.getNode( "A" );
2845             n = n.getNextExternalNode();
2846             if ( !n.getName().equals( "B" ) ) {
2847                 return false;
2848             }
2849             n = n.getNextExternalNode();
2850             if ( !n.getName().equals( "C" ) ) {
2851                 return false;
2852             }
2853             n = n.getNextExternalNode();
2854             if ( !n.getName().equals( "D" ) ) {
2855                 return false;
2856             }
2857             n = n.getNextExternalNode();
2858             if ( !n.getName().equals( "E" ) ) {
2859                 return false;
2860             }
2861             n = n.getNextExternalNode();
2862             if ( !n.getName().equals( "F" ) ) {
2863                 return false;
2864             }
2865             n = n.getNextExternalNode();
2866             if ( !n.getName().equals( "G" ) ) {
2867                 return false;
2868             }
2869             n = n.getNextExternalNode();
2870             if ( !n.getName().equals( "H" ) ) {
2871                 return false;
2872             }
2873             n = t3.getNode( "B" );
2874             while ( !n.isLastExternalNode() ) {
2875                 n = n.getNextExternalNode();
2876             }
2877             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2878             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
2879                 final PhylogenyNode node = iter.next();
2880             }
2881             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2882             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
2883                 final PhylogenyNode node = iter.next();
2884             }
2885             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
2886             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
2887             if ( !iter.next().getName().equals( "A" ) ) {
2888                 return false;
2889             }
2890             if ( !iter.next().getName().equals( "B" ) ) {
2891                 return false;
2892             }
2893             if ( !iter.next().getName().equals( "C" ) ) {
2894                 return false;
2895             }
2896             if ( !iter.next().getName().equals( "D" ) ) {
2897                 return false;
2898             }
2899             if ( !iter.next().getName().equals( "E" ) ) {
2900                 return false;
2901             }
2902             if ( !iter.next().getName().equals( "F" ) ) {
2903                 return false;
2904             }
2905             if ( iter.hasNext() ) {
2906                 return false;
2907             }
2908         }
2909         catch ( final Exception e ) {
2910             e.printStackTrace( System.out );
2911             return false;
2912         }
2913         return true;
2914     }
2915
2916     private static boolean testGeneralTable() {
2917         try {
2918             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
2919             t0.setValue( 3, 2, "23" );
2920             t0.setValue( 10, 1, "error" );
2921             t0.setValue( 10, 1, "110" );
2922             t0.setValue( 9, 1, "19" );
2923             t0.setValue( 1, 10, "101" );
2924             t0.setValue( 10, 10, "1010" );
2925             t0.setValue( 100, 10, "10100" );
2926             t0.setValue( 0, 0, "00" );
2927             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2928                 return false;
2929             }
2930             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2931                 return false;
2932             }
2933             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2934                 return false;
2935             }
2936             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2937                 return false;
2938             }
2939             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2940                 return false;
2941             }
2942             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2943                 return false;
2944             }
2945             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2946                 return false;
2947             }
2948             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
2949                 return false;
2950             }
2951             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
2952                 return false;
2953             }
2954             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
2955             t1.setValue( "3", "2", "23" );
2956             t1.setValue( "10", "1", "error" );
2957             t1.setValue( "10", "1", "110" );
2958             t1.setValue( "9", "1", "19" );
2959             t1.setValue( "1", "10", "101" );
2960             t1.setValue( "10", "10", "1010" );
2961             t1.setValue( "100", "10", "10100" );
2962             t1.setValue( "0", "0", "00" );
2963             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
2964             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
2965                 return false;
2966             }
2967             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
2968                 return false;
2969             }
2970             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
2971                 return false;
2972             }
2973             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
2974                 return false;
2975             }
2976             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
2977                 return false;
2978             }
2979             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
2980                 return false;
2981             }
2982             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
2983                 return false;
2984             }
2985             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
2986                 return false;
2987             }
2988             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
2989                 return false;
2990             }
2991             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
2992                 return false;
2993             }
2994         }
2995         catch ( final Exception e ) {
2996             e.printStackTrace( System.out );
2997             return false;
2998         }
2999         return true;
3000     }
3001
3002     private static boolean testGetDistance() {
3003         try {
3004             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3005             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",
3006                                                  new NHXParser() )[ 0 ];
3007             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3008                 return false;
3009             }
3010             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3011                 return false;
3012             }
3013             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3014                 return false;
3015             }
3016             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3017                 return false;
3018             }
3019             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3020                 return false;
3021             }
3022             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3023                 return false;
3024             }
3025             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3026                 return false;
3027             }
3028             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3029                 return false;
3030             }
3031             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3032                 return false;
3033             }
3034             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3035                 return false;
3036             }
3037             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3038                 return false;
3039             }
3040             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3041                 return false;
3042             }
3043             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3044                 return false;
3045             }
3046             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3047                 return false;
3048             }
3049             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3050                 return false;
3051             }
3052             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3053                 return false;
3054             }
3055             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3056                 return false;
3057             }
3058             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3059                 return false;
3060             }
3061             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3062                 return false;
3063             }
3064             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3065                 return false;
3066             }
3067             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3068                 return false;
3069             }
3070             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3071                 return false;
3072             }
3073             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3074                 return false;
3075             }
3076             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3077                 return false;
3078             }
3079             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3080                 return false;
3081             }
3082             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3083                 return false;
3084             }
3085             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3086                 return false;
3087             }
3088             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3089                 return false;
3090             }
3091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3092                 return false;
3093             }
3094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3095                 return false;
3096             }
3097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3098                 return false;
3099             }
3100             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",
3101                                                  new NHXParser() )[ 0 ];
3102             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3103                 return false;
3104             }
3105             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3106                 return false;
3107             }
3108             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3109                 return false;
3110             }
3111             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3112                 return false;
3113             }
3114             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3115                 return false;
3116             }
3117             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3118                 return false;
3119             }
3120             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3121                 return false;
3122             }
3123             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3124                 return false;
3125             }
3126             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3127                 return false;
3128             }
3129             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3130                 return false;
3131             }
3132             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3133                 return false;
3134             }
3135         }
3136         catch ( final Exception e ) {
3137             e.printStackTrace( System.out );
3138             return false;
3139         }
3140         return true;
3141     }
3142
3143     private static boolean testGetLCA() {
3144         try {
3145             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3146             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3147                                                  new NHXParser() )[ 0 ];
3148             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3149             if ( !A.getName().equals( "A" ) ) {
3150                 return false;
3151             }
3152             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3153             if ( !gh.getName().equals( "gh" ) ) {
3154                 return false;
3155             }
3156             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3157             if ( !ab.getName().equals( "ab" ) ) {
3158                 return false;
3159             }
3160             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3161             if ( !ab2.getName().equals( "ab" ) ) {
3162                 return false;
3163             }
3164             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3165             if ( !gh2.getName().equals( "gh" ) ) {
3166                 return false;
3167             }
3168             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3169             if ( !gh3.getName().equals( "gh" ) ) {
3170                 return false;
3171             }
3172             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3173             if ( !abc.getName().equals( "abc" ) ) {
3174                 return false;
3175             }
3176             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3177             if ( !abc2.getName().equals( "abc" ) ) {
3178                 return false;
3179             }
3180             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3181             if ( !abcd.getName().equals( "abcd" ) ) {
3182                 return false;
3183             }
3184             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3185             if ( !abcd2.getName().equals( "abcd" ) ) {
3186                 return false;
3187             }
3188             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3189             if ( !abcdef.getName().equals( "abcdef" ) ) {
3190                 return false;
3191             }
3192             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3193             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3194                 return false;
3195             }
3196             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3197             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3198                 return false;
3199             }
3200             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3201             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3202                 return false;
3203             }
3204             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3205             if ( !abcde.getName().equals( "abcde" ) ) {
3206                 return false;
3207             }
3208             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3209             if ( !abcde2.getName().equals( "abcde" ) ) {
3210                 return false;
3211             }
3212             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3213             if ( !r.getName().equals( "abcdefgh" ) ) {
3214                 return false;
3215             }
3216             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3217             if ( !r2.getName().equals( "abcdefgh" ) ) {
3218                 return false;
3219             }
3220             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3221             if ( !r3.getName().equals( "abcdefgh" ) ) {
3222                 return false;
3223             }
3224             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3225             if ( !abcde3.getName().equals( "abcde" ) ) {
3226                 return false;
3227             }
3228             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3229             if ( !abcde4.getName().equals( "abcde" ) ) {
3230                 return false;
3231             }
3232             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3233             if ( !ab3.getName().equals( "ab" ) ) {
3234                 return false;
3235             }
3236             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3237             if ( !ab4.getName().equals( "ab" ) ) {
3238                 return false;
3239             }
3240             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3241             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3242             if ( !cd.getName().equals( "cd" ) ) {
3243                 return false;
3244             }
3245             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3246             if ( !cd2.getName().equals( "cd" ) ) {
3247                 return false;
3248             }
3249             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3250             if ( !cde.getName().equals( "cde" ) ) {
3251                 return false;
3252             }
3253             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3254             if ( !cde2.getName().equals( "cde" ) ) {
3255                 return false;
3256             }
3257             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3258             if ( !cdef.getName().equals( "cdef" ) ) {
3259                 return false;
3260             }
3261             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3262             if ( !cdef2.getName().equals( "cdef" ) ) {
3263                 return false;
3264             }
3265             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3266             if ( !cdef3.getName().equals( "cdef" ) ) {
3267                 return false;
3268             }
3269             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3270             if ( !rt.getName().equals( "r" ) ) {
3271                 return false;
3272             }
3273             final Phylogeny p3 = factory
3274                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3275                              new NHXParser() )[ 0 ];
3276             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3277             if ( !bc_3.getName().equals( "bc" ) ) {
3278                 return false;
3279             }
3280             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3281             if ( !ac_3.getName().equals( "abc" ) ) {
3282                 return false;
3283             }
3284             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3285             if ( !ad_3.getName().equals( "abcde" ) ) {
3286                 return false;
3287             }
3288             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3289             if ( !af_3.getName().equals( "abcdef" ) ) {
3290                 return false;
3291             }
3292             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3293             if ( !ag_3.getName().equals( "" ) ) {
3294                 return false;
3295             }
3296             if ( !ag_3.isRoot() ) {
3297                 return false;
3298             }
3299             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3300             if ( !al_3.getName().equals( "" ) ) {
3301                 return false;
3302             }
3303             if ( !al_3.isRoot() ) {
3304                 return false;
3305             }
3306             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3307             if ( !kl_3.getName().equals( "" ) ) {
3308                 return false;
3309             }
3310             if ( !kl_3.isRoot() ) {
3311                 return false;
3312             }
3313             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3314             if ( !fl_3.getName().equals( "" ) ) {
3315                 return false;
3316             }
3317             if ( !fl_3.isRoot() ) {
3318                 return false;
3319             }
3320             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3321             if ( !gk_3.getName().equals( "ghijk" ) ) {
3322                 return false;
3323             }
3324             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3325             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3326             if ( !r_4.getName().equals( "r" ) ) {
3327                 return false;
3328             }
3329             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3330             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3331             if ( !r_5.getName().equals( "root" ) ) {
3332                 return false;
3333             }
3334             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3335             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3336             if ( !r_6.getName().equals( "rot" ) ) {
3337                 return false;
3338             }
3339             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3340             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3341             if ( !r_7.getName().equals( "rott" ) ) {
3342                 return false;
3343             }
3344         }
3345         catch ( final Exception e ) {
3346             e.printStackTrace( System.out );
3347             return false;
3348         }
3349         return true;
3350     }
3351
3352     private static boolean testGetLCA2() {
3353         try {
3354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3355             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3356             PhylogenyMethods.preOrderReId( p_a );
3357             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3358                                                                                               p_a.getNode( "a" ) );
3359             if ( !p_a_1.getName().equals( "a" ) ) {
3360                 return false;
3361             }
3362             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3363             PhylogenyMethods.preOrderReId( p_b );
3364             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3365                                                                                               p_b.getNode( "a" ) );
3366             if ( !p_b_1.getName().equals( "b" ) ) {
3367                 return false;
3368             }
3369             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3370                                                                                               p_b.getNode( "b" ) );
3371             if ( !p_b_2.getName().equals( "b" ) ) {
3372                 return false;
3373             }
3374             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3375             PhylogenyMethods.preOrderReId( p_c );
3376             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3377                                                                                               p_c.getNode( "a" ) );
3378             if ( !p_c_1.getName().equals( "b" ) ) {
3379                 return false;
3380             }
3381             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3382                                                                                               p_c.getNode( "c" ) );
3383             if ( !p_c_2.getName().equals( "c" ) ) {
3384                 System.out.println( p_c_2.getName() );
3385                 System.exit( -1 );
3386                 return false;
3387             }
3388             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3389                                                                                               p_c.getNode( "b" ) );
3390             if ( !p_c_3.getName().equals( "b" ) ) {
3391                 return false;
3392             }
3393             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3394                                                                                               p_c.getNode( "a" ) );
3395             if ( !p_c_4.getName().equals( "c" ) ) {
3396                 return false;
3397             }
3398             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3399                                                  new NHXParser() )[ 0 ];
3400             PhylogenyMethods.preOrderReId( p1 );
3401             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3402                                                                                           p1.getNode( "A" ) );
3403             if ( !A.getName().equals( "A" ) ) {
3404                 return false;
3405             }
3406             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3407                                                                                            p1.getNode( "gh" ) );
3408             if ( !gh.getName().equals( "gh" ) ) {
3409                 return false;
3410             }
3411             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3412                                                                                            p1.getNode( "B" ) );
3413             if ( !ab.getName().equals( "ab" ) ) {
3414                 return false;
3415             }
3416             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3417                                                                                             p1.getNode( "A" ) );
3418             if ( !ab2.getName().equals( "ab" ) ) {
3419                 return false;
3420             }
3421             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3422                                                                                             p1.getNode( "G" ) );
3423             if ( !gh2.getName().equals( "gh" ) ) {
3424                 return false;
3425             }
3426             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3427                                                                                             p1.getNode( "H" ) );
3428             if ( !gh3.getName().equals( "gh" ) ) {
3429                 return false;
3430             }
3431             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3432                                                                                             p1.getNode( "A" ) );
3433             if ( !abc.getName().equals( "abc" ) ) {
3434                 return false;
3435             }
3436             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3437                                                                                              p1.getNode( "C" ) );
3438             if ( !abc2.getName().equals( "abc" ) ) {
3439                 return false;
3440             }
3441             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3442                                                                                              p1.getNode( "D" ) );
3443             if ( !abcd.getName().equals( "abcd" ) ) {
3444                 return false;
3445             }
3446             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3447                                                                                               p1.getNode( "A" ) );
3448             if ( !abcd2.getName().equals( "abcd" ) ) {
3449                 return false;
3450             }
3451             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3452                                                                                                p1.getNode( "F" ) );
3453             if ( !abcdef.getName().equals( "abcdef" ) ) {
3454                 return false;
3455             }
3456             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3457                                                                                                 p1.getNode( "A" ) );
3458             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3459                 return false;
3460             }
3461             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3462                                                                                                 p1.getNode( "F" ) );
3463             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3464                 return false;
3465             }
3466             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3467                                                                                                 p1.getNode( "ab" ) );
3468             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3469                 return false;
3470             }
3471             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3472                                                                                               p1.getNode( "E" ) );
3473             if ( !abcde.getName().equals( "abcde" ) ) {
3474                 return false;
3475             }
3476             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3477                                                                                                p1.getNode( "A" ) );
3478             if ( !abcde2.getName().equals( "abcde" ) ) {
3479                 return false;
3480             }
3481             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3482                                                                                           p1.getNode( "abcdefgh" ) );
3483             if ( !r.getName().equals( "abcdefgh" ) ) {
3484                 return false;
3485             }
3486             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3487                                                                                            p1.getNode( "H" ) );
3488             if ( !r2.getName().equals( "abcdefgh" ) ) {
3489                 return false;
3490             }
3491             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3492                                                                                            p1.getNode( "A" ) );
3493             if ( !r3.getName().equals( "abcdefgh" ) ) {
3494                 return false;
3495             }
3496             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3497                                                                                                p1.getNode( "abcde" ) );
3498             if ( !abcde3.getName().equals( "abcde" ) ) {
3499                 return false;
3500             }
3501             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3502                                                                                                p1.getNode( "E" ) );
3503             if ( !abcde4.getName().equals( "abcde" ) ) {
3504                 return false;
3505             }
3506             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3507                                                                                             p1.getNode( "B" ) );
3508             if ( !ab3.getName().equals( "ab" ) ) {
3509                 return false;
3510             }
3511             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3512                                                                                             p1.getNode( "ab" ) );
3513             if ( !ab4.getName().equals( "ab" ) ) {
3514                 return false;
3515             }
3516             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3517             PhylogenyMethods.preOrderReId( p2 );
3518             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3519                                                                                            p2.getNode( "d" ) );
3520             if ( !cd.getName().equals( "cd" ) ) {
3521                 return false;
3522             }
3523             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3524                                                                                             p2.getNode( "c" ) );
3525             if ( !cd2.getName().equals( "cd" ) ) {
3526                 return false;
3527             }
3528             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3529                                                                                             p2.getNode( "e" ) );
3530             if ( !cde.getName().equals( "cde" ) ) {
3531                 return false;
3532             }
3533             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3534                                                                                              p2.getNode( "c" ) );
3535             if ( !cde2.getName().equals( "cde" ) ) {
3536                 return false;
3537             }
3538             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3539                                                                                              p2.getNode( "f" ) );
3540             if ( !cdef.getName().equals( "cdef" ) ) {
3541                 return false;
3542             }
3543             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3544                                                                                               p2.getNode( "f" ) );
3545             if ( !cdef2.getName().equals( "cdef" ) ) {
3546                 return false;
3547             }
3548             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3549                                                                                               p2.getNode( "d" ) );
3550             if ( !cdef3.getName().equals( "cdef" ) ) {
3551                 return false;
3552             }
3553             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3554                                                                                            p2.getNode( "a" ) );
3555             if ( !rt.getName().equals( "r" ) ) {
3556                 return false;
3557             }
3558             final Phylogeny p3 = factory
3559                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3560                              new NHXParser() )[ 0 ];
3561             PhylogenyMethods.preOrderReId( p3 );
3562             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3563                                                                                              p3.getNode( "c" ) );
3564             if ( !bc_3.getName().equals( "bc" ) ) {
3565                 return false;
3566             }
3567             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3568                                                                                              p3.getNode( "c" ) );
3569             if ( !ac_3.getName().equals( "abc" ) ) {
3570                 return false;
3571             }
3572             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3573                                                                                              p3.getNode( "d" ) );
3574             if ( !ad_3.getName().equals( "abcde" ) ) {
3575                 return false;
3576             }
3577             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3578                                                                                              p3.getNode( "f" ) );
3579             if ( !af_3.getName().equals( "abcdef" ) ) {
3580                 return false;
3581             }
3582             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3583                                                                                              p3.getNode( "g" ) );
3584             if ( !ag_3.getName().equals( "" ) ) {
3585                 return false;
3586             }
3587             if ( !ag_3.isRoot() ) {
3588                 return false;
3589             }
3590             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3591                                                                                              p3.getNode( "l" ) );
3592             if ( !al_3.getName().equals( "" ) ) {
3593                 return false;
3594             }
3595             if ( !al_3.isRoot() ) {
3596                 return false;
3597             }
3598             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3599                                                                                              p3.getNode( "l" ) );
3600             if ( !kl_3.getName().equals( "" ) ) {
3601                 return false;
3602             }
3603             if ( !kl_3.isRoot() ) {
3604                 return false;
3605             }
3606             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3607                                                                                              p3.getNode( "l" ) );
3608             if ( !fl_3.getName().equals( "" ) ) {
3609                 return false;
3610             }
3611             if ( !fl_3.isRoot() ) {
3612                 return false;
3613             }
3614             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3615                                                                                              p3.getNode( "k" ) );
3616             if ( !gk_3.getName().equals( "ghijk" ) ) {
3617                 return false;
3618             }
3619             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3620             PhylogenyMethods.preOrderReId( p4 );
3621             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3622                                                                                             p4.getNode( "c" ) );
3623             if ( !r_4.getName().equals( "r" ) ) {
3624                 return false;
3625             }
3626             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3627             PhylogenyMethods.preOrderReId( p5 );
3628             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3629                                                                                             p5.getNode( "c" ) );
3630             if ( !r_5.getName().equals( "root" ) ) {
3631                 return false;
3632             }
3633             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3634             PhylogenyMethods.preOrderReId( p6 );
3635             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3636                                                                                             p6.getNode( "a" ) );
3637             if ( !r_6.getName().equals( "rot" ) ) {
3638                 return false;
3639             }
3640             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3641             PhylogenyMethods.preOrderReId( p7 );
3642             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3643                                                                                             p7.getNode( "e" ) );
3644             if ( !r_7.getName().equals( "rott" ) ) {
3645                 return false;
3646             }
3647             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3648                                                                                              p7.getNode( "a" ) );
3649             if ( !r_71.getName().equals( "rott" ) ) {
3650                 return false;
3651             }
3652             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3653                                                                                              p7.getNode( "rott" ) );
3654             if ( !r_72.getName().equals( "rott" ) ) {
3655                 return false;
3656             }
3657             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3658                                                                                              p7.getNode( "a" ) );
3659             if ( !r_73.getName().equals( "rott" ) ) {
3660                 return false;
3661             }
3662             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3663                                                                                              p7.getNode( "rott" ) );
3664             if ( !r_74.getName().equals( "rott" ) ) {
3665                 return false;
3666             }
3667             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3668                                                                                              p7.getNode( "e" ) );
3669             if ( !r_75.getName().equals( "e" ) ) {
3670                 return false;
3671             }
3672         }
3673         catch ( final Exception e ) {
3674             e.printStackTrace( System.out );
3675             return false;
3676         }
3677         return true;
3678     }
3679
3680     private static boolean testHmmscanOutputParser() {
3681         final String test_dir = Test.PATH_TO_TEST_DATA;
3682         try {
3683             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
3684                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3685             parser1.parse();
3686             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
3687                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3688             final List<Protein> proteins = parser2.parse();
3689             if ( parser2.getProteinsEncountered() != 4 ) {
3690                 return false;
3691             }
3692             if ( proteins.size() != 4 ) {
3693                 return false;
3694             }
3695             if ( parser2.getDomainsEncountered() != 69 ) {
3696                 return false;
3697             }
3698             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
3699                 return false;
3700             }
3701             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
3702                 return false;
3703             }
3704             final Protein p1 = proteins.get( 0 );
3705             if ( p1.getNumberOfProteinDomains() != 15 ) {
3706                 return false;
3707             }
3708             if ( p1.getLength() != 850 ) {
3709                 return false;
3710             }
3711             final Protein p2 = proteins.get( 1 );
3712             if ( p2.getNumberOfProteinDomains() != 51 ) {
3713                 return false;
3714             }
3715             if ( p2.getLength() != 1291 ) {
3716                 return false;
3717             }
3718             final Protein p3 = proteins.get( 2 );
3719             if ( p3.getNumberOfProteinDomains() != 2 ) {
3720                 return false;
3721             }
3722             final Protein p4 = proteins.get( 3 );
3723             if ( p4.getNumberOfProteinDomains() != 1 ) {
3724                 return false;
3725             }
3726             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
3727                 return false;
3728             }
3729             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
3730                 return false;
3731             }
3732             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
3733                 return false;
3734             }
3735             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
3736                 return false;
3737             }
3738             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
3739                 return false;
3740             }
3741             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
3742                 return false;
3743             }
3744             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
3745                 return false;
3746             }
3747             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
3748                 return false;
3749             }
3750             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
3751                 return false;
3752             }
3753         }
3754         catch ( final Exception e ) {
3755             e.printStackTrace( System.out );
3756             return false;
3757         }
3758         return true;
3759     }
3760
3761     private static boolean testLastExternalNodeMethods() {
3762         try {
3763             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3764             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
3765             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
3766             final PhylogenyNode n1 = t0.getNode( "A" );
3767             if ( n1.isLastExternalNode() ) {
3768                 return false;
3769             }
3770             final PhylogenyNode n2 = t0.getNode( "B" );
3771             if ( n2.isLastExternalNode() ) {
3772                 return false;
3773             }
3774             final PhylogenyNode n3 = t0.getNode( "C" );
3775             if ( n3.isLastExternalNode() ) {
3776                 return false;
3777             }
3778             final PhylogenyNode n4 = t0.getNode( "D" );
3779             if ( !n4.isLastExternalNode() ) {
3780                 return false;
3781             }
3782         }
3783         catch ( final Exception e ) {
3784             e.printStackTrace( System.out );
3785             return false;
3786         }
3787         return true;
3788     }
3789
3790     private static boolean testLevelOrderIterator() {
3791         try {
3792             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3793             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
3794             PhylogenyNodeIterator it0;
3795             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
3796                 it0.next();
3797             }
3798             for( it0.reset(); it0.hasNext(); ) {
3799                 it0.next();
3800             }
3801             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
3802             if ( !it.next().getName().equals( "r" ) ) {
3803                 return false;
3804             }
3805             if ( !it.next().getName().equals( "ab" ) ) {
3806                 return false;
3807             }
3808             if ( !it.next().getName().equals( "cd" ) ) {
3809                 return false;
3810             }
3811             if ( !it.next().getName().equals( "A" ) ) {
3812                 return false;
3813             }
3814             if ( !it.next().getName().equals( "B" ) ) {
3815                 return false;
3816             }
3817             if ( !it.next().getName().equals( "C" ) ) {
3818                 return false;
3819             }
3820             if ( !it.next().getName().equals( "D" ) ) {
3821                 return false;
3822             }
3823             if ( it.hasNext() ) {
3824                 return false;
3825             }
3826             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",
3827                                                  new NHXParser() )[ 0 ];
3828             PhylogenyNodeIterator it2;
3829             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
3830                 it2.next();
3831             }
3832             for( it2.reset(); it2.hasNext(); ) {
3833                 it2.next();
3834             }
3835             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
3836             if ( !it3.next().getName().equals( "r" ) ) {
3837                 return false;
3838             }
3839             if ( !it3.next().getName().equals( "abc" ) ) {
3840                 return false;
3841             }
3842             if ( !it3.next().getName().equals( "defg" ) ) {
3843                 return false;
3844             }
3845             if ( !it3.next().getName().equals( "A" ) ) {
3846                 return false;
3847             }
3848             if ( !it3.next().getName().equals( "B" ) ) {
3849                 return false;
3850             }
3851             if ( !it3.next().getName().equals( "C" ) ) {
3852                 return false;
3853             }
3854             if ( !it3.next().getName().equals( "D" ) ) {
3855                 return false;
3856             }
3857             if ( !it3.next().getName().equals( "E" ) ) {
3858                 return false;
3859             }
3860             if ( !it3.next().getName().equals( "F" ) ) {
3861                 return false;
3862             }
3863             if ( !it3.next().getName().equals( "G" ) ) {
3864                 return false;
3865             }
3866             if ( !it3.next().getName().equals( "1" ) ) {
3867                 return false;
3868             }
3869             if ( !it3.next().getName().equals( "2" ) ) {
3870                 return false;
3871             }
3872             if ( !it3.next().getName().equals( "3" ) ) {
3873                 return false;
3874             }
3875             if ( !it3.next().getName().equals( "4" ) ) {
3876                 return false;
3877             }
3878             if ( !it3.next().getName().equals( "5" ) ) {
3879                 return false;
3880             }
3881             if ( !it3.next().getName().equals( "6" ) ) {
3882                 return false;
3883             }
3884             if ( !it3.next().getName().equals( "f1" ) ) {
3885                 return false;
3886             }
3887             if ( !it3.next().getName().equals( "f2" ) ) {
3888                 return false;
3889             }
3890             if ( !it3.next().getName().equals( "f3" ) ) {
3891                 return false;
3892             }
3893             if ( !it3.next().getName().equals( "a" ) ) {
3894                 return false;
3895             }
3896             if ( !it3.next().getName().equals( "b" ) ) {
3897                 return false;
3898             }
3899             if ( !it3.next().getName().equals( "f21" ) ) {
3900                 return false;
3901             }
3902             if ( !it3.next().getName().equals( "X" ) ) {
3903                 return false;
3904             }
3905             if ( !it3.next().getName().equals( "Y" ) ) {
3906                 return false;
3907             }
3908             if ( !it3.next().getName().equals( "Z" ) ) {
3909                 return false;
3910             }
3911             if ( it3.hasNext() ) {
3912                 return false;
3913             }
3914             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
3915             PhylogenyNodeIterator it4;
3916             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
3917                 it4.next();
3918             }
3919             for( it4.reset(); it4.hasNext(); ) {
3920                 it4.next();
3921             }
3922             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
3923             if ( !it5.next().getName().equals( "r" ) ) {
3924                 return false;
3925             }
3926             if ( !it5.next().getName().equals( "A" ) ) {
3927                 return false;
3928             }
3929             if ( !it5.next().getName().equals( "B" ) ) {
3930                 return false;
3931             }
3932             if ( !it5.next().getName().equals( "C" ) ) {
3933                 return false;
3934             }
3935             if ( !it5.next().getName().equals( "D" ) ) {
3936                 return false;
3937             }
3938             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
3939             PhylogenyNodeIterator it6;
3940             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
3941                 it6.next();
3942             }
3943             for( it6.reset(); it6.hasNext(); ) {
3944                 it6.next();
3945             }
3946             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
3947             if ( !it7.next().getName().equals( "A" ) ) {
3948                 return false;
3949             }
3950             if ( it.hasNext() ) {
3951                 return false;
3952             }
3953         }
3954         catch ( final Exception e ) {
3955             e.printStackTrace( System.out );
3956             return false;
3957         }
3958         return true;
3959     }
3960
3961     private static boolean testMidpointrooting() {
3962         try {
3963             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3964             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
3965             PhylogenyMethods.midpointRoot( t0 );
3966             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
3967                 return false;
3968             }
3969             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
3970                 return false;
3971             }
3972             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
3973                            1 ) ) {
3974                 return false;
3975             }
3976             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",
3977                                                  new NHXParser() )[ 0 ];
3978             if ( !t1.isRooted() ) {
3979                 return false;
3980             }
3981             PhylogenyMethods.midpointRoot( t1 );
3982             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
3983                 return false;
3984             }
3985             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
3986                 return false;
3987             }
3988             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
3989                 return false;
3990             }
3991             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
3992                 return false;
3993             }
3994             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
3995                 return false;
3996             }
3997             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
3998                 return false;
3999             }
4000             t1.reRoot( t1.getNode( "A" ) );
4001             PhylogenyMethods.midpointRoot( t1 );
4002             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4003                 return false;
4004             }
4005             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4006                 return false;
4007             }
4008             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4009                 return false;
4010             }
4011             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4012                 return false;
4013             }
4014             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4015                 System.exit( -1 );
4016                 return false;
4017             }
4018             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4019                 return false;
4020             }
4021         }
4022         catch ( final Exception e ) {
4023             e.printStackTrace( System.out );
4024             return false;
4025         }
4026         return true;
4027     }
4028
4029     private static boolean testNexusCharactersParsing() {
4030         try {
4031             final NexusCharactersParser parser = new NexusCharactersParser();
4032             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4033             parser.parse();
4034             String[] labels = parser.getCharStateLabels();
4035             if ( labels.length != 7 ) {
4036                 return false;
4037             }
4038             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4039                 return false;
4040             }
4041             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4042                 return false;
4043             }
4044             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4045                 return false;
4046             }
4047             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4048                 return false;
4049             }
4050             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4051                 return false;
4052             }
4053             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4054                 return false;
4055             }
4056             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4057                 return false;
4058             }
4059             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4060             parser.parse();
4061             labels = parser.getCharStateLabels();
4062             if ( labels.length != 7 ) {
4063                 return false;
4064             }
4065             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4066                 return false;
4067             }
4068             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4069                 return false;
4070             }
4071             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4072                 return false;
4073             }
4074             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4075                 return false;
4076             }
4077             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4078                 return false;
4079             }
4080             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4081                 return false;
4082             }
4083             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4084                 return false;
4085             }
4086         }
4087         catch ( final Exception e ) {
4088             e.printStackTrace( System.out );
4089             return false;
4090         }
4091         return true;
4092     }
4093
4094     private static boolean testNexusMatrixParsing() {
4095         try {
4096             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4097             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4098             parser.parse();
4099             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4100             if ( m.getNumberOfCharacters() != 9 ) {
4101                 return false;
4102             }
4103             if ( m.getNumberOfIdentifiers() != 5 ) {
4104                 return false;
4105             }
4106             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4107                 return false;
4108             }
4109             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4110                 return false;
4111             }
4112             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4113                 return false;
4114             }
4115             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4116                 return false;
4117             }
4118             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4119                 return false;
4120             }
4121             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4122                 return false;
4123             }
4124             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4125                 return false;
4126             }
4127             //            if ( labels.length != 7 ) {
4128             //                return false;
4129             //            }
4130             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4131             //                return false;
4132             //            }
4133             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4134             //                return false;
4135             //            }
4136             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4137             //                return false;
4138             //            }
4139             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4140             //                return false;
4141             //            }
4142             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4143             //                return false;
4144             //            }
4145             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4146             //                return false;
4147             //            }
4148             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4149             //                return false;
4150             //            }
4151             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4152             //            parser.parse();
4153             //            labels = parser.getCharStateLabels();
4154             //            if ( labels.length != 7 ) {
4155             //                return false;
4156             //            }
4157             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4158             //                return false;
4159             //            }
4160             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4161             //                return false;
4162             //            }
4163             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4164             //                return false;
4165             //            }
4166             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4167             //                return false;
4168             //            }
4169             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4170             //                return false;
4171             //            }
4172             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4173             //                return false;
4174             //            }
4175             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4176             //                return false;
4177             //            }
4178         }
4179         catch ( final Exception e ) {
4180             e.printStackTrace( System.out );
4181             return false;
4182         }
4183         return true;
4184     }
4185
4186     private static boolean testNexusTreeParsing() {
4187         try {
4188             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4189             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4190             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4191             if ( phylogenies.length != 1 ) {
4192                 return false;
4193             }
4194             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4195                 return false;
4196             }
4197             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4198                 return false;
4199             }
4200             phylogenies = null;
4201             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4202             if ( phylogenies.length != 1 ) {
4203                 return false;
4204             }
4205             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4206                 return false;
4207             }
4208             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4209                 return false;
4210             }
4211             phylogenies = null;
4212             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4213             if ( phylogenies.length != 1 ) {
4214                 return false;
4215             }
4216             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4217                 return false;
4218             }
4219             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4220                 return false;
4221             }
4222             if ( phylogenies[ 0 ].isRooted() ) {
4223                 return false;
4224             }
4225             phylogenies = null;
4226             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4227             if ( phylogenies.length != 18 ) {
4228                 return false;
4229             }
4230             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4231                 return false;
4232             }
4233             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4234                 return false;
4235             }
4236             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4237                 return false;
4238             }
4239             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4240                 return false;
4241             }
4242             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4243                 return false;
4244             }
4245             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4246                 return false;
4247             }
4248             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4249                 return false;
4250             }
4251             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4252                 return false;
4253             }
4254             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4255                 return false;
4256             }
4257             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4258                 return false;
4259             }
4260             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4261                 return false;
4262             }
4263             if ( phylogenies[ 8 ].isRooted() ) {
4264                 return false;
4265             }
4266             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4267                 return false;
4268             }
4269             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4270                 return false;
4271             }
4272             if ( !phylogenies[ 9 ].isRooted() ) {
4273                 return false;
4274             }
4275             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4276                 return false;
4277             }
4278             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4279                 return false;
4280             }
4281             if ( !phylogenies[ 10 ].isRooted() ) {
4282                 return false;
4283             }
4284             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4285                 return false;
4286             }
4287             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4288                 return false;
4289             }
4290             if ( phylogenies[ 11 ].isRooted() ) {
4291                 return false;
4292             }
4293             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4294                 return false;
4295             }
4296             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4297                 return false;
4298             }
4299             if ( !phylogenies[ 12 ].isRooted() ) {
4300                 return false;
4301             }
4302             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4303                 return false;
4304             }
4305             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4306                 return false;
4307             }
4308             if ( !phylogenies[ 13 ].isRooted() ) {
4309                 return false;
4310             }
4311             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4312                 return false;
4313             }
4314             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4315                 return false;
4316             }
4317             if ( !phylogenies[ 14 ].isRooted() ) {
4318                 return false;
4319             }
4320             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4321                 return false;
4322             }
4323             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4324                 return false;
4325             }
4326             if ( phylogenies[ 15 ].isRooted() ) {
4327                 return false;
4328             }
4329             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4330                 return false;
4331             }
4332             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4333                 return false;
4334             }
4335             if ( !phylogenies[ 16 ].isRooted() ) {
4336                 return false;
4337             }
4338             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4339                 return false;
4340             }
4341             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4342                 return false;
4343             }
4344             if ( phylogenies[ 17 ].isRooted() ) {
4345                 return false;
4346             }
4347             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4348                 return false;
4349             }
4350         }
4351         catch ( final Exception e ) {
4352             e.printStackTrace( System.out );
4353             return false;
4354         }
4355         return true;
4356     }
4357
4358     private static boolean testNexusTreeParsingTranslating() {
4359         try {
4360             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4361             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4362             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
4363             if ( phylogenies.length != 1 ) {
4364                 return false;
4365             }
4366             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4367                 return false;
4368             }
4369             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4370                 return false;
4371             }
4372             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4373                 return false;
4374             }
4375             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4376                 return false;
4377             }
4378             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4379                     .equals( "Aranaeus" ) ) {
4380                 return false;
4381             }
4382             phylogenies = null;
4383             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
4384             if ( phylogenies.length != 3 ) {
4385                 return false;
4386             }
4387             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4388                 return false;
4389             }
4390             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4391                 return false;
4392             }
4393             if ( phylogenies[ 0 ].isRooted() ) {
4394                 return false;
4395             }
4396             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4397                 return false;
4398             }
4399             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4400                 return false;
4401             }
4402             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4403                     .equals( "Aranaeus" ) ) {
4404                 return false;
4405             }
4406             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4407                 return false;
4408             }
4409             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4410                 return false;
4411             }
4412             if ( phylogenies[ 1 ].isRooted() ) {
4413                 return false;
4414             }
4415             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4416                 return false;
4417             }
4418             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4419                 return false;
4420             }
4421             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4422                     .equals( "Aranaeus" ) ) {
4423                 return false;
4424             }
4425             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4426                 return false;
4427             }
4428             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4429                 return false;
4430             }
4431             if ( !phylogenies[ 2 ].isRooted() ) {
4432                 return false;
4433             }
4434             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4435                 return false;
4436             }
4437             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4438                 return false;
4439             }
4440             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4441                     .equals( "Aranaeus" ) ) {
4442                 return false;
4443             }
4444             phylogenies = null;
4445             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
4446             if ( phylogenies.length != 3 ) {
4447                 return false;
4448             }
4449             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4450                 return false;
4451             }
4452             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4453                 return false;
4454             }
4455             if ( phylogenies[ 0 ].isRooted() ) {
4456                 return false;
4457             }
4458             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4459                 return false;
4460             }
4461             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4462                 return false;
4463             }
4464             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4465                     .equals( "Aranaeus" ) ) {
4466                 return false;
4467             }
4468             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4469                 return false;
4470             }
4471             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4472                 return false;
4473             }
4474             if ( phylogenies[ 1 ].isRooted() ) {
4475                 return false;
4476             }
4477             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4478                 return false;
4479             }
4480             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4481                 return false;
4482             }
4483             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4484                     .equals( "Aranaeus" ) ) {
4485                 return false;
4486             }
4487             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4488                 return false;
4489             }
4490             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4491                 return false;
4492             }
4493             if ( !phylogenies[ 2 ].isRooted() ) {
4494                 return false;
4495             }
4496             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4497                 return false;
4498             }
4499             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4500                 return false;
4501             }
4502             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4503                     .equals( "Aranaeus" ) ) {
4504                 return false;
4505             }
4506         }
4507         catch ( final Exception e ) {
4508             e.printStackTrace( System.out );
4509             return false;
4510         }
4511         return true;
4512     }
4513
4514     private static boolean testNHParsing() {
4515         try {
4516             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4517             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
4518             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
4519                 return false;
4520             }
4521             final NHXParser nhxp = new NHXParser();
4522             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
4523             nhxp.setReplaceUnderscores( true );
4524             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
4525             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
4526                 return false;
4527             }
4528             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
4529                 return false;
4530             }
4531             final Phylogeny p1b = factory
4532                     .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 ",
4533                              new NHXParser() )[ 0 ];
4534             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
4535                 return false;
4536             }
4537             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
4538                 return false;
4539             }
4540             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
4541             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
4542             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
4543             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
4544             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
4545             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
4546             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
4547             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
4548             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
4549             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
4550             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
4551                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
4552                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
4553                                                     new NHXParser() );
4554             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
4555                 return false;
4556             }
4557             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
4558                 return false;
4559             }
4560             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
4561                 return false;
4562             }
4563             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
4564                 return false;
4565             }
4566             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
4567             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
4568             final String p16_S = "((A,B),C)";
4569             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
4570             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
4571                 return false;
4572             }
4573             final String p17_S = "(C,(A,B))";
4574             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
4575             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
4576                 return false;
4577             }
4578             final String p18_S = "((A,B),(C,D))";
4579             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
4580             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
4581                 return false;
4582             }
4583             final String p19_S = "(((A,B),C),D)";
4584             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
4585             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
4586                 return false;
4587             }
4588             final String p20_S = "(A,(B,(C,D)))";
4589             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
4590             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
4591                 return false;
4592             }
4593             final String p21_S = "(A,(B,(C,(D,E))))";
4594             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
4595             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
4596                 return false;
4597             }
4598             final String p22_S = "((((A,B),C),D),E)";
4599             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
4600             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
4601                 return false;
4602             }
4603             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4604             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
4605             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
4606                 return false;
4607             }
4608             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4609             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
4610             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
4611                 return false;
4612             }
4613             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4614             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4615             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
4616             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
4617                 return false;
4618             }
4619             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
4620                 return false;
4621             }
4622             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
4623                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
4624                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
4625                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
4626                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
4627                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
4628                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
4629                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
4630             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
4631             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
4632                 return false;
4633             }
4634             final String p26_S = "(A,B)ab";
4635             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
4636             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
4637                 return false;
4638             }
4639             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4640             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
4641                                                     new NHXParser() );
4642             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
4643                 return false;
4644             }
4645             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4646             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4647             final String p28_S3 = "(A,B)ab";
4648             final String p28_S4 = "((((A,B),C),D),;E;)";
4649             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
4650                                                     new NHXParser() );
4651             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
4652                 return false;
4653             }
4654             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
4655                 return false;
4656             }
4657             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
4658                 return false;
4659             }
4660             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
4661                 return false;
4662             }
4663             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";
4664             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
4665             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
4666                 return false;
4667             }
4668             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";
4669             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
4670             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
4671                 return false;
4672             }
4673             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
4674             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
4675             if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) {
4676                 return false;
4677             }
4678             final String p33_S = "A";
4679             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
4680             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
4681                 return false;
4682             }
4683             final String p34_S = "B;";
4684             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
4685             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
4686                 return false;
4687             }
4688             final String p35_S = "B:0.2";
4689             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
4690             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
4691                 return false;
4692             }
4693             final String p36_S = "(A)";
4694             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
4695             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
4696                 return false;
4697             }
4698             final String p37_S = "((A))";
4699             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
4700             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
4701                 return false;
4702             }
4703             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4704             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
4705             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
4706                 return false;
4707             }
4708             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4709             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
4710             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
4711                 return false;
4712             }
4713             final String p40_S = "(A,B,C)";
4714             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
4715             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
4716                 return false;
4717             }
4718             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
4719             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
4720             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
4721                 return false;
4722             }
4723             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
4724             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
4725             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
4726                 return false;
4727             }
4728             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)";
4729             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
4730             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
4731                 return false;
4732             }
4733             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)))";
4734             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
4735             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
4736                 return false;
4737             }
4738             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
4739             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
4740             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
4741                 return false;
4742             }
4743             final String p46_S = "";
4744             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
4745             if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) {
4746                 return false;
4747             }
4748             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
4749             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4750                 return false;
4751             }
4752             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4753             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4754                 return false;
4755             }
4756             final Phylogeny p49 = factory
4757                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
4758                              new NHXParser() )[ 0 ];
4759             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4760                 return false;
4761             }
4762             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4763             if ( p50.getNode( "A" ) == null ) {
4764                 return false;
4765             }
4766             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4767                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
4768                 return false;
4769             }
4770             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
4771                 return false;
4772             }
4773             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
4774                     .equals( "((A,B)88:2.0,C);" ) ) {
4775                 return false;
4776             }
4777             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4778             if ( p51.getNode( "A(A" ) == null ) {
4779                 return false;
4780             }
4781             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4782             if ( p52.getNode( "A(A" ) == null ) {
4783                 return false;
4784             }
4785             final Phylogeny p53 = factory
4786                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
4787                              new NHXParser() )[ 0 ];
4788             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
4789                 return false;
4790             }
4791             // 
4792             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
4793             if ( p54.getNode( "A" ) == null ) {
4794                 return false;
4795             }
4796             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4797                     .equals( "((A,B)[88],C);" ) ) {
4798                 return false;
4799             }
4800         }
4801         catch ( final Exception e ) {
4802             e.printStackTrace( System.out );
4803             return false;
4804         }
4805         return true;
4806     }
4807
4808     private static boolean testNHXconversion() {
4809         try {
4810             final PhylogenyNode n1 = new PhylogenyNode();
4811             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4812             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4813             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4814             final PhylogenyNode n5 = PhylogenyNode
4815                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
4816             final PhylogenyNode n6 = PhylogenyNode
4817                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1:W=2:C=0.0.0:XN=B=bool_tag=T]" );
4818             if ( !n1.toNewHampshireX().equals( "" ) ) {
4819                 return false;
4820             }
4821             if ( !n2.toNewHampshireX().equals( "" ) ) {
4822                 return false;
4823             }
4824             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
4825                 return false;
4826             }
4827             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
4828                 return false;
4829             }
4830             if ( !n5.toNewHampshireX()
4831                     .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) {
4832                 return false;
4833             }
4834             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) {
4835                 return false;
4836             }
4837         }
4838         catch ( final Exception e ) {
4839             e.printStackTrace( System.out );
4840             return false;
4841         }
4842         return true;
4843     }
4844
4845     private static boolean testNHXNodeParsing() {
4846         try {
4847             final PhylogenyNode n1 = new PhylogenyNode();
4848             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4849             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4850             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4851             final PhylogenyNode n5 = PhylogenyNode
4852                     .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]" );
4853             if ( !n3.getName().equals( "n3" ) ) {
4854                 return false;
4855             }
4856             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
4857                 return false;
4858             }
4859             if ( n3.isDuplication() ) {
4860                 return false;
4861             }
4862             if ( n3.isHasAssignedEvent() ) {
4863                 return false;
4864             }
4865             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
4866                 return false;
4867             }
4868             if ( !n4.getName().equals( "n4" ) ) {
4869                 return false;
4870             }
4871             if ( n4.getDistanceToParent() != 0.01 ) {
4872                 return false;
4873             }
4874             if ( !n5.getName().equals( "n5" ) ) {
4875                 return false;
4876             }
4877             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
4878                 return false;
4879             }
4880             if ( n5.getDistanceToParent() != 0.1 ) {
4881                 return false;
4882             }
4883             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
4884                 return false;
4885             }
4886             if ( !n5.isDuplication() ) {
4887                 return false;
4888             }
4889             if ( !n5.isHasAssignedEvent() ) {
4890                 return false;
4891             }
4892             if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) {
4893                 return false;
4894             }
4895             if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) {
4896                 return false;
4897             }
4898             final PhylogenyNode n8 = PhylogenyNode
4899                     .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4900             if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
4901                 return false;
4902             }
4903             if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
4904                 return false;
4905             }
4906             final PhylogenyNode n9 = PhylogenyNode
4907                     .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4908             if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
4909                 return false;
4910             }
4911             if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
4912                 return false;
4913             }
4914             final PhylogenyNode n10 = PhylogenyNode
4915                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4916             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
4917                 return false;
4918             }
4919             final PhylogenyNode n20 = PhylogenyNode
4920                     .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4921             if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
4922                 return false;
4923             }
4924             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
4925                 return false;
4926             }
4927             final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2",
4928                                                                                   NHXParser.TAXONOMY_EXTRACTION.YES );
4929             if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
4930                 return false;
4931             }
4932             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
4933                 return false;
4934             }
4935             final PhylogenyNode n20xx = PhylogenyNode
4936                     .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4937             if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
4938                 return false;
4939             }
4940             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
4941                 return false;
4942             }
4943             final PhylogenyNode n20xxx = PhylogenyNode
4944                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4945             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
4946                 return false;
4947             }
4948             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
4949                 return false;
4950             }
4951             final PhylogenyNode n20xxxx = PhylogenyNode
4952                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4953             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
4954                 return false;
4955             }
4956             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
4957                 return false;
4958             }
4959             final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG",
4960                                                                                  NHXParser.TAXONOMY_EXTRACTION.YES );
4961             if ( !n21.getName().equals( "n21_PIG" ) ) {
4962                 return false;
4963             }
4964             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
4965                 return false;
4966             }
4967             final PhylogenyNode n21x = PhylogenyNode
4968                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4969             if ( !n21x.getName().equals( "n21_PIG" ) ) {
4970                 return false;
4971             }
4972             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
4973                 return false;
4974             }
4975             final PhylogenyNode n22 = PhylogenyNode
4976                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4977             if ( !n22.getName().equals( "n22/PIG" ) ) {
4978                 return false;
4979             }
4980             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
4981                 return false;
4982             }
4983             final PhylogenyNode n23 = PhylogenyNode
4984                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4985             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
4986                 return false;
4987             }
4988             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
4989                 return false;
4990             }
4991             final PhylogenyNode a = PhylogenyNode
4992                     .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4993             if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
4994                 return false;
4995             }
4996             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
4997                 return false;
4998             }
4999             final PhylogenyNode b = PhylogenyNode
5000                     .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5001             if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
5002                 return false;
5003             }
5004             if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
5005                 return false;
5006             }
5007             final PhylogenyNode c = PhylogenyNode
5008                     .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
5009                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5010             if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
5011                 return false;
5012             }
5013             if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
5014                 return false;
5015             }
5016             final PhylogenyNode c1 = PhylogenyNode
5017                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
5018                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5019             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
5020                 return false;
5021             }
5022             if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
5023                 return false;
5024             }
5025             final PhylogenyNode c2 = PhylogenyNode
5026                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
5027                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5028             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
5029                 return false;
5030             }
5031             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
5032                 return false;
5033             }
5034             final PhylogenyNode d = PhylogenyNode
5035                     .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5036             if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
5037                 return false;
5038             }
5039             if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
5040                 return false;
5041             }
5042             final PhylogenyNode e = PhylogenyNode
5043                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5044             if ( !e.getName().equals( "n10_RAT1" ) ) {
5045                 return false;
5046             }
5047             if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
5048                 return false;
5049             }
5050             final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1",
5051                                                                                 NHXParser.TAXONOMY_EXTRACTION.YES );
5052             if ( !e2.getName().equals( "n10_RAT1" ) ) {
5053                 return false;
5054             }
5055             if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
5056                 return false;
5057             }
5058             final PhylogenyNode e3 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT~",
5059                                                                                 NHXParser.TAXONOMY_EXTRACTION.YES );
5060             if ( !e3.getName().equals( "n10_RAT~" ) ) {
5061                 return false;
5062             }
5063             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
5064                 return false;
5065             }
5066             final PhylogenyNode n11 = PhylogenyNode
5067                     .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
5068                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5069             if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
5070                 return false;
5071             }
5072             if ( n11.getDistanceToParent() != 0.4 ) {
5073                 return false;
5074             }
5075             if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
5076                 return false;
5077             }
5078             final PhylogenyNode n12 = PhylogenyNode
5079                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
5080                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5081             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
5082                 return false;
5083             }
5084             if ( n12.getDistanceToParent() != 0.4 ) {
5085                 return false;
5086             }
5087             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
5088                 return false;
5089             }
5090             final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa",
5091                                                                                NHXParser.TAXONOMY_EXTRACTION.YES );
5092             if ( !m.getName().equals( "n10_MOUSEa" ) ) {
5093                 return false;
5094             }
5095             if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
5096                 return false;
5097             }
5098             final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_",
5099                                                                                NHXParser.TAXONOMY_EXTRACTION.YES );
5100             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
5101                 return false;
5102             }
5103             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
5104                 return false;
5105             }
5106             final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" );
5107             final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" );
5108             if ( !tvu1.getRef().equals( "tag1" ) ) {
5109                 return false;
5110             }
5111             if ( !tvu1.getDataType().equals( "xsd:string" ) ) {
5112                 return false;
5113             }
5114             if ( !tvu1.getUnit().equals( "unit1" ) ) {
5115                 return false;
5116             }
5117             if ( !tvu1.getValue().equals( "value1" ) ) {
5118                 return false;
5119             }
5120             if ( !tvu3.getRef().equals( "tag3" ) ) {
5121                 return false;
5122             }
5123             if ( !tvu3.getDataType().equals( "xsd:string" ) ) {
5124                 return false;
5125             }
5126             if ( !tvu3.getUnit().equals( "unit3" ) ) {
5127                 return false;
5128             }
5129             if ( !tvu3.getValue().equals( "value3" ) ) {
5130                 return false;
5131             }
5132             if ( n1.getName().compareTo( "" ) != 0 ) {
5133                 return false;
5134             }
5135             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5136                 return false;
5137             }
5138             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5139                 return false;
5140             }
5141             if ( n2.getName().compareTo( "" ) != 0 ) {
5142                 return false;
5143             }
5144             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5145                 return false;
5146             }
5147             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5148                 return false;
5149             }
5150             final PhylogenyNode n00 = PhylogenyNode
5151                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:ID=node_identifier:S=Ecoli:D=N:Co=N:B=100:T=1:On=100:SOn=100:SNn=100:W=2:C=0.0.0:XN=U=url_tag=www.yahoo.com]" );
5152             if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) {
5153                 return false;
5154             }
5155             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
5156                 return false;
5157             }
5158             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
5159                 return false;
5160             }
5161             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) {
5162                 return false;
5163             }
5164             if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) {
5165                 return false;
5166             }
5167             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) {
5168                 return false;
5169             }
5170             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) {
5171                 return false;
5172             }
5173             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) {
5174                 return false;
5175             }
5176             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
5177             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
5178                 return false;
5179             }
5180             final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" );
5181             if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) {
5182                 return false;
5183             }
5184             final PhylogenyNode n13 = PhylogenyNode
5185                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5186             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
5187                 return false;
5188             }
5189             if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
5190                 return false;
5191             }
5192             final PhylogenyNode n14 = PhylogenyNode
5193                     .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5194             if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
5195                 return false;
5196             }
5197             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) {
5198                 return false;
5199             }
5200             final PhylogenyNode n15 = PhylogenyNode
5201                     .createInstanceFromNhxString( "something_wicked[123]",
5202                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5203             if ( !n15.getName().equals( "something_wicked" ) ) {
5204                 return false;
5205             }
5206             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
5207                 return false;
5208             }
5209             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
5210                 return false;
5211             }
5212             final PhylogenyNode n16 = PhylogenyNode
5213                     .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5214             if ( !n16.getName().equals( "something_wicked2" ) ) {
5215                 return false;
5216             }
5217             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
5218                 return false;
5219             }
5220             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
5221                 return false;
5222             }
5223             final PhylogenyNode n17 = PhylogenyNode
5224                     .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5225             if ( !n17.getName().equals( "something_wicked3" ) ) {
5226                 return false;
5227             }
5228             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
5229                 return false;
5230             }
5231             final PhylogenyNode n18 = PhylogenyNode
5232                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5233             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
5234                 return false;
5235             }
5236             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
5237                 return false;
5238             }
5239             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
5240                 return false;
5241             }
5242         }
5243         catch ( final Exception e ) {
5244             e.printStackTrace( System.out );
5245             return false;
5246         }
5247         return true;
5248     }
5249
5250     private static boolean testNHXParsing() {
5251         try {
5252             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5253             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
5254             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
5255                 return false;
5256             }
5257             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]";
5258             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
5259             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5260                 return false;
5261             }
5262             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]";
5263             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
5264             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
5265                 return false;
5266             }
5267             final Phylogeny[] p3 = factory
5268                     .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]",
5269                              new NHXParser() );
5270             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5271                 return false;
5272             }
5273             final Phylogeny[] p4 = factory
5274                     .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(]",
5275                              new NHXParser() );
5276             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5277                 return false;
5278             }
5279             final Phylogeny[] p5 = factory
5280                     .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(((]",
5281                              new NHXParser() );
5282             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5283                 return false;
5284             }
5285             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)";
5286             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)";
5287             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
5288             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
5289                 return false;
5290             }
5291             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)))";
5292             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)))";
5293             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
5294             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
5295                 return false;
5296             }
5297             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])   ))[,,, ])))))))";
5298             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
5299             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
5300             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
5301                 return false;
5302             }
5303             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
5304             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5305                 return false;
5306             }
5307             final Phylogeny p10 = factory
5308                     .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]",
5309                              new NHXParser() )[ 0 ];
5310             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5311                 return false;
5312             }
5313         }
5314         catch ( final Exception e ) {
5315             e.printStackTrace( System.out );
5316             return false;
5317         }
5318         return true;
5319     }
5320
5321     private static boolean testNHXParsingQuotes() {
5322         try {
5323             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5324             final NHXParser p = new NHXParser();
5325             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
5326             if ( phylogenies_0.length != 5 ) {
5327                 return false;
5328             }
5329             final Phylogeny phy = phylogenies_0[ 4 ];
5330             if ( phy.getNumberOfExternalNodes() != 7 ) {
5331                 return false;
5332             }
5333             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
5334                 return false;
5335             }
5336             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
5337                 return false;
5338             }
5339             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
5340                     .getScientificName().equals( "hsapiens" ) ) {
5341                 return false;
5342             }
5343             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
5344                 return false;
5345             }
5346             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
5347                 return false;
5348             }
5349             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
5350                 return false;
5351             }
5352             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
5353                 return false;
5354             }
5355             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
5356                 return false;
5357             }
5358             final NHXParser p1p = new NHXParser();
5359             p1p.setIgnoreQuotes( true );
5360             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
5361             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
5362                 return false;
5363             }
5364             final NHXParser p2p = new NHXParser();
5365             p1p.setIgnoreQuotes( false );
5366             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
5367             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
5368                 return false;
5369             }
5370             final NHXParser p3p = new NHXParser();
5371             p3p.setIgnoreQuotes( false );
5372             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
5373             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
5374                 return false;
5375             }
5376             final NHXParser p4p = new NHXParser();
5377             p4p.setIgnoreQuotes( false );
5378             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
5379             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
5380                 return false;
5381             }
5382             final Phylogeny p10 = factory
5383                     .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]",
5384                              new NHXParser() )[ 0 ];
5385             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]";
5386             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
5387                 return false;
5388             }
5389             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
5390             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
5391                 return false;
5392             }
5393             //
5394             final Phylogeny p12 = factory
5395                     .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]",
5396                              new NHXParser() )[ 0 ];
5397             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]";
5398             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
5399                 return false;
5400             }
5401             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
5402             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
5403                 return false;
5404             }
5405             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;";
5406             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
5407                 return false;
5408             }
5409             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
5410             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
5411                 return false;
5412             }
5413         }
5414         catch ( final Exception e ) {
5415             e.printStackTrace( System.out );
5416             return false;
5417         }
5418         return true;
5419     }
5420
5421     private static boolean testNHXParsingMB() {
5422         try {
5423             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5424             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
5425                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5426                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5427                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5428                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5429                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5430                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5431                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5432                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
5433             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
5434                 return false;
5435             }
5436             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
5437                 return false;
5438             }
5439             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
5440                            0.1100000000000000e+00 ) ) {
5441                 return false;
5442             }
5443             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
5444                 return false;
5445             }
5446             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
5447                 return false;
5448             }
5449             final Phylogeny p2 = factory
5450                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
5451                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5452                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5453                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5454                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5455                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5456                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5457                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5458                                      + "7.369400000000000e-02}])",
5459                              new NHXParser() )[ 0 ];
5460             if ( p2.getNode( "1" ) == null ) {
5461                 return false;
5462             }
5463             if ( p2.getNode( "2" ) == null ) {
5464                 return false;
5465             }
5466         }
5467         catch ( final Exception e ) {
5468             e.printStackTrace( System.out );
5469             System.exit( -1 );
5470             return false;
5471         }
5472         return true;
5473     }
5474
5475     private static boolean testPhylogenyBranch() {
5476         try {
5477             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
5478             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
5479             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
5480             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
5481             if ( !a1b1.equals( a1b1 ) ) {
5482                 return false;
5483             }
5484             if ( !a1b1.equals( b1a1 ) ) {
5485                 return false;
5486             }
5487             if ( !b1a1.equals( a1b1 ) ) {
5488                 return false;
5489             }
5490             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
5491             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
5492             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
5493             if ( a1_b1.equals( b1_a1 ) ) {
5494                 return false;
5495             }
5496             if ( a1_b1.equals( a1_b1_ ) ) {
5497                 return false;
5498             }
5499             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
5500             if ( !a1_b1.equals( b1_a1_ ) ) {
5501                 return false;
5502             }
5503             if ( a1_b1_.equals( b1_a1_ ) ) {
5504                 return false;
5505             }
5506             if ( !a1_b1_.equals( b1_a1 ) ) {
5507                 return false;
5508             }
5509         }
5510         catch ( final Exception e ) {
5511             e.printStackTrace( System.out );
5512             return false;
5513         }
5514         return true;
5515     }
5516
5517     private static boolean testPhyloXMLparsingOfDistributionElement() {
5518         try {
5519             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5520             PhyloXmlParser xml_parser = null;
5521             try {
5522                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
5523             }
5524             catch ( final Exception e ) {
5525                 // Do nothing -- means were not running from jar.
5526             }
5527             if ( xml_parser == null ) {
5528                 xml_parser = new PhyloXmlParser();
5529                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
5530                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
5531                 }
5532                 else {
5533                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
5534                 }
5535             }
5536             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
5537                                                               xml_parser );
5538             if ( xml_parser.getErrorCount() > 0 ) {
5539                 System.out.println( xml_parser.getErrorMessages().toString() );
5540                 return false;
5541             }
5542             if ( phylogenies_0.length != 1 ) {
5543                 return false;
5544             }
5545             final Phylogeny t1 = phylogenies_0[ 0 ];
5546             PhylogenyNode n = null;
5547             Distribution d = null;
5548             n = t1.getNode( "root node" );
5549             if ( !n.getNodeData().isHasDistribution() ) {
5550                 return false;
5551             }
5552             if ( n.getNodeData().getDistributions().size() != 1 ) {
5553                 return false;
5554             }
5555             d = n.getNodeData().getDistribution();
5556             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5557                 return false;
5558             }
5559             if ( d.getPoints().size() != 1 ) {
5560                 return false;
5561             }
5562             if ( d.getPolygons() != null ) {
5563                 return false;
5564             }
5565             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5566                 return false;
5567             }
5568             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5569                 return false;
5570             }
5571             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5572                 return false;
5573             }
5574             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5575                 return false;
5576             }
5577             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5578                 return false;
5579             }
5580             n = t1.getNode( "node a" );
5581             if ( !n.getNodeData().isHasDistribution() ) {
5582                 return false;
5583             }
5584             if ( n.getNodeData().getDistributions().size() != 2 ) {
5585                 return false;
5586             }
5587             d = n.getNodeData().getDistribution( 1 );
5588             if ( !d.getDesc().equals( "San Diego" ) ) {
5589                 return false;
5590             }
5591             if ( d.getPoints().size() != 1 ) {
5592                 return false;
5593             }
5594             if ( d.getPolygons() != null ) {
5595                 return false;
5596             }
5597             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5598                 return false;
5599             }
5600             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5601                 return false;
5602             }
5603             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5604                 return false;
5605             }
5606             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5607                 return false;
5608             }
5609             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5610                 return false;
5611             }
5612             n = t1.getNode( "node bb" );
5613             if ( !n.getNodeData().isHasDistribution() ) {
5614                 return false;
5615             }
5616             if ( n.getNodeData().getDistributions().size() != 1 ) {
5617                 return false;
5618             }
5619             d = n.getNodeData().getDistribution( 0 );
5620             if ( d.getPoints().size() != 3 ) {
5621                 return false;
5622             }
5623             if ( d.getPolygons().size() != 2 ) {
5624                 return false;
5625             }
5626             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5627                 return false;
5628             }
5629             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5630                 return false;
5631             }
5632             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5633                 return false;
5634             }
5635             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5636                 return false;
5637             }
5638             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5639                 return false;
5640             }
5641             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5642                 return false;
5643             }
5644             Polygon p = d.getPolygons().get( 0 );
5645             if ( p.getPoints().size() != 3 ) {
5646                 return false;
5647             }
5648             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5649                 return false;
5650             }
5651             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5652                 return false;
5653             }
5654             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5655                 return false;
5656             }
5657             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5658                 return false;
5659             }
5660             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5661                 return false;
5662             }
5663             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5664                 return false;
5665             }
5666             p = d.getPolygons().get( 1 );
5667             if ( p.getPoints().size() != 3 ) {
5668                 return false;
5669             }
5670             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5671                 return false;
5672             }
5673             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5674                 return false;
5675             }
5676             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5677                 return false;
5678             }
5679             // Roundtrip:
5680             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
5681             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
5682             if ( rt.length != 1 ) {
5683                 return false;
5684             }
5685             final Phylogeny t1_rt = rt[ 0 ];
5686             n = t1_rt.getNode( "root node" );
5687             if ( !n.getNodeData().isHasDistribution() ) {
5688                 return false;
5689             }
5690             if ( n.getNodeData().getDistributions().size() != 1 ) {
5691                 return false;
5692             }
5693             d = n.getNodeData().getDistribution();
5694             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5695                 return false;
5696             }
5697             if ( d.getPoints().size() != 1 ) {
5698                 return false;
5699             }
5700             if ( d.getPolygons() != null ) {
5701                 return false;
5702             }
5703             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5704                 return false;
5705             }
5706             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5707                 return false;
5708             }
5709             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5710                 return false;
5711             }
5712             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5713                 return false;
5714             }
5715             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5716                 return false;
5717             }
5718             n = t1_rt.getNode( "node a" );
5719             if ( !n.getNodeData().isHasDistribution() ) {
5720                 return false;
5721             }
5722             if ( n.getNodeData().getDistributions().size() != 2 ) {
5723                 return false;
5724             }
5725             d = n.getNodeData().getDistribution( 1 );
5726             if ( !d.getDesc().equals( "San Diego" ) ) {
5727                 return false;
5728             }
5729             if ( d.getPoints().size() != 1 ) {
5730                 return false;
5731             }
5732             if ( d.getPolygons() != null ) {
5733                 return false;
5734             }
5735             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5736                 return false;
5737             }
5738             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5739                 return false;
5740             }
5741             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5742                 return false;
5743             }
5744             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5745                 return false;
5746             }
5747             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5748                 return false;
5749             }
5750             n = t1_rt.getNode( "node bb" );
5751             if ( !n.getNodeData().isHasDistribution() ) {
5752                 return false;
5753             }
5754             if ( n.getNodeData().getDistributions().size() != 1 ) {
5755                 return false;
5756             }
5757             d = n.getNodeData().getDistribution( 0 );
5758             if ( d.getPoints().size() != 3 ) {
5759                 return false;
5760             }
5761             if ( d.getPolygons().size() != 2 ) {
5762                 return false;
5763             }
5764             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5765                 return false;
5766             }
5767             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5768                 return false;
5769             }
5770             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5771                 return false;
5772             }
5773             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5774                 return false;
5775             }
5776             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5777                 return false;
5778             }
5779             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5780                 return false;
5781             }
5782             p = d.getPolygons().get( 0 );
5783             if ( p.getPoints().size() != 3 ) {
5784                 return false;
5785             }
5786             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5787                 return false;
5788             }
5789             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5790                 return false;
5791             }
5792             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5793                 return false;
5794             }
5795             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5796                 return false;
5797             }
5798             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5799                 return false;
5800             }
5801             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5802                 return false;
5803             }
5804             p = d.getPolygons().get( 1 );
5805             if ( p.getPoints().size() != 3 ) {
5806                 return false;
5807             }
5808             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5809                 return false;
5810             }
5811             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5812                 return false;
5813             }
5814             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5815                 return false;
5816             }
5817         }
5818         catch ( final Exception e ) {
5819             e.printStackTrace( System.out );
5820             return false;
5821         }
5822         return true;
5823     }
5824
5825     private static boolean testPostOrderIterator() {
5826         try {
5827             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5828             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5829             PhylogenyNodeIterator it0;
5830             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
5831                 it0.next();
5832             }
5833             for( it0.reset(); it0.hasNext(); ) {
5834                 it0.next();
5835             }
5836             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5837             final PhylogenyNodeIterator it = t1.iteratorPostorder();
5838             if ( !it.next().getName().equals( "A" ) ) {
5839                 return false;
5840             }
5841             if ( !it.next().getName().equals( "B" ) ) {
5842                 return false;
5843             }
5844             if ( !it.next().getName().equals( "ab" ) ) {
5845                 return false;
5846             }
5847             if ( !it.next().getName().equals( "C" ) ) {
5848                 return false;
5849             }
5850             if ( !it.next().getName().equals( "D" ) ) {
5851                 return false;
5852             }
5853             if ( !it.next().getName().equals( "cd" ) ) {
5854                 return false;
5855             }
5856             if ( !it.next().getName().equals( "abcd" ) ) {
5857                 return false;
5858             }
5859             if ( !it.next().getName().equals( "E" ) ) {
5860                 return false;
5861             }
5862             if ( !it.next().getName().equals( "F" ) ) {
5863                 return false;
5864             }
5865             if ( !it.next().getName().equals( "ef" ) ) {
5866                 return false;
5867             }
5868             if ( !it.next().getName().equals( "G" ) ) {
5869                 return false;
5870             }
5871             if ( !it.next().getName().equals( "H" ) ) {
5872                 return false;
5873             }
5874             if ( !it.next().getName().equals( "gh" ) ) {
5875                 return false;
5876             }
5877             if ( !it.next().getName().equals( "efgh" ) ) {
5878                 return false;
5879             }
5880             if ( !it.next().getName().equals( "r" ) ) {
5881                 return false;
5882             }
5883             if ( it.hasNext() ) {
5884                 return false;
5885             }
5886         }
5887         catch ( final Exception e ) {
5888             e.printStackTrace( System.out );
5889             return false;
5890         }
5891         return true;
5892     }
5893
5894     private static boolean testPreOrderIterator() {
5895         try {
5896             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5897             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5898             PhylogenyNodeIterator it0;
5899             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
5900                 it0.next();
5901             }
5902             for( it0.reset(); it0.hasNext(); ) {
5903                 it0.next();
5904             }
5905             PhylogenyNodeIterator it = t0.iteratorPreorder();
5906             if ( !it.next().getName().equals( "r" ) ) {
5907                 return false;
5908             }
5909             if ( !it.next().getName().equals( "ab" ) ) {
5910                 return false;
5911             }
5912             if ( !it.next().getName().equals( "A" ) ) {
5913                 return false;
5914             }
5915             if ( !it.next().getName().equals( "B" ) ) {
5916                 return false;
5917             }
5918             if ( !it.next().getName().equals( "cd" ) ) {
5919                 return false;
5920             }
5921             if ( !it.next().getName().equals( "C" ) ) {
5922                 return false;
5923             }
5924             if ( !it.next().getName().equals( "D" ) ) {
5925                 return false;
5926             }
5927             if ( it.hasNext() ) {
5928                 return false;
5929             }
5930             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5931             it = t1.iteratorPreorder();
5932             if ( !it.next().getName().equals( "r" ) ) {
5933                 return false;
5934             }
5935             if ( !it.next().getName().equals( "abcd" ) ) {
5936                 return false;
5937             }
5938             if ( !it.next().getName().equals( "ab" ) ) {
5939                 return false;
5940             }
5941             if ( !it.next().getName().equals( "A" ) ) {
5942                 return false;
5943             }
5944             if ( !it.next().getName().equals( "B" ) ) {
5945                 return false;
5946             }
5947             if ( !it.next().getName().equals( "cd" ) ) {
5948                 return false;
5949             }
5950             if ( !it.next().getName().equals( "C" ) ) {
5951                 return false;
5952             }
5953             if ( !it.next().getName().equals( "D" ) ) {
5954                 return false;
5955             }
5956             if ( !it.next().getName().equals( "efgh" ) ) {
5957                 return false;
5958             }
5959             if ( !it.next().getName().equals( "ef" ) ) {
5960                 return false;
5961             }
5962             if ( !it.next().getName().equals( "E" ) ) {
5963                 return false;
5964             }
5965             if ( !it.next().getName().equals( "F" ) ) {
5966                 return false;
5967             }
5968             if ( !it.next().getName().equals( "gh" ) ) {
5969                 return false;
5970             }
5971             if ( !it.next().getName().equals( "G" ) ) {
5972                 return false;
5973             }
5974             if ( !it.next().getName().equals( "H" ) ) {
5975                 return false;
5976             }
5977             if ( it.hasNext() ) {
5978                 return false;
5979             }
5980         }
5981         catch ( final Exception e ) {
5982             e.printStackTrace( System.out );
5983             return false;
5984         }
5985         return true;
5986     }
5987
5988     private static boolean testPropertiesMap() {
5989         try {
5990             final PropertiesMap pm = new PropertiesMap();
5991             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
5992             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
5993             final Property p2 = new Property( "something:else",
5994                                               "?",
5995                                               "improbable:research",
5996                                               "xsd:decimal",
5997                                               AppliesTo.NODE );
5998             pm.addProperty( p0 );
5999             pm.addProperty( p1 );
6000             pm.addProperty( p2 );
6001             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
6002                 return false;
6003             }
6004             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
6005                 return false;
6006             }
6007             if ( pm.getProperties().size() != 3 ) {
6008                 return false;
6009             }
6010             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
6011                 return false;
6012             }
6013             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6014                 return false;
6015             }
6016             if ( pm.getProperties().size() != 3 ) {
6017                 return false;
6018             }
6019             pm.removeProperty( "dimensions:diameter" );
6020             if ( pm.getProperties().size() != 2 ) {
6021                 return false;
6022             }
6023             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
6024                 return false;
6025             }
6026             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6027                 return false;
6028             }
6029         }
6030         catch ( final Exception e ) {
6031             e.printStackTrace( System.out );
6032             return false;
6033         }
6034         return true;
6035     }
6036
6037     private static boolean testReIdMethods() {
6038         try {
6039             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6040             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
6041             final int count = PhylogenyNode.getNodeCount();
6042             p.levelOrderReID();
6043             if ( p.getNode( "r" ).getId() != count ) {
6044                 return false;
6045             }
6046             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
6047                 return false;
6048             }
6049             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
6050                 return false;
6051             }
6052             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
6053                 return false;
6054             }
6055             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
6056                 return false;
6057             }
6058             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
6059                 return false;
6060             }
6061             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
6062                 return false;
6063             }
6064             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
6065                 return false;
6066             }
6067             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
6068                 return false;
6069             }
6070             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
6071                 return false;
6072             }
6073             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
6074                 return false;
6075             }
6076             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
6077                 return false;
6078             }
6079             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
6080                 return false;
6081             }
6082             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
6083                 return false;
6084             }
6085             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
6086                 return false;
6087             }
6088         }
6089         catch ( final Exception e ) {
6090             e.printStackTrace( System.out );
6091             return false;
6092         }
6093         return true;
6094     }
6095
6096     private static boolean testRerooting() {
6097         try {
6098             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6099             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",
6100                                                  new NHXParser() )[ 0 ];
6101             if ( !t1.isRooted() ) {
6102                 return false;
6103             }
6104             t1.reRoot( t1.getNode( "D" ) );
6105             t1.reRoot( t1.getNode( "CD" ) );
6106             t1.reRoot( t1.getNode( "A" ) );
6107             t1.reRoot( t1.getNode( "B" ) );
6108             t1.reRoot( t1.getNode( "AB" ) );
6109             t1.reRoot( t1.getNode( "D" ) );
6110             t1.reRoot( t1.getNode( "C" ) );
6111             t1.reRoot( t1.getNode( "CD" ) );
6112             t1.reRoot( t1.getNode( "A" ) );
6113             t1.reRoot( t1.getNode( "B" ) );
6114             t1.reRoot( t1.getNode( "AB" ) );
6115             t1.reRoot( t1.getNode( "D" ) );
6116             t1.reRoot( t1.getNode( "D" ) );
6117             t1.reRoot( t1.getNode( "C" ) );
6118             t1.reRoot( t1.getNode( "A" ) );
6119             t1.reRoot( t1.getNode( "B" ) );
6120             t1.reRoot( t1.getNode( "AB" ) );
6121             t1.reRoot( t1.getNode( "C" ) );
6122             t1.reRoot( t1.getNode( "D" ) );
6123             t1.reRoot( t1.getNode( "CD" ) );
6124             t1.reRoot( t1.getNode( "D" ) );
6125             t1.reRoot( t1.getNode( "A" ) );
6126             t1.reRoot( t1.getNode( "B" ) );
6127             t1.reRoot( t1.getNode( "AB" ) );
6128             t1.reRoot( t1.getNode( "C" ) );
6129             t1.reRoot( t1.getNode( "D" ) );
6130             t1.reRoot( t1.getNode( "CD" ) );
6131             t1.reRoot( t1.getNode( "D" ) );
6132             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6133                 return false;
6134             }
6135             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6136                 return false;
6137             }
6138             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6139                 return false;
6140             }
6141             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
6142                 return false;
6143             }
6144             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
6145                 return false;
6146             }
6147             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
6148                 return false;
6149             }
6150             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",
6151                                                  new NHXParser() )[ 0 ];
6152             t2.reRoot( t2.getNode( "A" ) );
6153             t2.reRoot( t2.getNode( "D" ) );
6154             t2.reRoot( t2.getNode( "ABC" ) );
6155             t2.reRoot( t2.getNode( "A" ) );
6156             t2.reRoot( t2.getNode( "B" ) );
6157             t2.reRoot( t2.getNode( "D" ) );
6158             t2.reRoot( t2.getNode( "C" ) );
6159             t2.reRoot( t2.getNode( "ABC" ) );
6160             t2.reRoot( t2.getNode( "A" ) );
6161             t2.reRoot( t2.getNode( "B" ) );
6162             t2.reRoot( t2.getNode( "AB" ) );
6163             t2.reRoot( t2.getNode( "AB" ) );
6164             t2.reRoot( t2.getNode( "D" ) );
6165             t2.reRoot( t2.getNode( "C" ) );
6166             t2.reRoot( t2.getNode( "B" ) );
6167             t2.reRoot( t2.getNode( "AB" ) );
6168             t2.reRoot( t2.getNode( "D" ) );
6169             t2.reRoot( t2.getNode( "D" ) );
6170             t2.reRoot( t2.getNode( "ABC" ) );
6171             t2.reRoot( t2.getNode( "A" ) );
6172             t2.reRoot( t2.getNode( "B" ) );
6173             t2.reRoot( t2.getNode( "AB" ) );
6174             t2.reRoot( t2.getNode( "D" ) );
6175             t2.reRoot( t2.getNode( "C" ) );
6176             t2.reRoot( t2.getNode( "ABC" ) );
6177             t2.reRoot( t2.getNode( "A" ) );
6178             t2.reRoot( t2.getNode( "B" ) );
6179             t2.reRoot( t2.getNode( "AB" ) );
6180             t2.reRoot( t2.getNode( "D" ) );
6181             t2.reRoot( t2.getNode( "D" ) );
6182             t2.reRoot( t2.getNode( "C" ) );
6183             t2.reRoot( t2.getNode( "A" ) );
6184             t2.reRoot( t2.getNode( "B" ) );
6185             t2.reRoot( t2.getNode( "AB" ) );
6186             t2.reRoot( t2.getNode( "C" ) );
6187             t2.reRoot( t2.getNode( "D" ) );
6188             t2.reRoot( t2.getNode( "ABC" ) );
6189             t2.reRoot( t2.getNode( "D" ) );
6190             t2.reRoot( t2.getNode( "A" ) );
6191             t2.reRoot( t2.getNode( "B" ) );
6192             t2.reRoot( t2.getNode( "AB" ) );
6193             t2.reRoot( t2.getNode( "C" ) );
6194             t2.reRoot( t2.getNode( "D" ) );
6195             t2.reRoot( t2.getNode( "ABC" ) );
6196             t2.reRoot( t2.getNode( "D" ) );
6197             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6198                 return false;
6199             }
6200             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6201                 return false;
6202             }
6203             t2.reRoot( t2.getNode( "ABC" ) );
6204             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6205                 return false;
6206             }
6207             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6208                 return false;
6209             }
6210             t2.reRoot( t2.getNode( "AB" ) );
6211             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6212                 return false;
6213             }
6214             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6215                 return false;
6216             }
6217             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6218                 return false;
6219             }
6220             t2.reRoot( t2.getNode( "AB" ) );
6221             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6222                 return false;
6223             }
6224             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6225                 return false;
6226             }
6227             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6228                 return false;
6229             }
6230             t2.reRoot( t2.getNode( "D" ) );
6231             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6232                 return false;
6233             }
6234             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6235                 return false;
6236             }
6237             t2.reRoot( t2.getNode( "ABC" ) );
6238             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6239                 return false;
6240             }
6241             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6242                 return false;
6243             }
6244             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
6245                                                  new NHXParser() )[ 0 ];
6246             t3.reRoot( t3.getNode( "B" ) );
6247             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6248                 return false;
6249             }
6250             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6251                 return false;
6252             }
6253             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6254                 return false;
6255             }
6256             t3.reRoot( t3.getNode( "B" ) );
6257             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6258                 return false;
6259             }
6260             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6261                 return false;
6262             }
6263             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6264                 return false;
6265             }
6266             t3.reRoot( t3.getRoot() );
6267             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6268                 return false;
6269             }
6270             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6271                 return false;
6272             }
6273             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6274                 return false;
6275             }
6276         }
6277         catch ( final Exception e ) {
6278             e.printStackTrace( System.out );
6279             return false;
6280         }
6281         return true;
6282     }
6283
6284     private static boolean testSDIse() {
6285         try {
6286             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6287             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
6288             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
6289             gene1.setRooted( true );
6290             species1.setRooted( true );
6291             final SDI sdi = new SDI( gene1, species1 );
6292             if ( !gene1.getRoot().isDuplication() ) {
6293                 return false;
6294             }
6295             final Phylogeny species2 = factory
6296                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6297                              new NHXParser() )[ 0 ];
6298             final Phylogeny gene2 = factory
6299                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6300                              new NHXParser() )[ 0 ];
6301             species2.setRooted( true );
6302             gene2.setRooted( true );
6303             final SDI sdi2 = new SDI( gene2, species2 );
6304             if ( sdi2.getDuplicationsSum() != 0 ) {
6305                 return false;
6306             }
6307             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
6308                 return false;
6309             }
6310             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
6311                 return false;
6312             }
6313             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
6314                 return false;
6315             }
6316             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
6317                 return false;
6318             }
6319             if ( !gene2.getNode( "r" ).isSpeciation() ) {
6320                 return false;
6321             }
6322             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
6323                 return false;
6324             }
6325             final Phylogeny species3 = factory
6326                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6327                              new NHXParser() )[ 0 ];
6328             final Phylogeny gene3 = factory
6329                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6330                              new NHXParser() )[ 0 ];
6331             species3.setRooted( true );
6332             gene3.setRooted( true );
6333             final SDI sdi3 = new SDI( gene3, species3 );
6334             if ( sdi3.getDuplicationsSum() != 1 ) {
6335                 return false;
6336             }
6337             if ( !gene3.getNode( "aa" ).isDuplication() ) {
6338                 return false;
6339             }
6340             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
6341                 return false;
6342             }
6343             final Phylogeny species4 = factory
6344                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6345                              new NHXParser() )[ 0 ];
6346             final Phylogeny gene4 = factory
6347                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6348                              new NHXParser() )[ 0 ];
6349             species4.setRooted( true );
6350             gene4.setRooted( true );
6351             final SDI sdi4 = new SDI( gene4, species4 );
6352             if ( sdi4.getDuplicationsSum() != 1 ) {
6353                 return false;
6354             }
6355             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
6356                 return false;
6357             }
6358             if ( !gene4.getNode( "abc" ).isDuplication() ) {
6359                 return false;
6360             }
6361             if ( gene4.getNode( "abcd" ).isDuplication() ) {
6362                 return false;
6363             }
6364             if ( species4.getNumberOfExternalNodes() != 6 ) {
6365                 return false;
6366             }
6367             if ( gene4.getNumberOfExternalNodes() != 6 ) {
6368                 return false;
6369             }
6370             final Phylogeny species5 = factory
6371                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6372                              new NHXParser() )[ 0 ];
6373             final Phylogeny gene5 = factory
6374                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6375                              new NHXParser() )[ 0 ];
6376             species5.setRooted( true );
6377             gene5.setRooted( true );
6378             final SDI sdi5 = new SDI( gene5, species5 );
6379             if ( sdi5.getDuplicationsSum() != 2 ) {
6380                 return false;
6381             }
6382             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
6383                 return false;
6384             }
6385             if ( !gene5.getNode( "adc" ).isDuplication() ) {
6386                 return false;
6387             }
6388             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
6389                 return false;
6390             }
6391             if ( species5.getNumberOfExternalNodes() != 6 ) {
6392                 return false;
6393             }
6394             if ( gene5.getNumberOfExternalNodes() != 6 ) {
6395                 return false;
6396             }
6397             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
6398             // Conjecture for Comparing Molecular Phylogenies"
6399             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
6400             final Phylogeny species6 = factory
6401                     .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,"
6402                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6403                              new NHXParser() )[ 0 ];
6404             final Phylogeny gene6 = factory
6405                     .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,"
6406                                      + "((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,"
6407                                      + "(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;",
6408                              new NHXParser() )[ 0 ];
6409             species6.setRooted( true );
6410             gene6.setRooted( true );
6411             final SDI sdi6 = new SDI( gene6, species6 );
6412             if ( sdi6.getDuplicationsSum() != 3 ) {
6413                 return false;
6414             }
6415             if ( !gene6.getNode( "r" ).isDuplication() ) {
6416                 return false;
6417             }
6418             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
6419                 return false;
6420             }
6421             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
6422                 return false;
6423             }
6424             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
6425                 return false;
6426             }
6427             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
6428                 return false;
6429             }
6430             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
6431                 return false;
6432             }
6433             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
6434                 return false;
6435             }
6436             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
6437                 return false;
6438             }
6439             sdi6.computeMappingCostL();
6440             if ( sdi6.computeMappingCostL() != 17 ) {
6441                 return false;
6442             }
6443             if ( species6.getNumberOfExternalNodes() != 9 ) {
6444                 return false;
6445             }
6446             if ( gene6.getNumberOfExternalNodes() != 9 ) {
6447                 return false;
6448             }
6449             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
6450                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
6451                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
6452                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
6453                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
6454             species7.setRooted( true );
6455             final Phylogeny gene7_1 = Test
6456                     .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])" );
6457             gene7_1.setRooted( true );
6458             final SDI sdi7 = new SDI( gene7_1, species7 );
6459             if ( sdi7.getDuplicationsSum() != 0 ) {
6460                 return false;
6461             }
6462             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
6463                 return false;
6464             }
6465             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
6466                 return false;
6467             }
6468             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
6469                 return false;
6470             }
6471             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
6472                 return false;
6473             }
6474             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
6475                 return false;
6476             }
6477             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
6478                 return false;
6479             }
6480             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
6481                 return false;
6482             }
6483             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
6484                 return false;
6485             }
6486             final Phylogeny gene7_2 = Test
6487                     .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])" );
6488             gene7_2.setRooted( true );
6489             final SDI sdi7_2 = new SDI( gene7_2, species7 );
6490             if ( sdi7_2.getDuplicationsSum() != 1 ) {
6491                 return false;
6492             }
6493             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
6494                 return false;
6495             }
6496             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
6497                 return false;
6498             }
6499             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
6500                 return false;
6501             }
6502             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
6503                 return false;
6504             }
6505             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
6506                 return false;
6507             }
6508             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
6509                 return false;
6510             }
6511             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
6512                 return false;
6513             }
6514             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
6515                 return false;
6516             }
6517             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
6518                 return false;
6519             }
6520         }
6521         catch ( final Exception e ) {
6522             return false;
6523         }
6524         return true;
6525     }
6526
6527     private static boolean testSDIunrooted() {
6528         try {
6529             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6530             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
6531             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
6532             final Iterator<PhylogenyBranch> iter = l.iterator();
6533             PhylogenyBranch br = iter.next();
6534             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
6535                 return false;
6536             }
6537             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
6538                 return false;
6539             }
6540             br = iter.next();
6541             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6542                 return false;
6543             }
6544             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6545                 return false;
6546             }
6547             br = iter.next();
6548             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
6549                 return false;
6550             }
6551             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
6552                 return false;
6553             }
6554             br = iter.next();
6555             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6556                 return false;
6557             }
6558             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6559                 return false;
6560             }
6561             br = iter.next();
6562             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6563                 return false;
6564             }
6565             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6566                 return false;
6567             }
6568             br = iter.next();
6569             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6570                 return false;
6571             }
6572             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6573                 return false;
6574             }
6575             br = iter.next();
6576             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6577                 return false;
6578             }
6579             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6580                 return false;
6581             }
6582             br = iter.next();
6583             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6584                 return false;
6585             }
6586             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6587                 return false;
6588             }
6589             br = iter.next();
6590             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6591                 return false;
6592             }
6593             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6594                 return false;
6595             }
6596             br = iter.next();
6597             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6598                 return false;
6599             }
6600             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6601                 return false;
6602             }
6603             br = iter.next();
6604             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6605                 return false;
6606             }
6607             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6608                 return false;
6609             }
6610             br = iter.next();
6611             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
6612                 return false;
6613             }
6614             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
6615                 return false;
6616             }
6617             br = iter.next();
6618             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6619                 return false;
6620             }
6621             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6622                 return false;
6623             }
6624             br = iter.next();
6625             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
6626                 return false;
6627             }
6628             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
6629                 return false;
6630             }
6631             br = iter.next();
6632             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
6633                 return false;
6634             }
6635             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
6636                 return false;
6637             }
6638             if ( iter.hasNext() ) {
6639                 return false;
6640             }
6641             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
6642             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
6643             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
6644             br = iter1.next();
6645             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6646                 return false;
6647             }
6648             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6649                 return false;
6650             }
6651             br = iter1.next();
6652             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6653                 return false;
6654             }
6655             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6656                 return false;
6657             }
6658             br = iter1.next();
6659             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6660                 return false;
6661             }
6662             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6663                 return false;
6664             }
6665             if ( iter1.hasNext() ) {
6666                 return false;
6667             }
6668             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
6669             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
6670             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
6671             br = iter2.next();
6672             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6673                 return false;
6674             }
6675             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6676                 return false;
6677             }
6678             br = iter2.next();
6679             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6680                 return false;
6681             }
6682             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6683                 return false;
6684             }
6685             br = iter2.next();
6686             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6687                 return false;
6688             }
6689             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6690                 return false;
6691             }
6692             if ( iter2.hasNext() ) {
6693                 return false;
6694             }
6695             final Phylogeny species0 = factory
6696                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6697                              new NHXParser() )[ 0 ];
6698             final Phylogeny gene1 = factory
6699                     .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])",
6700                              new NHXParser() )[ 0 ];
6701             species0.setRooted( true );
6702             gene1.setRooted( true );
6703             final SDIR sdi_unrooted = new SDIR();
6704             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
6705             if ( sdi_unrooted.getCount() != 1 ) {
6706                 return false;
6707             }
6708             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
6709                 return false;
6710             }
6711             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
6712                 return false;
6713             }
6714             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
6715                 return false;
6716             }
6717             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6718                 return false;
6719             }
6720             final Phylogeny gene2 = factory
6721                     .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])",
6722                              new NHXParser() )[ 0 ];
6723             gene2.setRooted( true );
6724             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
6725             if ( sdi_unrooted.getCount() != 1 ) {
6726                 return false;
6727             }
6728             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6729                 return false;
6730             }
6731             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6732                 return false;
6733             }
6734             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
6735                 return false;
6736             }
6737             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6738                 return false;
6739             }
6740             final Phylogeny species6 = factory
6741                     .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,"
6742                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6743                              new NHXParser() )[ 0 ];
6744             final Phylogeny gene6 = factory
6745                     .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],"
6746                                      + "(((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],"
6747                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6748                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6749                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6750                              new NHXParser() )[ 0 ];
6751             species6.setRooted( true );
6752             gene6.setRooted( true );
6753             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
6754             if ( sdi_unrooted.getCount() != 1 ) {
6755                 return false;
6756             }
6757             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6758                 return false;
6759             }
6760             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6761                 return false;
6762             }
6763             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6764                 return false;
6765             }
6766             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6767                 return false;
6768             }
6769             if ( !p6[ 0 ].getRoot().isDuplication() ) {
6770                 return false;
6771             }
6772             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6773                 return false;
6774             }
6775             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6776                 return false;
6777             }
6778             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
6779                 return false;
6780             }
6781             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6782                 return false;
6783             }
6784             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
6785                 return false;
6786             }
6787             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
6788                 return false;
6789             }
6790             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6791                 return false;
6792             }
6793             p6 = null;
6794             final Phylogeny species7 = factory
6795                     .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,"
6796                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6797                              new NHXParser() )[ 0 ];
6798             final Phylogeny gene7 = factory
6799                     .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],"
6800                                      + "(((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],"
6801                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6802                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6803                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6804                              new NHXParser() )[ 0 ];
6805             species7.setRooted( true );
6806             gene7.setRooted( true );
6807             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
6808             if ( sdi_unrooted.getCount() != 1 ) {
6809                 return false;
6810             }
6811             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6812                 return false;
6813             }
6814             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6815                 return false;
6816             }
6817             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6818                 return false;
6819             }
6820             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
6821                 return false;
6822             }
6823             if ( !p7[ 0 ].getRoot().isDuplication() ) {
6824                 return false;
6825             }
6826             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6827                 return false;
6828             }
6829             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6830                 return false;
6831             }
6832             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
6833                 return false;
6834             }
6835             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6836                 return false;
6837             }
6838             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
6839                 return false;
6840             }
6841             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
6842                 return false;
6843             }
6844             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6845                 return false;
6846             }
6847             p7 = null;
6848             final Phylogeny species8 = factory
6849                     .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,"
6850                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6851                              new NHXParser() )[ 0 ];
6852             final Phylogeny gene8 = factory
6853                     .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],"
6854                                      + "(((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],"
6855                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6856                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6857                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6858                              new NHXParser() )[ 0 ];
6859             species8.setRooted( true );
6860             gene8.setRooted( true );
6861             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
6862             if ( sdi_unrooted.getCount() != 1 ) {
6863                 return false;
6864             }
6865             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6866                 return false;
6867             }
6868             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6869                 return false;
6870             }
6871             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6872                 return false;
6873             }
6874             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6875                 return false;
6876             }
6877             if ( !p8[ 0 ].getRoot().isDuplication() ) {
6878                 return false;
6879             }
6880             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6881                 return false;
6882             }
6883             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6884                 return false;
6885             }
6886             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
6887                 return false;
6888             }
6889             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6890                 return false;
6891             }
6892             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
6893                 return false;
6894             }
6895             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
6896                 return false;
6897             }
6898             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6899                 return false;
6900             }
6901             p8 = null;
6902         }
6903         catch ( final Exception e ) {
6904             e.printStackTrace( System.out );
6905             return false;
6906         }
6907         return true;
6908     }
6909
6910     private static boolean testSplit() {
6911         try {
6912             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6913             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
6914             //Archaeopteryx.createApplication( p0 );
6915             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
6916             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6917             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6918             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6919             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6920             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6921             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6922             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6923             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
6924             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
6925             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
6926             // System.out.println( s0.toString() );
6927             //
6928             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
6929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6931             if ( s0.match( query_nodes ) ) {
6932                 return false;
6933             }
6934             query_nodes = new HashSet<PhylogenyNode>();
6935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6942             if ( !s0.match( query_nodes ) ) {
6943                 return false;
6944             }
6945             //
6946             query_nodes = new HashSet<PhylogenyNode>();
6947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6950             if ( !s0.match( query_nodes ) ) {
6951                 return false;
6952             }
6953             //
6954             query_nodes = new HashSet<PhylogenyNode>();
6955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6959             if ( !s0.match( query_nodes ) ) {
6960                 return false;
6961             }
6962             //
6963             query_nodes = new HashSet<PhylogenyNode>();
6964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6968             if ( !s0.match( query_nodes ) ) {
6969                 return false;
6970             }
6971             //
6972             query_nodes = new HashSet<PhylogenyNode>();
6973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6976             if ( !s0.match( query_nodes ) ) {
6977                 return false;
6978             }
6979             //
6980             query_nodes = new HashSet<PhylogenyNode>();
6981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6983             if ( !s0.match( query_nodes ) ) {
6984                 return false;
6985             }
6986             //
6987             query_nodes = new HashSet<PhylogenyNode>();
6988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6993             if ( !s0.match( query_nodes ) ) {
6994                 return false;
6995             }
6996             //
6997             query_nodes = new HashSet<PhylogenyNode>();
6998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7001             if ( !s0.match( query_nodes ) ) {
7002                 return false;
7003             }
7004             //
7005             query_nodes = new HashSet<PhylogenyNode>();
7006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7010             if ( !s0.match( query_nodes ) ) {
7011                 return false;
7012             }
7013             //
7014             query_nodes = new HashSet<PhylogenyNode>();
7015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7017             if ( s0.match( query_nodes ) ) {
7018                 return false;
7019             }
7020             //
7021             query_nodes = new HashSet<PhylogenyNode>();
7022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7026             if ( s0.match( query_nodes ) ) {
7027                 return false;
7028             }
7029             //
7030             query_nodes = new HashSet<PhylogenyNode>();
7031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7034             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7036             if ( s0.match( query_nodes ) ) {
7037                 return false;
7038             }
7039             //
7040             query_nodes = new HashSet<PhylogenyNode>();
7041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7044             if ( s0.match( query_nodes ) ) {
7045                 return false;
7046             }
7047             //
7048             query_nodes = new HashSet<PhylogenyNode>();
7049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7051             if ( s0.match( query_nodes ) ) {
7052                 return false;
7053             }
7054             //
7055             query_nodes = new HashSet<PhylogenyNode>();
7056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7058             if ( s0.match( query_nodes ) ) {
7059                 return false;
7060             }
7061             //
7062             query_nodes = new HashSet<PhylogenyNode>();
7063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7065             if ( s0.match( query_nodes ) ) {
7066                 return false;
7067             }
7068             //
7069             query_nodes = new HashSet<PhylogenyNode>();
7070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7072             if ( s0.match( query_nodes ) ) {
7073                 return false;
7074             }
7075             //
7076             query_nodes = new HashSet<PhylogenyNode>();
7077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7079             if ( s0.match( query_nodes ) ) {
7080                 return false;
7081             }
7082             //
7083             query_nodes = new HashSet<PhylogenyNode>();
7084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7086             if ( s0.match( query_nodes ) ) {
7087                 return false;
7088             }
7089             //
7090             query_nodes = new HashSet<PhylogenyNode>();
7091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7093             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7094             if ( s0.match( query_nodes ) ) {
7095                 return false;
7096             }
7097             //
7098             query_nodes = new HashSet<PhylogenyNode>();
7099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7101             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7102             if ( s0.match( query_nodes ) ) {
7103                 return false;
7104             }
7105             //
7106             query_nodes = new HashSet<PhylogenyNode>();
7107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7110             if ( s0.match( query_nodes ) ) {
7111                 return false;
7112             }
7113             //
7114             query_nodes = new HashSet<PhylogenyNode>();
7115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7119             if ( s0.match( query_nodes ) ) {
7120                 return false;
7121             }
7122             /////////
7123             //            query_nodes = new HashSet<PhylogenyNode>();
7124             //            query_nodes.add( new PhylogenyNode( "X" ) );
7125             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7126             //            query_nodes.add( new PhylogenyNode( "A" ) );
7127             //            query_nodes.add( new PhylogenyNode( "B" ) );
7128             //            query_nodes.add( new PhylogenyNode( "C" ) );
7129             //            query_nodes.add( new PhylogenyNode( "D" ) );
7130             //            query_nodes.add( new PhylogenyNode( "E" ) );
7131             //            query_nodes.add( new PhylogenyNode( "F" ) );
7132             //            query_nodes.add( new PhylogenyNode( "G" ) );
7133             //            if ( !s0.match( query_nodes ) ) {
7134             //                return false;
7135             //            }
7136             //            query_nodes = new HashSet<PhylogenyNode>();
7137             //            query_nodes.add( new PhylogenyNode( "X" ) );
7138             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7139             //            query_nodes.add( new PhylogenyNode( "A" ) );
7140             //            query_nodes.add( new PhylogenyNode( "B" ) );
7141             //            query_nodes.add( new PhylogenyNode( "C" ) );
7142             //            if ( !s0.match( query_nodes ) ) {
7143             //                return false;
7144             //            }
7145             //            //
7146             //            query_nodes = new HashSet<PhylogenyNode>();
7147             //            query_nodes.add( new PhylogenyNode( "X" ) );
7148             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7149             //            query_nodes.add( new PhylogenyNode( "D" ) );
7150             //            query_nodes.add( new PhylogenyNode( "E" ) );
7151             //            query_nodes.add( new PhylogenyNode( "F" ) );
7152             //            query_nodes.add( new PhylogenyNode( "G" ) );
7153             //            if ( !s0.match( query_nodes ) ) {
7154             //                return false;
7155             //            }
7156             //            //
7157             //            query_nodes = new HashSet<PhylogenyNode>();
7158             //            query_nodes.add( new PhylogenyNode( "X" ) );
7159             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7160             //            query_nodes.add( new PhylogenyNode( "A" ) );
7161             //            query_nodes.add( new PhylogenyNode( "B" ) );
7162             //            query_nodes.add( new PhylogenyNode( "C" ) );
7163             //            query_nodes.add( new PhylogenyNode( "D" ) );
7164             //            if ( !s0.match( query_nodes ) ) {
7165             //                return false;
7166             //            }
7167             //            //
7168             //            query_nodes = new HashSet<PhylogenyNode>();
7169             //            query_nodes.add( new PhylogenyNode( "X" ) );
7170             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7171             //            query_nodes.add( new PhylogenyNode( "E" ) );
7172             //            query_nodes.add( new PhylogenyNode( "F" ) );
7173             //            query_nodes.add( new PhylogenyNode( "G" ) );
7174             //            if ( !s0.match( query_nodes ) ) {
7175             //                return false;
7176             //            }
7177             //            //
7178             //            query_nodes = new HashSet<PhylogenyNode>();
7179             //            query_nodes.add( new PhylogenyNode( "X" ) );
7180             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7181             //            query_nodes.add( new PhylogenyNode( "F" ) );
7182             //            query_nodes.add( new PhylogenyNode( "G" ) );
7183             //            if ( !s0.match( query_nodes ) ) {
7184             //                return false;
7185             //            }
7186             //
7187             query_nodes = new HashSet<PhylogenyNode>();
7188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7190             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7192             if ( s0.match( query_nodes ) ) {
7193                 return false;
7194             }
7195             //
7196             query_nodes = new HashSet<PhylogenyNode>();
7197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7198             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7199             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7200             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7201             if ( s0.match( query_nodes ) ) {
7202                 return false;
7203             }
7204             ///////////////////////////
7205             //
7206             query_nodes = new HashSet<PhylogenyNode>();
7207             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7208             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7211             if ( s0.match( query_nodes ) ) {
7212                 return false;
7213             }
7214             //
7215             query_nodes = new HashSet<PhylogenyNode>();
7216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7220             if ( s0.match( query_nodes ) ) {
7221                 return false;
7222             }
7223             //
7224             query_nodes = new HashSet<PhylogenyNode>();
7225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7229             if ( s0.match( query_nodes ) ) {
7230                 return false;
7231             }
7232             //
7233             query_nodes = new HashSet<PhylogenyNode>();
7234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7235             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7238             if ( s0.match( query_nodes ) ) {
7239                 return false;
7240             }
7241             //
7242             query_nodes = new HashSet<PhylogenyNode>();
7243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7247             if ( s0.match( query_nodes ) ) {
7248                 return false;
7249             }
7250             //
7251             query_nodes = new HashSet<PhylogenyNode>();
7252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7255             if ( s0.match( query_nodes ) ) {
7256                 return false;
7257             }
7258             //
7259             query_nodes = new HashSet<PhylogenyNode>();
7260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7265             if ( s0.match( query_nodes ) ) {
7266                 return false;
7267             }
7268             //
7269             query_nodes = new HashSet<PhylogenyNode>();
7270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7271             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7275             if ( s0.match( query_nodes ) ) {
7276                 return false;
7277             }
7278             //
7279             query_nodes = new HashSet<PhylogenyNode>();
7280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7285             if ( s0.match( query_nodes ) ) {
7286                 return false;
7287             }
7288             //
7289             query_nodes = new HashSet<PhylogenyNode>();
7290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7295             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7296             if ( s0.match( query_nodes ) ) {
7297                 return false;
7298             }
7299         }
7300         catch ( final Exception e ) {
7301             e.printStackTrace();
7302             return false;
7303         }
7304         return true;
7305     }
7306
7307     private static boolean testSplitStrict() {
7308         try {
7309             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7310             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
7311             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
7312             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7313             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7314             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7315             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7316             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7317             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7318             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7319             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
7320             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7323             if ( s0.match( query_nodes ) ) {
7324                 return false;
7325             }
7326             query_nodes = new HashSet<PhylogenyNode>();
7327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7334             if ( !s0.match( query_nodes ) ) {
7335                 return false;
7336             }
7337             //
7338             query_nodes = new HashSet<PhylogenyNode>();
7339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7342             if ( !s0.match( query_nodes ) ) {
7343                 return false;
7344             }
7345             //
7346             query_nodes = new HashSet<PhylogenyNode>();
7347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7351             if ( !s0.match( query_nodes ) ) {
7352                 return false;
7353             }
7354             //
7355             query_nodes = new HashSet<PhylogenyNode>();
7356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7360             if ( !s0.match( query_nodes ) ) {
7361                 return false;
7362             }
7363             //
7364             query_nodes = new HashSet<PhylogenyNode>();
7365             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7368             if ( !s0.match( query_nodes ) ) {
7369                 return false;
7370             }
7371             //
7372             query_nodes = new HashSet<PhylogenyNode>();
7373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7375             if ( !s0.match( query_nodes ) ) {
7376                 return false;
7377             }
7378             //
7379             query_nodes = new HashSet<PhylogenyNode>();
7380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7385             if ( !s0.match( query_nodes ) ) {
7386                 return false;
7387             }
7388             //
7389             query_nodes = new HashSet<PhylogenyNode>();
7390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7393             if ( !s0.match( query_nodes ) ) {
7394                 return false;
7395             }
7396             //
7397             query_nodes = new HashSet<PhylogenyNode>();
7398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7402             if ( !s0.match( query_nodes ) ) {
7403                 return false;
7404             }
7405             //
7406             query_nodes = new HashSet<PhylogenyNode>();
7407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7409             if ( s0.match( query_nodes ) ) {
7410                 return false;
7411             }
7412             //
7413             query_nodes = new HashSet<PhylogenyNode>();
7414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7415             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7416             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7418             if ( s0.match( query_nodes ) ) {
7419                 return false;
7420             }
7421             //
7422             query_nodes = new HashSet<PhylogenyNode>();
7423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7428             if ( s0.match( query_nodes ) ) {
7429                 return false;
7430             }
7431             //
7432             query_nodes = new HashSet<PhylogenyNode>();
7433             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7434             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7436             if ( s0.match( query_nodes ) ) {
7437                 return false;
7438             }
7439             //
7440             query_nodes = new HashSet<PhylogenyNode>();
7441             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7442             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7443             if ( s0.match( query_nodes ) ) {
7444                 return false;
7445             }
7446             //
7447             query_nodes = new HashSet<PhylogenyNode>();
7448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7449             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7450             if ( s0.match( query_nodes ) ) {
7451                 return false;
7452             }
7453             //
7454             query_nodes = new HashSet<PhylogenyNode>();
7455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7457             if ( s0.match( query_nodes ) ) {
7458                 return false;
7459             }
7460             //
7461             query_nodes = new HashSet<PhylogenyNode>();
7462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7464             if ( s0.match( query_nodes ) ) {
7465                 return false;
7466             }
7467             //
7468             query_nodes = new HashSet<PhylogenyNode>();
7469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7471             if ( s0.match( query_nodes ) ) {
7472                 return false;
7473             }
7474             //
7475             query_nodes = new HashSet<PhylogenyNode>();
7476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7478             if ( s0.match( query_nodes ) ) {
7479                 return false;
7480             }
7481             //
7482             query_nodes = new HashSet<PhylogenyNode>();
7483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7486             if ( s0.match( query_nodes ) ) {
7487                 return false;
7488             }
7489             //
7490             query_nodes = new HashSet<PhylogenyNode>();
7491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7494             if ( s0.match( query_nodes ) ) {
7495                 return false;
7496             }
7497             //
7498             query_nodes = new HashSet<PhylogenyNode>();
7499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7502             if ( s0.match( query_nodes ) ) {
7503                 return false;
7504             }
7505             //
7506             query_nodes = new HashSet<PhylogenyNode>();
7507             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7508             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7511             if ( s0.match( query_nodes ) ) {
7512                 return false;
7513             }
7514         }
7515         catch ( final Exception e ) {
7516             e.printStackTrace();
7517             return false;
7518         }
7519         return true;
7520     }
7521
7522     private static boolean testSubtreeDeletion() {
7523         try {
7524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7525             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7526             t1.deleteSubtree( t1.getNode( "A" ), false );
7527             if ( t1.getNumberOfExternalNodes() != 5 ) {
7528                 return false;
7529             }
7530             t1.toNewHampshireX();
7531             t1.deleteSubtree( t1.getNode( "E" ), false );
7532             if ( t1.getNumberOfExternalNodes() != 4 ) {
7533                 return false;
7534             }
7535             t1.toNewHampshireX();
7536             t1.deleteSubtree( t1.getNode( "F" ), false );
7537             if ( t1.getNumberOfExternalNodes() != 3 ) {
7538                 return false;
7539             }
7540             t1.toNewHampshireX();
7541             t1.deleteSubtree( t1.getNode( "D" ), false );
7542             t1.toNewHampshireX();
7543             if ( t1.getNumberOfExternalNodes() != 3 ) {
7544                 return false;
7545             }
7546             t1.deleteSubtree( t1.getNode( "def" ), false );
7547             t1.toNewHampshireX();
7548             if ( t1.getNumberOfExternalNodes() != 2 ) {
7549                 return false;
7550             }
7551             t1.deleteSubtree( t1.getNode( "B" ), false );
7552             t1.toNewHampshireX();
7553             if ( t1.getNumberOfExternalNodes() != 1 ) {
7554                 return false;
7555             }
7556             t1.deleteSubtree( t1.getNode( "C" ), false );
7557             t1.toNewHampshireX();
7558             if ( t1.getNumberOfExternalNodes() != 1 ) {
7559                 return false;
7560             }
7561             t1.deleteSubtree( t1.getNode( "abc" ), false );
7562             t1.toNewHampshireX();
7563             if ( t1.getNumberOfExternalNodes() != 1 ) {
7564                 return false;
7565             }
7566             t1.deleteSubtree( t1.getNode( "r" ), false );
7567             if ( t1.getNumberOfExternalNodes() != 0 ) {
7568                 return false;
7569             }
7570             if ( !t1.isEmpty() ) {
7571                 return false;
7572             }
7573             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7574             t2.deleteSubtree( t2.getNode( "A" ), false );
7575             t2.toNewHampshireX();
7576             if ( t2.getNumberOfExternalNodes() != 5 ) {
7577                 return false;
7578             }
7579             t2.deleteSubtree( t2.getNode( "abc" ), false );
7580             t2.toNewHampshireX();
7581             if ( t2.getNumberOfExternalNodes() != 3 ) {
7582                 return false;
7583             }
7584             t2.deleteSubtree( t2.getNode( "def" ), false );
7585             t2.toNewHampshireX();
7586             if ( t2.getNumberOfExternalNodes() != 1 ) {
7587                 return false;
7588             }
7589         }
7590         catch ( final Exception e ) {
7591             e.printStackTrace( System.out );
7592             return false;
7593         }
7594         return true;
7595     }
7596
7597     private static boolean testSupportCount() {
7598         try {
7599             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7600             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
7601             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
7602                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
7603                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
7604                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
7605                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
7606                                                               new NHXParser() );
7607             SupportCount.count( t0_1, phylogenies_1, true, false );
7608             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
7609             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
7610                                                                       + "(((((A,B),C),D),E),((F,G),X))"
7611                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
7612                                                                       + "(((((A,B),C),D),E),(F,G))"
7613                                                                       + "(((((A,B),C),D),E),(F,G))"
7614                                                                       + "(((((A,B),C),D),E),(F,G))"
7615                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
7616                                                                       + "(((((A,B),C),D),E),(F,G))"
7617                                                                       + "((((((A,B),C),D),E),F),G)"
7618                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
7619                                                               new NHXParser() );
7620             SupportCount.count( t0_2, phylogenies_2, true, false );
7621             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
7622             while ( it.hasNext() ) {
7623                 final PhylogenyNode n = it.next();
7624                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
7625                     return false;
7626                 }
7627             }
7628             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
7629             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
7630                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
7631             SupportCount.count( t0_3, phylogenies_3, true, false );
7632             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
7633             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
7634                 return false;
7635             }
7636             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
7637                 return false;
7638             }
7639             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
7640                 return false;
7641             }
7642             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
7643                 return false;
7644             }
7645             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
7646                 return false;
7647             }
7648             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
7649                 return false;
7650             }
7651             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
7652                 return false;
7653             }
7654             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
7655                 return false;
7656             }
7657             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
7658                 return false;
7659             }
7660             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
7661                 return false;
7662             }
7663             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7664             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
7665                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
7666             SupportCount.count( t0_4, phylogenies_4, true, false );
7667             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
7668             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
7669                 return false;
7670             }
7671             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
7672                 return false;
7673             }
7674             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
7675                 return false;
7676             }
7677             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
7678                 return false;
7679             }
7680             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
7681                 return false;
7682             }
7683             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
7684                 return false;
7685             }
7686             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
7687                 return false;
7688             }
7689             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
7690                 return false;
7691             }
7692             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
7693                 return false;
7694             }
7695             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
7696                 return false;
7697             }
7698             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7699             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7700             double d = SupportCount.compare( b1, a, true, true, true );
7701             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
7702                 return false;
7703             }
7704             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7705             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7706             d = SupportCount.compare( b2, a, true, true, true );
7707             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
7708                 return false;
7709             }
7710             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7711             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
7712             d = SupportCount.compare( b3, a, true, true, true );
7713             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
7714                 return false;
7715             }
7716             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
7717             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
7718             d = SupportCount.compare( b4, a, true, true, false );
7719             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
7720                 return false;
7721             }
7722         }
7723         catch ( final Exception e ) {
7724             e.printStackTrace( System.out );
7725             return false;
7726         }
7727         return true;
7728     }
7729
7730     private static boolean testSupportTransfer() {
7731         try {
7732             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7733             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)",
7734                                                  new NHXParser() )[ 0 ];
7735             final Phylogeny p2 = factory
7736                     .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 ];
7737             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
7738                 return false;
7739             }
7740             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
7741                 return false;
7742             }
7743             support_transfer.moveBranchLengthsToBootstrap( p1 );
7744             support_transfer.transferSupportValues( p1, p2 );
7745             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
7746                 return false;
7747             }
7748             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
7749                 return false;
7750             }
7751             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
7752                 return false;
7753             }
7754             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
7755                 return false;
7756             }
7757             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
7758                 return false;
7759             }
7760             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
7761                 return false;
7762             }
7763             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
7764                 return false;
7765             }
7766             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
7767                 return false;
7768             }
7769         }
7770         catch ( final Exception e ) {
7771             e.printStackTrace( System.out );
7772             return false;
7773         }
7774         return true;
7775     }
7776
7777     private static boolean testUniprotTaxonomySearch() {
7778         try {
7779             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
7780                                                                                                  10 );
7781             if ( results.size() != 1 ) {
7782                 return false;
7783             }
7784             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7785                 return false;
7786             }
7787             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7788                 return false;
7789             }
7790             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7791                 return false;
7792             }
7793             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7794                 return false;
7795             }
7796             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7797                 return false;
7798             }
7799             results = null;
7800             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
7801             if ( results.size() != 1 ) {
7802                 return false;
7803             }
7804             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7805                 return false;
7806             }
7807             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7808                 return false;
7809             }
7810             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7811                 return false;
7812             }
7813             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7814                 return false;
7815             }
7816             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7817                 return false;
7818             }
7819             results = null;
7820             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
7821             if ( results.size() != 1 ) {
7822                 return false;
7823             }
7824             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7825                 return false;
7826             }
7827             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7828                 return false;
7829             }
7830             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7831                 return false;
7832             }
7833             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7834                 return false;
7835             }
7836             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7837                 return false;
7838             }
7839             results = null;
7840             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
7841             if ( results.size() != 1 ) {
7842                 return false;
7843             }
7844             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7845                 return false;
7846             }
7847             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7848                 return false;
7849             }
7850             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7851                 return false;
7852             }
7853             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7854                 return false;
7855             }
7856             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7857                 return false;
7858             }
7859             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
7860                 return false;
7861             }
7862             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
7863                 return false;
7864             }
7865             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
7866                     .equals( "Nematostella vectensis" ) ) {
7867                 System.out.println( results.get( 0 ).getLineage() );
7868                 return false;
7869             }
7870         }
7871         catch ( final IOException e ) {
7872             System.out.println();
7873             System.out.println( "the following might be due to absence internet connection:" );
7874             e.printStackTrace( System.out );
7875             return true;
7876         }
7877         catch ( final Exception e ) {
7878             return false;
7879         }
7880         return true;
7881     }
7882
7883     private static boolean testEmblEntryRetrieval() {
7884         //The format for GenBank Accession numbers are:
7885         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
7886         //Protein:    3 letters + 5 numerals
7887         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
7888         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
7889             return false;
7890         }
7891         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
7892             return false;
7893         }
7894         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
7895             return false;
7896         }
7897         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
7898             return false;
7899         }
7900         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
7901             return false;
7902         }
7903         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
7904             return false;
7905         }
7906         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
7907             return false;
7908         }
7909         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
7910             return false;
7911         }
7912         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
7913             return false;
7914         }
7915         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
7916             return false;
7917         }
7918         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
7919             return false;
7920         }
7921         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
7922             return false;
7923         }
7924         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
7925             return false;
7926         }
7927         return true;
7928     }
7929
7930     private static boolean testUniprotEntryRetrieval() {
7931         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
7932             return false;
7933         }
7934         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
7935             return false;
7936         }
7937         if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
7938             return false;
7939         }
7940         if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
7941             return false;
7942         }
7943         if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
7944             return false;
7945         }
7946         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
7947             return false;
7948         }
7949         if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
7950             return false;
7951         }
7952         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
7953             return false;
7954         }
7955         if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
7956             return false;
7957         }
7958         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
7959             return false;
7960         }
7961         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
7962             return false;
7963         }
7964         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
7965             return false;
7966         }
7967         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
7968             return false;
7969         }
7970         try {
7971             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
7972             if ( !entry.getAccession().equals( "P12345" ) ) {
7973                 return false;
7974             }
7975             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
7976                 return false;
7977             }
7978             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
7979                 return false;
7980             }
7981             if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
7982                 return false;
7983             }
7984             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
7985                 return false;
7986             }
7987         }
7988         catch ( final IOException e ) {
7989             System.out.println();
7990             System.out.println( "the following might be due to absence internet connection:" );
7991             e.printStackTrace( System.out );
7992             return true;
7993         }
7994         catch ( final Exception e ) {
7995             return false;
7996         }
7997         return true;
7998     }
7999
8000     private static boolean testWabiTxSearch() {
8001         try {
8002             String result = "";
8003             result = TxSearch.searchSimple( "nematostella" );
8004             result = TxSearch.getTxId( "nematostella" );
8005             if ( !result.equals( "45350" ) ) {
8006                 return false;
8007             }
8008             result = TxSearch.getTxName( "45350" );
8009             if ( !result.equals( "Nematostella" ) ) {
8010                 return false;
8011             }
8012             result = TxSearch.getTxId( "nematostella vectensis" );
8013             if ( !result.equals( "45351" ) ) {
8014                 return false;
8015             }
8016             result = TxSearch.getTxName( "45351" );
8017             if ( !result.equals( "Nematostella vectensis" ) ) {
8018                 return false;
8019             }
8020             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
8021             if ( !result.equals( "536089" ) ) {
8022                 return false;
8023             }
8024             result = TxSearch.getTxName( "536089" );
8025             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
8026                 return false;
8027             }
8028             final List<String> queries = new ArrayList<String>();
8029             queries.add( "Campylobacter coli" );
8030             queries.add( "Escherichia coli" );
8031             queries.add( "Arabidopsis" );
8032             queries.add( "Trichoplax" );
8033             queries.add( "Samanea saman" );
8034             queries.add( "Kluyveromyces marxianus" );
8035             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
8036             queries.add( "Bornavirus parrot/PDD/2008" );
8037             final List<RANKS> ranks = new ArrayList<RANKS>();
8038             ranks.add( RANKS.SUPERKINGDOM );
8039             ranks.add( RANKS.KINGDOM );
8040             ranks.add( RANKS.FAMILY );
8041             ranks.add( RANKS.GENUS );
8042             ranks.add( RANKS.TRIBE );
8043             result = TxSearch.searchLineage( queries, ranks );
8044             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
8045             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
8046         }
8047         catch ( final Exception e ) {
8048             System.out.println();
8049             System.out.println( "the following might be due to absence internet connection:" );
8050             e.printStackTrace( System.out );
8051             return false;
8052         }
8053         return true;
8054     }
8055
8056     private static boolean testAminoAcidSequence() {
8057         try {
8058             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
8059             if ( aa1.getLength() != 13 ) {
8060                 return false;
8061             }
8062             if ( aa1.getResidueAt( 0 ) != 'A' ) {
8063                 return false;
8064             }
8065             if ( aa1.getResidueAt( 2 ) != 'K' ) {
8066                 return false;
8067             }
8068             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
8069                 return false;
8070             }
8071             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
8072             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
8073                 return false;
8074             }
8075             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
8076             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
8077                 return false;
8078             }
8079             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
8080             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
8081                 return false;
8082             }
8083         }
8084         catch ( final Exception e ) {
8085             e.printStackTrace();
8086             return false;
8087         }
8088         return true;
8089     }
8090
8091     private static boolean testCreateBalancedPhylogeny() {
8092         try {
8093             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
8094             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
8095                 return false;
8096             }
8097             if ( p0.getNumberOfExternalNodes() != 15625 ) {
8098                 return false;
8099             }
8100             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
8101             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
8102                 return false;
8103             }
8104             if ( p1.getNumberOfExternalNodes() != 100 ) {
8105                 return false;
8106             }
8107         }
8108         catch ( final Exception e ) {
8109             e.printStackTrace();
8110             return false;
8111         }
8112         return true;
8113     }
8114
8115     private static boolean testFastaParser() {
8116         try {
8117             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
8118                 return false;
8119             }
8120             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
8121                 return false;
8122             }
8123             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
8124             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
8125                 return false;
8126             }
8127             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
8128                 return false;
8129             }
8130             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
8131                 return false;
8132             }
8133             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
8134                 return false;
8135             }
8136             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
8137                 return false;
8138             }
8139             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
8140                 return false;
8141             }
8142         }
8143         catch ( final Exception e ) {
8144             e.printStackTrace();
8145             return false;
8146         }
8147         return true;
8148     }
8149
8150     private static boolean testGeneralMsaParser() {
8151         try {
8152             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
8153             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
8154             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
8155             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
8156             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
8157             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
8158             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
8159             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
8160             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8161                 return false;
8162             }
8163             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8164                 return false;
8165             }
8166             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8167                 return false;
8168             }
8169             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8170                 return false;
8171             }
8172             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8173                 return false;
8174             }
8175             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8176                 return false;
8177             }
8178             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8179                 return false;
8180             }
8181             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8182                 return false;
8183             }
8184             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8185                 return false;
8186             }
8187             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8188                 return false;
8189             }
8190             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8191                 return false;
8192             }
8193             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8194                 return false;
8195             }
8196             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
8197             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8198                 return false;
8199             }
8200             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8201                 return false;
8202             }
8203             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8204                 return false;
8205             }
8206             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
8207             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
8208                 return false;
8209             }
8210             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
8211                 return false;
8212             }
8213             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
8214                 return false;
8215             }
8216             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
8217             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8218                 return false;
8219             }
8220             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8221                 return false;
8222             }
8223             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8224                 return false;
8225             }
8226         }
8227         catch ( final Exception e ) {
8228             e.printStackTrace();
8229             return false;
8230         }
8231         return true;
8232     }
8233
8234     private static boolean testMafft( final String path ) {
8235         try {
8236             final List<String> opts = new ArrayList<String>();
8237             opts.add( "--maxiterate" );
8238             opts.add( "1000" );
8239             opts.add( "--localpair" );
8240             opts.add( "--quiet" );
8241             Msa msa = null;
8242             final MsaInferrer mafft = Mafft.createInstance( path );
8243             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
8244             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
8245                 return false;
8246             }
8247             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
8248                 return false;
8249             }
8250         }
8251         catch ( final Exception e ) {
8252             e.printStackTrace( System.out );
8253             return false;
8254         }
8255         return true;
8256     }
8257
8258     private static boolean testNextNodeWithCollapsing() {
8259         try {
8260             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8261             PhylogenyNode n;
8262             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
8263             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8264             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
8265             t0.getNode( "cd" ).setCollapse( true );
8266             t0.getNode( "cde" ).setCollapse( true );
8267             n = t0.getFirstExternalNode();
8268             while ( n != null ) {
8269                 ext.add( n );
8270                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8271             }
8272             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8273                 return false;
8274             }
8275             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8276                 return false;
8277             }
8278             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
8279                 return false;
8280             }
8281             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
8282                 return false;
8283             }
8284             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
8285                 return false;
8286             }
8287             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
8288                 return false;
8289             }
8290             ext.clear();
8291             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8292             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
8293             t1.getNode( "ab" ).setCollapse( true );
8294             t1.getNode( "cd" ).setCollapse( true );
8295             t1.getNode( "cde" ).setCollapse( true );
8296             n = t1.getNode( "ab" );
8297             ext = new ArrayList<PhylogenyNode>();
8298             while ( n != null ) {
8299                 ext.add( n );
8300                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8301             }
8302             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8303                 return false;
8304             }
8305             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8306                 return false;
8307             }
8308             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8309                 return false;
8310             }
8311             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
8312                 return false;
8313             }
8314             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
8315                 return false;
8316             }
8317             //
8318             //
8319             ext.clear();
8320             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8321             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
8322             t2.getNode( "ab" ).setCollapse( true );
8323             t2.getNode( "cd" ).setCollapse( true );
8324             t2.getNode( "cde" ).setCollapse( true );
8325             t2.getNode( "c" ).setCollapse( true );
8326             t2.getNode( "d" ).setCollapse( true );
8327             t2.getNode( "e" ).setCollapse( true );
8328             t2.getNode( "gh" ).setCollapse( true );
8329             n = t2.getNode( "ab" );
8330             ext = new ArrayList<PhylogenyNode>();
8331             while ( n != null ) {
8332                 ext.add( n );
8333                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8334             }
8335             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8336                 return false;
8337             }
8338             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8339                 return false;
8340             }
8341             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8342                 return false;
8343             }
8344             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
8345                 return false;
8346             }
8347             //
8348             //
8349             ext.clear();
8350             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8351             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
8352             t3.getNode( "ab" ).setCollapse( true );
8353             t3.getNode( "cd" ).setCollapse( true );
8354             t3.getNode( "cde" ).setCollapse( true );
8355             t3.getNode( "c" ).setCollapse( true );
8356             t3.getNode( "d" ).setCollapse( true );
8357             t3.getNode( "e" ).setCollapse( true );
8358             t3.getNode( "gh" ).setCollapse( true );
8359             t3.getNode( "fgh" ).setCollapse( true );
8360             n = t3.getNode( "ab" );
8361             ext = new ArrayList<PhylogenyNode>();
8362             while ( n != null ) {
8363                 ext.add( n );
8364                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8365             }
8366             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8367                 return false;
8368             }
8369             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8370                 return false;
8371             }
8372             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
8373                 return false;
8374             }
8375             //
8376             //
8377             ext.clear();
8378             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8379             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
8380             t4.getNode( "ab" ).setCollapse( true );
8381             t4.getNode( "cd" ).setCollapse( true );
8382             t4.getNode( "cde" ).setCollapse( true );
8383             t4.getNode( "c" ).setCollapse( true );
8384             t4.getNode( "d" ).setCollapse( true );
8385             t4.getNode( "e" ).setCollapse( true );
8386             t4.getNode( "gh" ).setCollapse( true );
8387             t4.getNode( "fgh" ).setCollapse( true );
8388             t4.getNode( "abcdefgh" ).setCollapse( true );
8389             n = t4.getNode( "abcdefgh" );
8390             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
8391                 return false;
8392             }
8393             //
8394             //
8395             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8396             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
8397             ext.clear();
8398             n = t5.getFirstExternalNode();
8399             while ( n != null ) {
8400                 ext.add( n );
8401                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8402             }
8403             if ( ext.size() != 8 ) {
8404                 return false;
8405             }
8406             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8407                 return false;
8408             }
8409             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8410                 return false;
8411             }
8412             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8413                 return false;
8414             }
8415             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8416                 return false;
8417             }
8418             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8419                 return false;
8420             }
8421             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8422                 return false;
8423             }
8424             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
8425                 return false;
8426             }
8427             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
8428                 return false;
8429             }
8430             //
8431             //
8432             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8433             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
8434             ext.clear();
8435             t6.getNode( "ab" ).setCollapse( true );
8436             n = t6.getNode( "ab" );
8437             while ( n != null ) {
8438                 ext.add( n );
8439                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8440             }
8441             if ( ext.size() != 7 ) {
8442                 return false;
8443             }
8444             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8445                 return false;
8446             }
8447             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8448                 return false;
8449             }
8450             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8451                 return false;
8452             }
8453             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8454                 return false;
8455             }
8456             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8457                 return false;
8458             }
8459             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8460                 return false;
8461             }
8462             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8463                 return false;
8464             }
8465             //
8466             //
8467             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8468             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
8469             ext.clear();
8470             t7.getNode( "cd" ).setCollapse( true );
8471             n = t7.getNode( "a" );
8472             while ( n != null ) {
8473                 ext.add( n );
8474                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8475             }
8476             if ( ext.size() != 7 ) {
8477                 return false;
8478             }
8479             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8480                 return false;
8481             }
8482             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8483                 return false;
8484             }
8485             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8486                 return false;
8487             }
8488             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8489                 return false;
8490             }
8491             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8492                 return false;
8493             }
8494             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8495                 return false;
8496             }
8497             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8498                 return false;
8499             }
8500             //
8501             //
8502             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8503             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
8504             ext.clear();
8505             t8.getNode( "cd" ).setCollapse( true );
8506             t8.getNode( "c" ).setCollapse( true );
8507             t8.getNode( "d" ).setCollapse( true );
8508             n = t8.getNode( "a" );
8509             while ( n != null ) {
8510                 ext.add( n );
8511                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8512             }
8513             if ( ext.size() != 7 ) {
8514                 return false;
8515             }
8516             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8517                 return false;
8518             }
8519             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8520                 return false;
8521             }
8522             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8523                 System.out.println( "2 fail" );
8524                 return false;
8525             }
8526             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8527                 return false;
8528             }
8529             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8530                 return false;
8531             }
8532             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8533                 return false;
8534             }
8535             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8536                 return false;
8537             }
8538             //
8539             //
8540             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8541             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
8542             ext.clear();
8543             t9.getNode( "gh" ).setCollapse( true );
8544             n = t9.getNode( "a" );
8545             while ( n != null ) {
8546                 ext.add( n );
8547                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8548             }
8549             if ( ext.size() != 7 ) {
8550                 return false;
8551             }
8552             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8553                 return false;
8554             }
8555             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8556                 return false;
8557             }
8558             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8559                 return false;
8560             }
8561             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8562                 return false;
8563             }
8564             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8565                 return false;
8566             }
8567             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8568                 return false;
8569             }
8570             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8571                 return false;
8572             }
8573             //
8574             //
8575             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8576             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
8577             ext.clear();
8578             t10.getNode( "gh" ).setCollapse( true );
8579             t10.getNode( "g" ).setCollapse( true );
8580             t10.getNode( "h" ).setCollapse( true );
8581             n = t10.getNode( "a" );
8582             while ( n != null ) {
8583                 ext.add( n );
8584                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8585             }
8586             if ( ext.size() != 7 ) {
8587                 return false;
8588             }
8589             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8590                 return false;
8591             }
8592             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8593                 return false;
8594             }
8595             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8596                 return false;
8597             }
8598             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8599                 return false;
8600             }
8601             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8602                 return false;
8603             }
8604             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8605                 return false;
8606             }
8607             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8608                 return false;
8609             }
8610             //
8611             //
8612             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8613             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
8614             ext.clear();
8615             t11.getNode( "gh" ).setCollapse( true );
8616             t11.getNode( "fgh" ).setCollapse( true );
8617             n = t11.getNode( "a" );
8618             while ( n != null ) {
8619                 ext.add( n );
8620                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8621             }
8622             if ( ext.size() != 6 ) {
8623                 return false;
8624             }
8625             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8626                 return false;
8627             }
8628             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8629                 return false;
8630             }
8631             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8632                 return false;
8633             }
8634             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8635                 return false;
8636             }
8637             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8638                 return false;
8639             }
8640             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8641                 return false;
8642             }
8643             //
8644             //
8645             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8646             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
8647             ext.clear();
8648             t12.getNode( "gh" ).setCollapse( true );
8649             t12.getNode( "fgh" ).setCollapse( true );
8650             t12.getNode( "g" ).setCollapse( true );
8651             t12.getNode( "h" ).setCollapse( true );
8652             t12.getNode( "f" ).setCollapse( true );
8653             n = t12.getNode( "a" );
8654             while ( n != null ) {
8655                 ext.add( n );
8656                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8657             }
8658             if ( ext.size() != 6 ) {
8659                 return false;
8660             }
8661             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8662                 return false;
8663             }
8664             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8665                 return false;
8666             }
8667             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8668                 return false;
8669             }
8670             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8671                 return false;
8672             }
8673             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8674                 return false;
8675             }
8676             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8677                 return false;
8678             }
8679             //
8680             //
8681             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8682             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
8683             ext.clear();
8684             t13.getNode( "ab" ).setCollapse( true );
8685             t13.getNode( "b" ).setCollapse( true );
8686             t13.getNode( "fgh" ).setCollapse( true );
8687             t13.getNode( "gh" ).setCollapse( true );
8688             n = t13.getNode( "ab" );
8689             while ( n != null ) {
8690                 ext.add( n );
8691                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8692             }
8693             if ( ext.size() != 5 ) {
8694                 return false;
8695             }
8696             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8697                 return false;
8698             }
8699             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8700                 return false;
8701             }
8702             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8703                 return false;
8704             }
8705             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8706                 return false;
8707             }
8708             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8709                 return false;
8710             }
8711             //
8712             //
8713             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8714             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
8715             ext.clear();
8716             t14.getNode( "ab" ).setCollapse( true );
8717             t14.getNode( "a" ).setCollapse( true );
8718             t14.getNode( "fgh" ).setCollapse( true );
8719             t14.getNode( "gh" ).setCollapse( true );
8720             n = t14.getNode( "ab" );
8721             while ( n != null ) {
8722                 ext.add( n );
8723                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8724             }
8725             if ( ext.size() != 5 ) {
8726                 return false;
8727             }
8728             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8729                 return false;
8730             }
8731             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8732                 return false;
8733             }
8734             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8735                 return false;
8736             }
8737             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8738                 return false;
8739             }
8740             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8741                 return false;
8742             }
8743             //
8744             //
8745             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" );
8746             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
8747             ext.clear();
8748             t15.getNode( "ab" ).setCollapse( true );
8749             t15.getNode( "a" ).setCollapse( true );
8750             t15.getNode( "fgh" ).setCollapse( true );
8751             t15.getNode( "gh" ).setCollapse( true );
8752             n = t15.getNode( "ab" );
8753             while ( n != null ) {
8754                 ext.add( n );
8755                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8756             }
8757             if ( ext.size() != 6 ) {
8758                 return false;
8759             }
8760             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8761                 return false;
8762             }
8763             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8764                 return false;
8765             }
8766             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8767                 return false;
8768             }
8769             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8770                 return false;
8771             }
8772             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
8773                 return false;
8774             }
8775             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8776                 return false;
8777             }
8778             //
8779             //
8780             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" );
8781             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
8782             ext.clear();
8783             t16.getNode( "ab" ).setCollapse( true );
8784             t16.getNode( "a" ).setCollapse( true );
8785             t16.getNode( "fgh" ).setCollapse( true );
8786             t16.getNode( "gh" ).setCollapse( true );
8787             t16.getNode( "cd" ).setCollapse( true );
8788             t16.getNode( "cde" ).setCollapse( true );
8789             t16.getNode( "d" ).setCollapse( true );
8790             t16.getNode( "x" ).setCollapse( true );
8791             n = t16.getNode( "ab" );
8792             while ( n != null ) {
8793                 ext.add( n );
8794                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8795             }
8796             if ( ext.size() != 4 ) {
8797                 return false;
8798             }
8799             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8800                 return false;
8801             }
8802             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8803                 return false;
8804             }
8805             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
8806                 return false;
8807             }
8808             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
8809                 return false;
8810             }
8811         }
8812         catch ( final Exception e ) {
8813             e.printStackTrace( System.out );
8814             return false;
8815         }
8816         return true;
8817     }
8818
8819     private static boolean testMsaQualityMethod() {
8820         try {
8821             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
8822             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
8823             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
8824             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
8825             final List<Sequence> l = new ArrayList<Sequence>();
8826             l.add( s0 );
8827             l.add( s1 );
8828             l.add( s2 );
8829             l.add( s3 );
8830             final Msa msa = BasicMsa.createInstance( l );
8831             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
8832                 return false;
8833             }
8834             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
8835                 return false;
8836             }
8837             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
8838                 return false;
8839             }
8840             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
8841                 return false;
8842             }
8843         }
8844         catch ( final Exception e ) {
8845             e.printStackTrace( System.out );
8846             return false;
8847         }
8848         return true;
8849     }
8850
8851     private static boolean testSequenceIdParsing() {
8852         try {
8853             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
8854             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8855                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8856                 if ( id != null ) {
8857                     System.out.println( "value   =" + id.getValue() );
8858                     System.out.println( "provider=" + id.getProvider() );
8859                 }
8860                 return false;
8861             }
8862             //
8863             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
8864             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8865                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8866                 if ( id != null ) {
8867                     System.out.println( "value   =" + id.getValue() );
8868                     System.out.println( "provider=" + id.getProvider() );
8869                 }
8870                 return false;
8871             }
8872             //
8873             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
8874             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8875                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8876                 if ( id != null ) {
8877                     System.out.println( "value   =" + id.getValue() );
8878                     System.out.println( "provider=" + id.getProvider() );
8879                 }
8880                 return false;
8881             }
8882             // 
8883             id = SequenceIdParser.parse( "gb_AAA96518_1" );
8884             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8885                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
8886                 if ( id != null ) {
8887                     System.out.println( "value   =" + id.getValue() );
8888                     System.out.println( "provider=" + id.getProvider() );
8889                 }
8890                 return false;
8891             }
8892             // 
8893             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
8894             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8895                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
8896                 if ( id != null ) {
8897                     System.out.println( "value   =" + id.getValue() );
8898                     System.out.println( "provider=" + id.getProvider() );
8899                 }
8900                 return false;
8901             }
8902             // 
8903             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
8904             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8905                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
8906                 if ( id != null ) {
8907                     System.out.println( "value   =" + id.getValue() );
8908                     System.out.println( "provider=" + id.getProvider() );
8909                 }
8910                 return false;
8911             }
8912             // 
8913             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
8914             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8915                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
8916                 if ( id != null ) {
8917                     System.out.println( "value   =" + id.getValue() );
8918                     System.out.println( "provider=" + id.getProvider() );
8919                 }
8920                 return false;
8921             }
8922             // 
8923             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
8924             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8925                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8926                 if ( id != null ) {
8927                     System.out.println( "value   =" + id.getValue() );
8928                     System.out.println( "provider=" + id.getProvider() );
8929                 }
8930                 return false;
8931             }
8932             // 
8933             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
8934             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8935                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8936                 if ( id != null ) {
8937                     System.out.println( "value   =" + id.getValue() );
8938                     System.out.println( "provider=" + id.getProvider() );
8939                 }
8940                 return false;
8941             }
8942             // 
8943             id = SequenceIdParser.parse( "P4A123" );
8944             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8945                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8946                 if ( id != null ) {
8947                     System.out.println( "value   =" + id.getValue() );
8948                     System.out.println( "provider=" + id.getProvider() );
8949                 }
8950                 return false;
8951             }
8952             // 
8953             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
8954             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8955                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8956                 if ( id != null ) {
8957                     System.out.println( "value   =" + id.getValue() );
8958                     System.out.println( "provider=" + id.getProvider() );
8959                 }
8960                 return false;
8961             }
8962             // 
8963             id = SequenceIdParser.parse( "XP_12345" );
8964             if ( id != null ) {
8965                 System.out.println( "value   =" + id.getValue() );
8966                 System.out.println( "provider=" + id.getProvider() );
8967                 return false;
8968             }
8969             // lcl_91970_unknown_
8970         }
8971         catch ( final Exception e ) {
8972             e.printStackTrace( System.out );
8973             return false;
8974         }
8975         return true;
8976     }
8977 }