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