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