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