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