inprogress
[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 import java.util.SortedSet;
40 import java.util.TreeSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.Mafft;
65 import org.forester.msa.Msa;
66 import org.forester.msa.MsaInferrer;
67 import org.forester.msa.MsaMethods;
68 import org.forester.pccx.TestPccx;
69 import org.forester.phylogeny.Phylogeny;
70 import org.forester.phylogeny.PhylogenyBranch;
71 import org.forester.phylogeny.PhylogenyMethods;
72 import org.forester.phylogeny.PhylogenyNode;
73 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
74 import org.forester.phylogeny.data.Accession;
75 import org.forester.phylogeny.data.Accession.Source;
76 import org.forester.phylogeny.data.BinaryCharacters;
77 import org.forester.phylogeny.data.BranchWidth;
78 import org.forester.phylogeny.data.Confidence;
79 import org.forester.phylogeny.data.Distribution;
80 import org.forester.phylogeny.data.DomainArchitecture;
81 import org.forester.phylogeny.data.Event;
82 import org.forester.phylogeny.data.Identifier;
83 import org.forester.phylogeny.data.PhylogenyData;
84 import org.forester.phylogeny.data.PhylogenyDataUtil;
85 import org.forester.phylogeny.data.Polygon;
86 import org.forester.phylogeny.data.PropertiesMap;
87 import org.forester.phylogeny.data.Property;
88 import org.forester.phylogeny.data.Property.AppliesTo;
89 import org.forester.phylogeny.data.ProteinDomain;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.protein.BasicDomain;
95 import org.forester.protein.BasicProtein;
96 import org.forester.protein.Domain;
97 import org.forester.protein.Protein;
98 import org.forester.protein.ProteinId;
99 import org.forester.rio.TestRIO;
100 import org.forester.sdi.SDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sdi.TestGSDI;
103 import org.forester.sequence.BasicSequence;
104 import org.forester.sequence.Sequence;
105 import org.forester.species.BasicSpecies;
106 import org.forester.species.Species;
107 import org.forester.surfacing.TestSurfacing;
108 import org.forester.tools.ConfidenceAssessor;
109 import org.forester.tools.SupportCount;
110 import org.forester.tools.TreeSplitMatrix;
111 import org.forester.util.AsciiHistogram;
112 import org.forester.util.BasicDescriptiveStatistics;
113 import org.forester.util.BasicTable;
114 import org.forester.util.BasicTableParser;
115 import org.forester.util.DescriptiveStatistics;
116 import org.forester.util.ForesterConstants;
117 import org.forester.util.ForesterUtil;
118 import org.forester.util.GeneralTable;
119 import org.forester.util.SequenceAccessionTools;
120 import org.forester.ws.seqdb.SequenceDatabaseEntry;
121 import org.forester.ws.seqdb.SequenceDbWsTools;
122 import org.forester.ws.seqdb.UniProtTaxonomy;
123 import org.forester.ws.wabi.TxSearch;
124 import org.forester.ws.wabi.TxSearch.RANKS;
125 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
126 import org.forester.ws.wabi.TxSearch.TAX_RANK;
127
128 @SuppressWarnings( "unused")
129 public final class Test {
130
131     private final static double  ZERO_DIFF                 = 1.0E-9;
132     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "test_data"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
139     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
140                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_XSD;
142     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
143                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_XSD;
145
146     public static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Basic node methods: " );
178         if ( Test.testBasicNodeMethods() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Protein id: " );
187         if ( !testProteinId() ) {
188             System.out.println( "failed." );
189             failed++;
190         }
191         else {
192             succeeded++;
193         }
194         System.out.println( "OK." );
195         System.out.print( "Species: " );
196         if ( !testSpecies() ) {
197             System.out.println( "failed." );
198             failed++;
199         }
200         else {
201             succeeded++;
202         }
203         System.out.println( "OK." );
204         System.out.print( "Basic domain: " );
205         if ( !testBasicDomain() ) {
206             System.out.println( "failed." );
207             failed++;
208         }
209         else {
210             succeeded++;
211         }
212         System.out.println( "OK." );
213         System.out.print( "Basic protein: " );
214         if ( !testBasicProtein() ) {
215             System.out.println( "failed." );
216             failed++;
217         }
218         else {
219             succeeded++;
220         }
221         System.out.println( "OK." );
222         System.out.print( "Sequence writer: " );
223         if ( testSequenceWriter() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "Sequence id parsing: " );
232         if ( testSequenceIdParsing() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         System.out.print( "UniProtKB id extraction: " );
241         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
242             System.out.println( "OK." );
243             succeeded++;
244         }
245         else {
246             System.out.println( "failed." );
247             failed++;
248         }
249         System.out.print( "Sequence DB tools 1: " );
250         if ( testSequenceDbWsTools1() ) {
251             System.out.println( "OK." );
252             succeeded++;
253         }
254         else {
255             System.out.println( "failed." );
256             failed++;
257         }
258         System.out.print( "Sequence DB tools 2: " );
259         if ( testSequenceDbWsTools2() ) {
260             System.out.println( "OK." );
261             succeeded++;
262         }
263         else {
264             System.out.println( "failed." );
265             failed++;
266             System.exit( -1 );
267         }
268         System.exit( 0 );
269         System.out.print( "Hmmscan output parser: " );
270         if ( testHmmscanOutputParser() ) {
271             System.out.println( "OK." );
272             succeeded++;
273         }
274         else {
275             System.out.println( "failed." );
276             failed++;
277         }
278         System.out.print( "Taxonomy code extraction: " );
279         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
280             System.out.println( "OK." );
281             succeeded++;
282         }
283         else {
284             System.out.println( "failed." );
285             failed++;
286         }
287         System.out.print( "SN extraction: " );
288         if ( Test.testExtractSNFromNodeName() ) {
289             System.out.println( "OK." );
290             succeeded++;
291         }
292         else {
293             System.out.println( "failed." );
294             failed++;
295         }
296         System.out.print( "Taxonomy extraction (general): " );
297         if ( Test.testTaxonomyExtraction() ) {
298             System.out.println( "OK." );
299             succeeded++;
300         }
301         else {
302             System.out.println( "failed." );
303             failed++;
304         }
305         System.out.print( "Uri for Aptx web sequence accession: " );
306         if ( Test.testCreateUriForSeqWeb() ) {
307             System.out.println( "OK." );
308             succeeded++;
309         }
310         else {
311             System.out.println( "failed." );
312             failed++;
313         }
314         System.out.print( "Basic node construction and parsing of NHX (node level): " );
315         if ( Test.testNHXNodeParsing() ) {
316             System.out.println( "OK." );
317             succeeded++;
318         }
319         else {
320             System.out.println( "failed." );
321             failed++;
322         }
323         System.out.print( "NHX parsing iterating: " );
324         if ( Test.testNHParsingIter() ) {
325             System.out.println( "OK." );
326             succeeded++;
327         }
328         else {
329             System.out.println( "failed." );
330             failed++;
331         }
332         System.out.print( "NH parsing: " );
333         if ( Test.testNHParsing() ) {
334             System.out.println( "OK." );
335             succeeded++;
336         }
337         else {
338             System.out.println( "failed." );
339             failed++;
340         }
341         System.out.print( "Conversion to NHX (node level): " );
342         if ( Test.testNHXconversion() ) {
343             System.out.println( "OK." );
344             succeeded++;
345         }
346         else {
347             System.out.println( "failed." );
348             failed++;
349         }
350         System.out.print( "NHX parsing: " );
351         if ( Test.testNHXParsing() ) {
352             System.out.println( "OK." );
353             succeeded++;
354         }
355         else {
356             System.out.println( "failed." );
357             failed++;
358         }
359         System.out.print( "NHX parsing with quotes: " );
360         if ( Test.testNHXParsingQuotes() ) {
361             System.out.println( "OK." );
362             succeeded++;
363         }
364         else {
365             System.out.println( "failed." );
366             failed++;
367         }
368         System.out.print( "NHX parsing (MrBayes): " );
369         if ( Test.testNHXParsingMB() ) {
370             System.out.println( "OK." );
371             succeeded++;
372         }
373         else {
374             System.out.println( "failed." );
375             failed++;
376         }
377         System.out.print( "Nexus characters parsing: " );
378         if ( Test.testNexusCharactersParsing() ) {
379             System.out.println( "OK." );
380             succeeded++;
381         }
382         else {
383             System.out.println( "failed." );
384             failed++;
385         }
386         System.out.print( "Nexus tree parsing iterating: " );
387         if ( Test.testNexusTreeParsingIterating() ) {
388             System.out.println( "OK." );
389             succeeded++;
390         }
391         else {
392             System.out.println( "failed." );
393             failed++;
394         }
395         System.out.print( "Nexus tree parsing: " );
396         if ( Test.testNexusTreeParsing() ) {
397             System.out.println( "OK." );
398             succeeded++;
399         }
400         else {
401             System.out.println( "failed." );
402             failed++;
403         }
404         System.out.print( "Nexus tree parsing (translating): " );
405         if ( Test.testNexusTreeParsingTranslating() ) {
406             System.out.println( "OK." );
407             succeeded++;
408         }
409         else {
410             System.out.println( "failed." );
411             failed++;
412         }
413         System.out.print( "Nexus matrix parsing: " );
414         if ( Test.testNexusMatrixParsing() ) {
415             System.out.println( "OK." );
416             succeeded++;
417         }
418         else {
419             System.out.println( "failed." );
420             failed++;
421         }
422         System.out.print( "Basic phyloXML parsing: " );
423         if ( Test.testBasicPhyloXMLparsing() ) {
424             System.out.println( "OK." );
425             succeeded++;
426         }
427         else {
428             System.out.println( "failed." );
429             failed++;
430         }
431         System.out.print( "Basic phyloXML parsing (validating against schema): " );
432         if ( testBasicPhyloXMLparsingValidating() ) {
433             System.out.println( "OK." );
434             succeeded++;
435         }
436         else {
437             System.out.println( "failed." );
438             failed++;
439         }
440         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
441         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
442             System.out.println( "OK." );
443             succeeded++;
444         }
445         else {
446             System.out.println( "failed." );
447             failed++;
448         }
449         System.out.print( "phyloXML Distribution Element: " );
450         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
451             System.out.println( "OK." );
452             succeeded++;
453         }
454         else {
455             System.out.println( "failed." );
456             failed++;
457         }
458         System.out.print( "Tol XML parsing: " );
459         if ( Test.testBasicTolXMLparsing() ) {
460             System.out.println( "OK." );
461             succeeded++;
462         }
463         else {
464             System.out.println( "failed." );
465             failed++;
466         }
467         System.out.print( "Copying of node data: " );
468         if ( Test.testCopyOfNodeData() ) {
469             System.out.println( "OK." );
470             succeeded++;
471         }
472         else {
473             System.out.println( "failed." );
474             failed++;
475         }
476         System.out.print( "Basic tree methods: " );
477         if ( Test.testBasicTreeMethods() ) {
478             System.out.println( "OK." );
479             succeeded++;
480         }
481         else {
482             System.out.println( "failed." );
483             failed++;
484         }
485         System.out.print( "Tree methods: " );
486         if ( Test.testTreeMethods() ) {
487             System.out.println( "OK." );
488             succeeded++;
489         }
490         else {
491             System.out.println( "failed." );
492             failed++;
493         }
494         System.out.print( "Postorder Iterator: " );
495         if ( Test.testPostOrderIterator() ) {
496             System.out.println( "OK." );
497             succeeded++;
498         }
499         else {
500             System.out.println( "failed." );
501             failed++;
502         }
503         System.out.print( "Preorder Iterator: " );
504         if ( Test.testPreOrderIterator() ) {
505             System.out.println( "OK." );
506             succeeded++;
507         }
508         else {
509             System.out.println( "failed." );
510             failed++;
511         }
512         System.out.print( "Levelorder Iterator: " );
513         if ( Test.testLevelOrderIterator() ) {
514             System.out.println( "OK." );
515             succeeded++;
516         }
517         else {
518             System.out.println( "failed." );
519             failed++;
520         }
521         System.out.print( "Re-id methods: " );
522         if ( Test.testReIdMethods() ) {
523             System.out.println( "OK." );
524             succeeded++;
525         }
526         else {
527             System.out.println( "failed." );
528             failed++;
529         }
530         System.out.print( "Methods on last external nodes: " );
531         if ( Test.testLastExternalNodeMethods() ) {
532             System.out.println( "OK." );
533             succeeded++;
534         }
535         else {
536             System.out.println( "failed." );
537             failed++;
538         }
539         System.out.print( "Methods on external nodes: " );
540         if ( Test.testExternalNodeRelatedMethods() ) {
541             System.out.println( "OK." );
542             succeeded++;
543         }
544         else {
545             System.out.println( "failed." );
546             failed++;
547         }
548         System.out.print( "Deletion of external nodes: " );
549         if ( Test.testDeletionOfExternalNodes() ) {
550             System.out.println( "OK." );
551             succeeded++;
552         }
553         else {
554             System.out.println( "failed." );
555             failed++;
556         }
557         System.out.print( "Subtree deletion: " );
558         if ( Test.testSubtreeDeletion() ) {
559             System.out.println( "OK." );
560             succeeded++;
561         }
562         else {
563             System.out.println( "failed." );
564             failed++;
565         }
566         System.out.print( "Phylogeny branch: " );
567         if ( Test.testPhylogenyBranch() ) {
568             System.out.println( "OK." );
569             succeeded++;
570         }
571         else {
572             System.out.println( "failed." );
573             failed++;
574         }
575         System.out.print( "Rerooting: " );
576         if ( Test.testRerooting() ) {
577             System.out.println( "OK." );
578             succeeded++;
579         }
580         else {
581             System.out.println( "failed." );
582             failed++;
583         }
584         System.out.print( "Mipoint rooting: " );
585         if ( Test.testMidpointrooting() ) {
586             System.out.println( "OK." );
587             succeeded++;
588         }
589         else {
590             System.out.println( "failed." );
591             failed++;
592         }
593         System.out.print( "Node removal: " );
594         if ( Test.testNodeRemoval() ) {
595             System.out.println( "OK." );
596             succeeded++;
597         }
598         else {
599             System.out.println( "failed." );
600             failed++;
601         }
602         System.out.print( "Support count: " );
603         if ( Test.testSupportCount() ) {
604             System.out.println( "OK." );
605             succeeded++;
606         }
607         else {
608             System.out.println( "failed." );
609             failed++;
610         }
611         System.out.print( "Support transfer: " );
612         if ( Test.testSupportTransfer() ) {
613             System.out.println( "OK." );
614             succeeded++;
615         }
616         else {
617             System.out.println( "failed." );
618             failed++;
619         }
620         System.out.print( "Finding of LCA: " );
621         if ( Test.testGetLCA() ) {
622             System.out.println( "OK." );
623             succeeded++;
624         }
625         else {
626             System.out.println( "failed." );
627             failed++;
628         }
629         System.out.print( "Finding of LCA 2: " );
630         if ( Test.testGetLCA2() ) {
631             System.out.println( "OK." );
632             succeeded++;
633         }
634         else {
635             System.out.println( "failed." );
636             failed++;
637         }
638         System.out.print( "Calculation of distance between nodes: " );
639         if ( Test.testGetDistance() ) {
640             System.out.println( "OK." );
641             succeeded++;
642         }
643         else {
644             System.out.println( "failed." );
645             failed++;
646         }
647         System.out.print( "Descriptive statistics: " );
648         if ( Test.testDescriptiveStatistics() ) {
649             System.out.println( "OK." );
650             succeeded++;
651         }
652         else {
653             System.out.println( "failed." );
654             failed++;
655         }
656         System.out.print( "Data objects and methods: " );
657         if ( Test.testDataObjects() ) {
658             System.out.println( "OK." );
659             succeeded++;
660         }
661         else {
662             System.out.println( "failed." );
663             failed++;
664         }
665         System.out.print( "Properties map: " );
666         if ( Test.testPropertiesMap() ) {
667             System.out.println( "OK." );
668             succeeded++;
669         }
670         else {
671             System.out.println( "failed." );
672             failed++;
673         }
674         System.out.print( "SDIse: " );
675         if ( Test.testSDIse() ) {
676             System.out.println( "OK." );
677             succeeded++;
678         }
679         else {
680             System.out.println( "failed." );
681             failed++;
682         }
683         System.out.print( "SDIunrooted: " );
684         if ( Test.testSDIunrooted() ) {
685             System.out.println( "OK." );
686             succeeded++;
687         }
688         else {
689             System.out.println( "failed." );
690             failed++;
691         }
692         System.out.print( "GSDI: " );
693         if ( TestGSDI.test() ) {
694             System.out.println( "OK." );
695             succeeded++;
696         }
697         else {
698             System.out.println( "failed." );
699             failed++;
700         }
701         System.out.print( "RIO: " );
702         if ( TestRIO.test() ) {
703             System.out.println( "OK." );
704             succeeded++;
705         }
706         else {
707             System.out.println( "failed." );
708             failed++;
709         }
710         System.out.print( "Phylogeny reconstruction:" );
711         System.out.println();
712         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "Analysis of domain architectures: " );
721         System.out.println();
722         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
723             System.out.println( "OK." );
724             succeeded++;
725         }
726         else {
727             System.out.println( "failed." );
728             failed++;
729         }
730         System.out.print( "GO: " );
731         System.out.println();
732         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
733             System.out.println( "OK." );
734             succeeded++;
735         }
736         else {
737             System.out.println( "failed." );
738             failed++;
739         }
740         System.out.print( "Modeling tools: " );
741         if ( TestPccx.test() ) {
742             System.out.println( "OK." );
743             succeeded++;
744         }
745         else {
746             System.out.println( "failed." );
747             failed++;
748         }
749         System.out.print( "Split Matrix strict: " );
750         if ( Test.testSplitStrict() ) {
751             System.out.println( "OK." );
752             succeeded++;
753         }
754         else {
755             System.out.println( "failed." );
756             failed++;
757         }
758         System.out.print( "Split Matrix: " );
759         if ( Test.testSplit() ) {
760             System.out.println( "OK." );
761             succeeded++;
762         }
763         else {
764             System.out.println( "failed." );
765             failed++;
766         }
767         System.out.print( "Confidence Assessor: " );
768         if ( Test.testConfidenceAssessor() ) {
769             System.out.println( "OK." );
770             succeeded++;
771         }
772         else {
773             System.out.println( "failed." );
774             failed++;
775         }
776         System.out.print( "Basic table: " );
777         if ( Test.testBasicTable() ) {
778             System.out.println( "OK." );
779             succeeded++;
780         }
781         else {
782             System.out.println( "failed." );
783             failed++;
784         }
785         System.out.print( "General table: " );
786         if ( Test.testGeneralTable() ) {
787             System.out.println( "OK." );
788             succeeded++;
789         }
790         else {
791             System.out.println( "failed." );
792             failed++;
793         }
794         System.out.print( "Amino acid sequence: " );
795         if ( Test.testAminoAcidSequence() ) {
796             System.out.println( "OK." );
797             succeeded++;
798         }
799         else {
800             System.out.println( "failed." );
801             failed++;
802         }
803         System.out.print( "General MSA parser: " );
804         if ( Test.testGeneralMsaParser() ) {
805             System.out.println( "OK." );
806             succeeded++;
807         }
808         else {
809             System.out.println( "failed." );
810             failed++;
811         }
812         System.out.print( "Fasta parser for msa: " );
813         if ( Test.testFastaParser() ) {
814             System.out.println( "OK." );
815             succeeded++;
816         }
817         else {
818             System.out.println( "failed." );
819             failed++;
820         }
821         System.out.print( "Creation of balanced phylogeny: " );
822         if ( Test.testCreateBalancedPhylogeny() ) {
823             System.out.println( "OK." );
824             succeeded++;
825         }
826         else {
827             System.out.println( "failed." );
828             failed++;
829         }
830         System.out.print( "EMBL Entry Retrieval: " );
831         if ( Test.testEmblEntryRetrieval() ) {
832             System.out.println( "OK." );
833             succeeded++;
834         }
835         else {
836             System.out.println( "failed." );
837             failed++;
838         }
839         System.out.print( "Uniprot Entry Retrieval: " );
840         if ( Test.testUniprotEntryRetrieval() ) {
841             System.out.println( "OK." );
842             succeeded++;
843         }
844         else {
845             System.out.println( "failed." );
846             failed++;
847         }
848         System.out.print( "Uniprot Taxonomy Search: " );
849         if ( Test.testUniprotTaxonomySearch() ) {
850             System.out.println( "OK." );
851             succeeded++;
852         }
853         else {
854             System.out.println( "failed." );
855             failed++;
856         }
857         //----
858         String path = "";
859         final String os = ForesterUtil.OS_NAME.toLowerCase();
860         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
861             path = "/usr/local/bin/mafft";
862         }
863         else if ( os.indexOf( "win" ) >= 0 ) {
864             path = "C:\\Program Files\\mafft-win\\mafft.bat";
865         }
866         else {
867             path = "/home/czmasek/bin/mafft";
868         }
869         if ( !MsaInferrer.isInstalled( path ) ) {
870             path = "mafft";
871         }
872         if ( !MsaInferrer.isInstalled( path ) ) {
873             path = "/usr/local/bin/mafft";
874         }
875         if ( MsaInferrer.isInstalled( path ) ) {
876             System.out.print( "MAFFT (external program): " );
877             if ( Test.testMafft( path ) ) {
878                 System.out.println( "OK." );
879                 succeeded++;
880             }
881             else {
882                 System.out.println( "failed [will not count towards failed tests]" );
883             }
884         }
885         //----
886         System.out.print( "Next nodes with collapsed: " );
887         if ( Test.testNextNodeWithCollapsing() ) {
888             System.out.println( "OK." );
889             succeeded++;
890         }
891         else {
892             System.out.println( "failed." );
893             failed++;
894         }
895         System.out.print( "Simple MSA quality: " );
896         if ( Test.testMsaQualityMethod() ) {
897             System.out.println( "OK." );
898             succeeded++;
899         }
900         else {
901             System.out.println( "failed." );
902             failed++;
903         }
904         System.out.println();
905         final Runtime rt = java.lang.Runtime.getRuntime();
906         final long free_memory = rt.freeMemory() / 1000000;
907         final long total_memory = rt.totalMemory() / 1000000;
908         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
909                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
910         System.out.println();
911         System.out.println( "Successful tests: " + succeeded );
912         System.out.println( "Failed     tests: " + failed );
913         System.out.println();
914         if ( failed < 1 ) {
915             System.out.println( "OK." );
916         }
917         else {
918             System.out.println( "Not OK." );
919         }
920     }
921
922     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
923         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
924         return p;
925     }
926
927     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
928         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
929     }
930
931     private static boolean testAminoAcidSequence() {
932         try {
933             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
934             if ( aa1.getLength() != 13 ) {
935                 return false;
936             }
937             if ( aa1.getResidueAt( 0 ) != 'A' ) {
938                 return false;
939             }
940             if ( aa1.getResidueAt( 2 ) != 'K' ) {
941                 return false;
942             }
943             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
944                 return false;
945             }
946             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
947             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
948                 return false;
949             }
950             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
951             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
952                 return false;
953             }
954             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
955             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
956                 return false;
957             }
958         }
959         catch ( final Exception e ) {
960             e.printStackTrace();
961             return false;
962         }
963         return true;
964     }
965
966     private static boolean testBasicDomain() {
967         try {
968             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
969             if ( !pd.getDomainId().equals( "id" ) ) {
970                 return false;
971             }
972             if ( pd.getNumber() != 1 ) {
973                 return false;
974             }
975             if ( pd.getTotalCount() != 4 ) {
976                 return false;
977             }
978             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
979                 return false;
980             }
981             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
982             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
983             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
984             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
985             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
986             if ( !a1.equals( a1 ) ) {
987                 return false;
988             }
989             if ( !a1.equals( a1_copy ) ) {
990                 return false;
991             }
992             if ( !a1.equals( a1_equal ) ) {
993                 return false;
994             }
995             if ( !a1.equals( a2 ) ) {
996                 return false;
997             }
998             if ( a1.equals( a3 ) ) {
999                 return false;
1000             }
1001             if ( a1.compareTo( a1 ) != 0 ) {
1002                 return false;
1003             }
1004             if ( a1.compareTo( a1_copy ) != 0 ) {
1005                 return false;
1006             }
1007             if ( a1.compareTo( a1_equal ) != 0 ) {
1008                 return false;
1009             }
1010             if ( a1.compareTo( a2 ) != 0 ) {
1011                 return false;
1012             }
1013             if ( a1.compareTo( a3 ) == 0 ) {
1014                 return false;
1015             }
1016         }
1017         catch ( final Exception e ) {
1018             e.printStackTrace( System.out );
1019             return false;
1020         }
1021         return true;
1022     }
1023
1024     private static boolean testBasicNodeMethods() {
1025         try {
1026             if ( PhylogenyNode.getNodeCount() != 0 ) {
1027                 return false;
1028             }
1029             final PhylogenyNode n1 = new PhylogenyNode();
1030             final PhylogenyNode n2 = PhylogenyNode
1031                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1032             final PhylogenyNode n3 = PhylogenyNode
1033                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1034             final PhylogenyNode n4 = PhylogenyNode
1035                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1036             if ( n1.isHasAssignedEvent() ) {
1037                 return false;
1038             }
1039             if ( PhylogenyNode.getNodeCount() != 4 ) {
1040                 return false;
1041             }
1042             if ( n3.getIndicator() != 0 ) {
1043                 return false;
1044             }
1045             if ( n3.getNumberOfExternalNodes() != 1 ) {
1046                 return false;
1047             }
1048             if ( !n3.isExternal() ) {
1049                 return false;
1050             }
1051             if ( !n3.isRoot() ) {
1052                 return false;
1053             }
1054             if ( !n4.getName().equals( "n4" ) ) {
1055                 return false;
1056             }
1057         }
1058         catch ( final Exception e ) {
1059             e.printStackTrace( System.out );
1060             return false;
1061         }
1062         return true;
1063     }
1064
1065     private static boolean testBasicPhyloXMLparsing() {
1066         try {
1067             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1068             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1069             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1070                                                               xml_parser );
1071             if ( xml_parser.getErrorCount() > 0 ) {
1072                 System.out.println( xml_parser.getErrorMessages().toString() );
1073                 return false;
1074             }
1075             if ( phylogenies_0.length != 4 ) {
1076                 return false;
1077             }
1078             final Phylogeny t1 = phylogenies_0[ 0 ];
1079             final Phylogeny t2 = phylogenies_0[ 1 ];
1080             final Phylogeny t3 = phylogenies_0[ 2 ];
1081             final Phylogeny t4 = phylogenies_0[ 3 ];
1082             if ( t1.getNumberOfExternalNodes() != 1 ) {
1083                 return false;
1084             }
1085             if ( !t1.isRooted() ) {
1086                 return false;
1087             }
1088             if ( t1.isRerootable() ) {
1089                 return false;
1090             }
1091             if ( !t1.getType().equals( "gene_tree" ) ) {
1092                 return false;
1093             }
1094             if ( t2.getNumberOfExternalNodes() != 2 ) {
1095                 return false;
1096             }
1097             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1098                 return false;
1099             }
1100             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1101                 return false;
1102             }
1103             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1104                 return false;
1105             }
1106             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1107                 return false;
1108             }
1109             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1110                 return false;
1111             }
1112             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1113                 return false;
1114             }
1115             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1116                     .startsWith( "actgtgggggt" ) ) {
1117                 return false;
1118             }
1119             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1120                     .startsWith( "ctgtgatgcat" ) ) {
1121                 return false;
1122             }
1123             if ( t3.getNumberOfExternalNodes() != 4 ) {
1124                 return false;
1125             }
1126             if ( !t1.getName().equals( "t1" ) ) {
1127                 return false;
1128             }
1129             if ( !t2.getName().equals( "t2" ) ) {
1130                 return false;
1131             }
1132             if ( !t3.getName().equals( "t3" ) ) {
1133                 return false;
1134             }
1135             if ( !t4.getName().equals( "t4" ) ) {
1136                 return false;
1137             }
1138             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1139                 return false;
1140             }
1141             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1142                 return false;
1143             }
1144             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1145                 return false;
1146             }
1147             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1148                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1149                 return false;
1150             }
1151             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1152                 return false;
1153             }
1154             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1155                 return false;
1156             }
1157             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1158                 return false;
1159             }
1160             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1161                     .equals( "apoptosis" ) ) {
1162                 return false;
1163             }
1164             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1165                     .equals( "GO:0006915" ) ) {
1166                 return false;
1167             }
1168             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1169                     .equals( "UniProtKB" ) ) {
1170                 return false;
1171             }
1172             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1173                     .equals( "experimental" ) ) {
1174                 return false;
1175             }
1176             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1177                     .equals( "function" ) ) {
1178                 return false;
1179             }
1180             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1181                     .getValue() != 1 ) {
1182                 return false;
1183             }
1184             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1185                     .getType().equals( "ml" ) ) {
1186                 return false;
1187             }
1188             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1189                     .equals( "apoptosis" ) ) {
1190                 return false;
1191             }
1192             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1193                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1194                 return false;
1195             }
1196             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1197                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1198                 return false;
1199             }
1200             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1201                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1202                 return false;
1203             }
1204             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1205                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1206                 return false;
1207             }
1208             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1209                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1210                 return false;
1211             }
1212             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1213                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1214                 return false;
1215             }
1216             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1217                     .equals( "GO:0005829" ) ) {
1218                 return false;
1219             }
1220             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1221                     .equals( "intracellular organelle" ) ) {
1222                 return false;
1223             }
1224             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1225                 return false;
1226             }
1227             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1228                     .equals( "UniProt link" ) ) ) {
1229                 return false;
1230             }
1231             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1232                 return false;
1233             }
1234             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1235             if ( x.size() != 4 ) {
1236                 return false;
1237             }
1238             int c = 0;
1239             for( final Accession acc : x ) {
1240                 if ( c == 0 ) {
1241                     if ( !acc.getSource().equals( "KEGG" ) ) {
1242                         return false;
1243                     }
1244                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1245                         return false;
1246                     }
1247                 }
1248                 c++;
1249             }
1250         }
1251         catch ( final Exception e ) {
1252             e.printStackTrace( System.out );
1253             return false;
1254         }
1255         return true;
1256     }
1257
1258     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1259         try {
1260             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1261             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1262             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1263                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1264             }
1265             else {
1266                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1267             }
1268             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1269                                                               xml_parser );
1270             if ( xml_parser.getErrorCount() > 0 ) {
1271                 System.out.println( xml_parser.getErrorMessages().toString() );
1272                 return false;
1273             }
1274             if ( phylogenies_0.length != 4 ) {
1275                 return false;
1276             }
1277             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1278             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1279             if ( phylogenies_t1.length != 1 ) {
1280                 return false;
1281             }
1282             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1283             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1284                 return false;
1285             }
1286             if ( !t1_rt.isRooted() ) {
1287                 return false;
1288             }
1289             if ( t1_rt.isRerootable() ) {
1290                 return false;
1291             }
1292             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1293                 return false;
1294             }
1295             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1296             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1297             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1298             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1299                 return false;
1300             }
1301             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1302                 return false;
1303             }
1304             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1305                 return false;
1306             }
1307             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1308                 return false;
1309             }
1310             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1311                     .startsWith( "actgtgggggt" ) ) {
1312                 return false;
1313             }
1314             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1315                     .startsWith( "ctgtgatgcat" ) ) {
1316                 return false;
1317             }
1318             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1319             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1320             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1321             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1322             if ( phylogenies_1.length != 1 ) {
1323                 return false;
1324             }
1325             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1326             if ( !t3_rt.getName().equals( "t3" ) ) {
1327                 return false;
1328             }
1329             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1330                 return false;
1331             }
1332             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1333                 return false;
1334             }
1335             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1336                 return false;
1337             }
1338             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1339                 return false;
1340             }
1341             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1342                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1343                 return false;
1344             }
1345             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1346                 return false;
1347             }
1348             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1349                 return false;
1350             }
1351             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1352                     .equals( "UniProtKB" ) ) {
1353                 return false;
1354             }
1355             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1356                     .equals( "apoptosis" ) ) {
1357                 return false;
1358             }
1359             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1360                     .equals( "GO:0006915" ) ) {
1361                 return false;
1362             }
1363             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1364                     .equals( "UniProtKB" ) ) {
1365                 return false;
1366             }
1367             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1368                     .equals( "experimental" ) ) {
1369                 return false;
1370             }
1371             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1372                     .equals( "function" ) ) {
1373                 return false;
1374             }
1375             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1376                     .getValue() != 1 ) {
1377                 return false;
1378             }
1379             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1380                     .getType().equals( "ml" ) ) {
1381                 return false;
1382             }
1383             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1384                     .equals( "apoptosis" ) ) {
1385                 return false;
1386             }
1387             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1388                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1389                 return false;
1390             }
1391             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1392                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1393                 return false;
1394             }
1395             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1396                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1397                 return false;
1398             }
1399             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1400                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1401                 return false;
1402             }
1403             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1404                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1405                 return false;
1406             }
1407             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1408                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1409                 return false;
1410             }
1411             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1412                     .equals( "GO:0005829" ) ) {
1413                 return false;
1414             }
1415             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1416                     .equals( "intracellular organelle" ) ) {
1417                 return false;
1418             }
1419             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1420                 return false;
1421             }
1422             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1423                     .equals( "UniProt link" ) ) ) {
1424                 return false;
1425             }
1426             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1427                 return false;
1428             }
1429             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1430                 return false;
1431             }
1432             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1433                     .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." ) ) ) {
1434                 return false;
1435             }
1436             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1437                 return false;
1438             }
1439             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1440                 return false;
1441             }
1442             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1443                 return false;
1444             }
1445             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1446                 return false;
1447             }
1448             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1449                     .equals( "ncbi" ) ) {
1450                 return false;
1451             }
1452             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1453                 return false;
1454             }
1455             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1456                     .getName().equals( "B" ) ) {
1457                 return false;
1458             }
1459             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1460                     .getFrom() != 21 ) {
1461                 return false;
1462             }
1463             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1464                 return false;
1465             }
1466             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1467                     .getLength() != 24 ) {
1468                 return false;
1469             }
1470             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1471                     .getConfidence() != 2144 ) {
1472                 return false;
1473             }
1474             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1475                     .equals( "pfam" ) ) {
1476                 return false;
1477             }
1478             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1479                 return false;
1480             }
1481             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1482                 return false;
1483             }
1484             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1485                 return false;
1486             }
1487             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1488                 return false;
1489             }
1490             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1491             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1492                 return false;
1493             }
1494             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1495                 return false;
1496             }
1497             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1498                 return false;
1499             }
1500             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1501                 return false;
1502             }
1503             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1504                 return false;
1505             }
1506             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1507                 return false;
1508             }
1509             if ( taxbb.getSynonyms().size() != 2 ) {
1510                 return false;
1511             }
1512             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1513                 return false;
1514             }
1515             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1516                 return false;
1517             }
1518             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1519                 return false;
1520             }
1521             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1522                 return false;
1523             }
1524             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1525                 return false;
1526             }
1527             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1528                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1529                 return false;
1530             }
1531             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1532                 return false;
1533             }
1534             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1535                 return false;
1536             }
1537             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1538                 return false;
1539             }
1540             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1541                 return false;
1542             }
1543             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1544                 return false;
1545             }
1546             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1547                 return false;
1548             }
1549             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1550                 return false;
1551             }
1552             //
1553             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1554                 return false;
1555             }
1556             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1557                     .equalsIgnoreCase( "435" ) ) {
1558                 return false;
1559             }
1560             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1561                 return false;
1562             }
1563             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1564                     .equalsIgnoreCase( "443.7" ) ) {
1565                 return false;
1566             }
1567             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1568                 return false;
1569             }
1570             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1571                 return false;
1572             }
1573             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1574                     .equalsIgnoreCase( "433" ) ) {
1575                 return false;
1576             }
1577             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1578                     .getCrossReferences();
1579             if ( x.size() != 4 ) {
1580                 return false;
1581             }
1582             int c = 0;
1583             for( final Accession acc : x ) {
1584                 if ( c == 0 ) {
1585                     if ( !acc.getSource().equals( "KEGG" ) ) {
1586                         return false;
1587                     }
1588                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1589                         return false;
1590                     }
1591                 }
1592                 c++;
1593             }
1594         }
1595         catch ( final Exception e ) {
1596             e.printStackTrace( System.out );
1597             return false;
1598         }
1599         return true;
1600     }
1601
1602     private static boolean testBasicPhyloXMLparsingValidating() {
1603         try {
1604             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1605             PhyloXmlParser xml_parser = null;
1606             try {
1607                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1608             }
1609             catch ( final Exception e ) {
1610                 // Do nothing -- means were not running from jar.
1611             }
1612             if ( xml_parser == null ) {
1613                 xml_parser = new PhyloXmlParser();
1614                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1615                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1616                 }
1617                 else {
1618                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1619                 }
1620             }
1621             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1622                                                               xml_parser );
1623             if ( xml_parser.getErrorCount() > 0 ) {
1624                 System.out.println( xml_parser.getErrorMessages().toString() );
1625                 return false;
1626             }
1627             if ( phylogenies_0.length != 4 ) {
1628                 return false;
1629             }
1630             final Phylogeny t1 = phylogenies_0[ 0 ];
1631             final Phylogeny t2 = phylogenies_0[ 1 ];
1632             final Phylogeny t3 = phylogenies_0[ 2 ];
1633             final Phylogeny t4 = phylogenies_0[ 3 ];
1634             if ( !t1.getName().equals( "t1" ) ) {
1635                 return false;
1636             }
1637             if ( !t2.getName().equals( "t2" ) ) {
1638                 return false;
1639             }
1640             if ( !t3.getName().equals( "t3" ) ) {
1641                 return false;
1642             }
1643             if ( !t4.getName().equals( "t4" ) ) {
1644                 return false;
1645             }
1646             if ( t1.getNumberOfExternalNodes() != 1 ) {
1647                 return false;
1648             }
1649             if ( t2.getNumberOfExternalNodes() != 2 ) {
1650                 return false;
1651             }
1652             if ( t3.getNumberOfExternalNodes() != 4 ) {
1653                 return false;
1654             }
1655             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1656             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1657             if ( xml_parser.getErrorCount() > 0 ) {
1658                 System.out.println( "errors:" );
1659                 System.out.println( xml_parser.getErrorMessages().toString() );
1660                 return false;
1661             }
1662             if ( phylogenies_1.length != 4 ) {
1663                 return false;
1664             }
1665             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1666                                                               xml_parser );
1667             if ( xml_parser.getErrorCount() > 0 ) {
1668                 System.out.println( "errors:" );
1669                 System.out.println( xml_parser.getErrorMessages().toString() );
1670                 return false;
1671             }
1672             if ( phylogenies_2.length != 1 ) {
1673                 return false;
1674             }
1675             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1676                 return false;
1677             }
1678             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1679                                                               xml_parser );
1680             if ( xml_parser.getErrorCount() > 0 ) {
1681                 System.out.println( xml_parser.getErrorMessages().toString() );
1682                 return false;
1683             }
1684             if ( phylogenies_3.length != 2 ) {
1685                 return false;
1686             }
1687             final Phylogeny a = phylogenies_3[ 0 ];
1688             if ( !a.getName().equals( "tree 4" ) ) {
1689                 return false;
1690             }
1691             if ( a.getNumberOfExternalNodes() != 3 ) {
1692                 return false;
1693             }
1694             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1695                 return false;
1696             }
1697             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1698                 return false;
1699             }
1700             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1701                                                               xml_parser );
1702             if ( xml_parser.getErrorCount() > 0 ) {
1703                 System.out.println( xml_parser.getErrorMessages().toString() );
1704                 return false;
1705             }
1706             if ( phylogenies_4.length != 1 ) {
1707                 return false;
1708             }
1709             final Phylogeny s = phylogenies_4[ 0 ];
1710             if ( s.getNumberOfExternalNodes() != 6 ) {
1711                 return false;
1712             }
1713             s.getNode( "first" );
1714             s.getNode( "<>" );
1715             s.getNode( "\"<a'b&c'd\">\"" );
1716             s.getNode( "'''\"" );
1717             s.getNode( "\"\"\"" );
1718             s.getNode( "dick & doof" );
1719         }
1720         catch ( final Exception e ) {
1721             e.printStackTrace( System.out );
1722             return false;
1723         }
1724         return true;
1725     }
1726
1727     private static boolean testBasicProtein() {
1728         try {
1729             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1730             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1731             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1732             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1733             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1734             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1735             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1736             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1737             p0.addProteinDomain( y );
1738             p0.addProteinDomain( e );
1739             p0.addProteinDomain( b );
1740             p0.addProteinDomain( c );
1741             p0.addProteinDomain( d );
1742             p0.addProteinDomain( a );
1743             p0.addProteinDomain( x );
1744             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1745                 return false;
1746             }
1747             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1748                 return false;
1749             }
1750             //
1751             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1752             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1753             aa0.addProteinDomain( a1 );
1754             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1755                 return false;
1756             }
1757             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1758                 return false;
1759             }
1760             //
1761             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1762             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1763             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1764             aa1.addProteinDomain( a11 );
1765             aa1.addProteinDomain( a12 );
1766             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1767                 return false;
1768             }
1769             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1770                 return false;
1771             }
1772             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1773             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1774                 return false;
1775             }
1776             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1777                 return false;
1778             }
1779             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1780                 return false;
1781             }
1782             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1783             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1784                 return false;
1785             }
1786             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1787                 return false;
1788             }
1789             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1790                 return false;
1791             }
1792             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1793                 return false;
1794             }
1795             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1796             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1797                 return false;
1798             }
1799             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1800                 return false;
1801             }
1802             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1803                 return false;
1804             }
1805             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1806                 return false;
1807             }
1808             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1809             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1810                 return false;
1811             }
1812             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1813                 return false;
1814             }
1815             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1816                 return false;
1817             }
1818             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1819                 return false;
1820             }
1821             //
1822             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1823             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1824             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1825             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1826             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1827             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1828             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1829             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1830             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1831             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1832             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1833             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1834             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1835             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1836             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1837             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1838             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1839             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1840             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1841             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1842             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1843             p00.addProteinDomain( y0 );
1844             p00.addProteinDomain( e0 );
1845             p00.addProteinDomain( b0 );
1846             p00.addProteinDomain( c0 );
1847             p00.addProteinDomain( d0 );
1848             p00.addProteinDomain( a0 );
1849             p00.addProteinDomain( x0 );
1850             p00.addProteinDomain( y1 );
1851             p00.addProteinDomain( y2 );
1852             p00.addProteinDomain( y3 );
1853             p00.addProteinDomain( e1 );
1854             p00.addProteinDomain( e2 );
1855             p00.addProteinDomain( e3 );
1856             p00.addProteinDomain( e4 );
1857             p00.addProteinDomain( e5 );
1858             p00.addProteinDomain( z0 );
1859             p00.addProteinDomain( z1 );
1860             p00.addProteinDomain( z2 );
1861             p00.addProteinDomain( zz0 );
1862             p00.addProteinDomain( zz1 );
1863             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1864                 return false;
1865             }
1866             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1867                 return false;
1868             }
1869             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1870                 return false;
1871             }
1872             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1873                 return false;
1874             }
1875             if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1876                 return false;
1877             }
1878             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1879             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1880             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1881             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1882             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1883             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1884             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1885             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1886             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1887             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1888             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1889             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1890             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1891             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1892             p.addProteinDomain( B15 );
1893             p.addProteinDomain( C50 );
1894             p.addProteinDomain( A60 );
1895             p.addProteinDomain( A30 );
1896             p.addProteinDomain( C70 );
1897             p.addProteinDomain( B35 );
1898             p.addProteinDomain( B40 );
1899             p.addProteinDomain( A0 );
1900             p.addProteinDomain( A10 );
1901             p.addProteinDomain( A20 );
1902             p.addProteinDomain( B25 );
1903             p.addProteinDomain( D80 );
1904             List<String> domains_ids = new ArrayList<String>();
1905             domains_ids.add( "A" );
1906             domains_ids.add( "B" );
1907             domains_ids.add( "C" );
1908             if ( !p.contains( domains_ids, false ) ) {
1909                 return false;
1910             }
1911             if ( !p.contains( domains_ids, true ) ) {
1912                 return false;
1913             }
1914             domains_ids.add( "X" );
1915             if ( p.contains( domains_ids, false ) ) {
1916                 return false;
1917             }
1918             if ( p.contains( domains_ids, true ) ) {
1919                 return false;
1920             }
1921             domains_ids = new ArrayList<String>();
1922             domains_ids.add( "A" );
1923             domains_ids.add( "C" );
1924             domains_ids.add( "D" );
1925             if ( !p.contains( domains_ids, false ) ) {
1926                 return false;
1927             }
1928             if ( !p.contains( domains_ids, true ) ) {
1929                 return false;
1930             }
1931             domains_ids = new ArrayList<String>();
1932             domains_ids.add( "A" );
1933             domains_ids.add( "D" );
1934             domains_ids.add( "C" );
1935             if ( !p.contains( domains_ids, false ) ) {
1936                 return false;
1937             }
1938             if ( p.contains( domains_ids, true ) ) {
1939                 return false;
1940             }
1941             domains_ids = new ArrayList<String>();
1942             domains_ids.add( "A" );
1943             domains_ids.add( "A" );
1944             domains_ids.add( "B" );
1945             if ( !p.contains( domains_ids, false ) ) {
1946                 return false;
1947             }
1948             if ( !p.contains( domains_ids, true ) ) {
1949                 return false;
1950             }
1951             domains_ids = new ArrayList<String>();
1952             domains_ids.add( "A" );
1953             domains_ids.add( "A" );
1954             domains_ids.add( "A" );
1955             domains_ids.add( "B" );
1956             domains_ids.add( "B" );
1957             if ( !p.contains( domains_ids, false ) ) {
1958                 return false;
1959             }
1960             if ( !p.contains( domains_ids, true ) ) {
1961                 return false;
1962             }
1963             domains_ids = new ArrayList<String>();
1964             domains_ids.add( "A" );
1965             domains_ids.add( "A" );
1966             domains_ids.add( "B" );
1967             domains_ids.add( "A" );
1968             domains_ids.add( "B" );
1969             domains_ids.add( "B" );
1970             domains_ids.add( "A" );
1971             domains_ids.add( "B" );
1972             domains_ids.add( "C" );
1973             domains_ids.add( "A" );
1974             domains_ids.add( "C" );
1975             domains_ids.add( "D" );
1976             if ( !p.contains( domains_ids, false ) ) {
1977                 return false;
1978             }
1979             if ( p.contains( domains_ids, true ) ) {
1980                 return false;
1981             }
1982         }
1983         catch ( final Exception e ) {
1984             e.printStackTrace( System.out );
1985             return false;
1986         }
1987         return true;
1988     }
1989
1990     private static boolean testBasicTable() {
1991         try {
1992             final BasicTable<String> t0 = new BasicTable<String>();
1993             if ( t0.getNumberOfColumns() != 0 ) {
1994                 return false;
1995             }
1996             if ( t0.getNumberOfRows() != 0 ) {
1997                 return false;
1998             }
1999             t0.setValue( 3, 2, "23" );
2000             t0.setValue( 10, 1, "error" );
2001             t0.setValue( 10, 1, "110" );
2002             t0.setValue( 9, 1, "19" );
2003             t0.setValue( 1, 10, "101" );
2004             t0.setValue( 10, 10, "1010" );
2005             t0.setValue( 100, 10, "10100" );
2006             t0.setValue( 0, 0, "00" );
2007             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2008                 return false;
2009             }
2010             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2011                 return false;
2012             }
2013             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2014                 return false;
2015             }
2016             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2017                 return false;
2018             }
2019             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2020                 return false;
2021             }
2022             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2023                 return false;
2024             }
2025             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2026                 return false;
2027             }
2028             if ( t0.getNumberOfColumns() != 101 ) {
2029                 return false;
2030             }
2031             if ( t0.getNumberOfRows() != 11 ) {
2032                 return false;
2033             }
2034             if ( t0.getValueAsString( 49, 4 ) != null ) {
2035                 return false;
2036             }
2037             final String l = ForesterUtil.getLineSeparator();
2038             final StringBuffer source = new StringBuffer();
2039             source.append( "" + l );
2040             source.append( "# 1 1 1 1 1 1 1 1" + l );
2041             source.append( " 00 01 02 03" + l );
2042             source.append( "   10 11 12 13  " + l );
2043             source.append( "20 21 22 23 " + l );
2044             source.append( "    30  31    32 33" + l );
2045             source.append( "40 41 42 43" + l );
2046             source.append( "  # 1 1 1 1 1 " + l );
2047             source.append( "50 51 52 53 54" + l );
2048             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2049             if ( t1.getNumberOfColumns() != 5 ) {
2050                 return false;
2051             }
2052             if ( t1.getNumberOfRows() != 6 ) {
2053                 return false;
2054             }
2055             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2056                 return false;
2057             }
2058             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2059                 return false;
2060             }
2061             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2062                 return false;
2063             }
2064             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2065                 return false;
2066             }
2067             final StringBuffer source1 = new StringBuffer();
2068             source1.append( "" + l );
2069             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2070             source1.append( " 00; 01 ;02;03" + l );
2071             source1.append( "   10; 11; 12; 13  " + l );
2072             source1.append( "20; 21; 22; 23 " + l );
2073             source1.append( "    30;  31;    32; 33" + l );
2074             source1.append( "40;41;42;43" + l );
2075             source1.append( "  # 1 1 1 1 1 " + l );
2076             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2077             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2078             if ( t2.getNumberOfColumns() != 5 ) {
2079                 return false;
2080             }
2081             if ( t2.getNumberOfRows() != 6 ) {
2082                 return false;
2083             }
2084             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2085                 return false;
2086             }
2087             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2088                 return false;
2089             }
2090             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2091                 return false;
2092             }
2093             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2094                 return false;
2095             }
2096             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2097                 return false;
2098             }
2099             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2100                 return false;
2101             }
2102             final StringBuffer source2 = new StringBuffer();
2103             source2.append( "" + l );
2104             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2105             source2.append( " 00; 01 ;02;03" + l );
2106             source2.append( "   10; 11; 12; 13  " + l );
2107             source2.append( "20; 21; 22; 23 " + l );
2108             source2.append( "                     " + l );
2109             source2.append( "    30;  31;    32; 33" + l );
2110             source2.append( "40;41;42;43" + l );
2111             source2.append( "  comment: 1 1 1 1 1 " + l );
2112             source2.append( ";;;50  ;   52; 53;;54   " + l );
2113             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2114                                                                         ';',
2115                                                                         false,
2116                                                                         false,
2117                                                                         "comment:",
2118                                                                         false );
2119             if ( tl.size() != 2 ) {
2120                 return false;
2121             }
2122             final BasicTable<String> t3 = tl.get( 0 );
2123             final BasicTable<String> t4 = tl.get( 1 );
2124             if ( t3.getNumberOfColumns() != 4 ) {
2125                 return false;
2126             }
2127             if ( t3.getNumberOfRows() != 3 ) {
2128                 return false;
2129             }
2130             if ( t4.getNumberOfColumns() != 4 ) {
2131                 return false;
2132             }
2133             if ( t4.getNumberOfRows() != 3 ) {
2134                 return false;
2135             }
2136             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2137                 return false;
2138             }
2139             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2140                 return false;
2141             }
2142         }
2143         catch ( final Exception e ) {
2144             e.printStackTrace( System.out );
2145             return false;
2146         }
2147         return true;
2148     }
2149
2150     private static boolean testBasicTolXMLparsing() {
2151         try {
2152             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2153             final TolParser parser = new TolParser();
2154             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2155             if ( parser.getErrorCount() > 0 ) {
2156                 System.out.println( parser.getErrorMessages().toString() );
2157                 return false;
2158             }
2159             if ( phylogenies_0.length != 1 ) {
2160                 return false;
2161             }
2162             final Phylogeny t1 = phylogenies_0[ 0 ];
2163             if ( t1.getNumberOfExternalNodes() != 5 ) {
2164                 return false;
2165             }
2166             if ( !t1.isRooted() ) {
2167                 return false;
2168             }
2169             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2170                 return false;
2171             }
2172             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2173                 return false;
2174             }
2175             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2176                 return false;
2177             }
2178             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2179                 return false;
2180             }
2181             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2182             if ( parser.getErrorCount() > 0 ) {
2183                 System.out.println( parser.getErrorMessages().toString() );
2184                 return false;
2185             }
2186             if ( phylogenies_1.length != 1 ) {
2187                 return false;
2188             }
2189             final Phylogeny t2 = phylogenies_1[ 0 ];
2190             if ( t2.getNumberOfExternalNodes() != 664 ) {
2191                 return false;
2192             }
2193             if ( !t2.isRooted() ) {
2194                 return false;
2195             }
2196             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2197                 return false;
2198             }
2199             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2200                 return false;
2201             }
2202             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2203                 return false;
2204             }
2205             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2206                 return false;
2207             }
2208             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2209                 return false;
2210             }
2211             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2212                     .equals( "Aquifex" ) ) {
2213                 return false;
2214             }
2215             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2216             if ( parser.getErrorCount() > 0 ) {
2217                 System.out.println( parser.getErrorMessages().toString() );
2218                 return false;
2219             }
2220             if ( phylogenies_2.length != 1 ) {
2221                 return false;
2222             }
2223             final Phylogeny t3 = phylogenies_2[ 0 ];
2224             if ( t3.getNumberOfExternalNodes() != 184 ) {
2225                 return false;
2226             }
2227             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2228                 return false;
2229             }
2230             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2231                 return false;
2232             }
2233             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2234                 return false;
2235             }
2236             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2237             if ( parser.getErrorCount() > 0 ) {
2238                 System.out.println( parser.getErrorMessages().toString() );
2239                 return false;
2240             }
2241             if ( phylogenies_3.length != 1 ) {
2242                 return false;
2243             }
2244             final Phylogeny t4 = phylogenies_3[ 0 ];
2245             if ( t4.getNumberOfExternalNodes() != 1 ) {
2246                 return false;
2247             }
2248             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2249                 return false;
2250             }
2251             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2252                 return false;
2253             }
2254             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2255                 return false;
2256             }
2257             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2258             if ( parser.getErrorCount() > 0 ) {
2259                 System.out.println( parser.getErrorMessages().toString() );
2260                 return false;
2261             }
2262             if ( phylogenies_4.length != 1 ) {
2263                 return false;
2264             }
2265             final Phylogeny t5 = phylogenies_4[ 0 ];
2266             if ( t5.getNumberOfExternalNodes() != 13 ) {
2267                 return false;
2268             }
2269             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2270                 return false;
2271             }
2272             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2273                 return false;
2274             }
2275             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2276                 return false;
2277             }
2278         }
2279         catch ( final Exception e ) {
2280             e.printStackTrace( System.out );
2281             return false;
2282         }
2283         return true;
2284     }
2285
2286     private static boolean testBasicTreeMethods() {
2287         try {
2288             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2289             final Phylogeny t1 = factory.create();
2290             if ( !t1.isEmpty() ) {
2291                 return false;
2292             }
2293             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2294             if ( t2.getNumberOfExternalNodes() != 4 ) {
2295                 return false;
2296             }
2297             if ( t2.getHeight() != 8.5 ) {
2298                 return false;
2299             }
2300             if ( !t2.isCompletelyBinary() ) {
2301                 return false;
2302             }
2303             if ( t2.isEmpty() ) {
2304                 return false;
2305             }
2306             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2307             if ( t3.getNumberOfExternalNodes() != 5 ) {
2308                 return false;
2309             }
2310             if ( t3.getHeight() != 11 ) {
2311                 return false;
2312             }
2313             if ( t3.isCompletelyBinary() ) {
2314                 return false;
2315             }
2316             final PhylogenyNode n = t3.getNode( "ABC" );
2317             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 ];
2318             if ( t4.getNumberOfExternalNodes() != 9 ) {
2319                 return false;
2320             }
2321             if ( t4.getHeight() != 11 ) {
2322                 return false;
2323             }
2324             if ( t4.isCompletelyBinary() ) {
2325                 return false;
2326             }
2327             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)" );
2328             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2329             if ( t5.getNumberOfExternalNodes() != 8 ) {
2330                 return false;
2331             }
2332             if ( t5.getHeight() != 15 ) {
2333                 return false;
2334             }
2335             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)" );
2336             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2337             if ( t6.getHeight() != 15 ) {
2338                 return false;
2339             }
2340             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)" );
2341             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2342             if ( t7.getHeight() != 15 ) {
2343                 return false;
2344             }
2345             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)" );
2346             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2347             if ( t8.getNumberOfExternalNodes() != 10 ) {
2348                 return false;
2349             }
2350             if ( t8.getHeight() != 15 ) {
2351                 return false;
2352             }
2353             final char[] a9 = new char[] { 'a' };
2354             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2355             if ( t9.getHeight() != 0 ) {
2356                 return false;
2357             }
2358             final char[] a10 = new char[] { 'a', ':', '6' };
2359             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2360             if ( t10.getHeight() != 6 ) {
2361                 return false;
2362             }
2363         }
2364         catch ( final Exception e ) {
2365             e.printStackTrace( System.out );
2366             return false;
2367         }
2368         return true;
2369     }
2370
2371     private static boolean testConfidenceAssessor() {
2372         try {
2373             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2374             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2375             final Phylogeny[] ev0 = factory
2376                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2377                              new NHXParser() );
2378             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2379             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2380                 return false;
2381             }
2382             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2383                 return false;
2384             }
2385             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2386             final Phylogeny[] ev1 = factory
2387                     .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)));",
2388                              new NHXParser() );
2389             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2390             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2391                 return false;
2392             }
2393             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2394                 return false;
2395             }
2396             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2397             final Phylogeny[] ev_b = factory
2398                     .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",
2399                              new NHXParser() );
2400             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2401             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2402                 return false;
2403             }
2404             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2405                 return false;
2406             }
2407             //
2408             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2409             final Phylogeny[] ev1x = factory
2410                     .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)));",
2411                              new NHXParser() );
2412             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2413             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2414                 return false;
2415             }
2416             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2417                 return false;
2418             }
2419             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2420             final Phylogeny[] ev_bx = factory
2421                     .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",
2422                              new NHXParser() );
2423             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2424             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2425                 return false;
2426             }
2427             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2428                 return false;
2429             }
2430             //
2431             final Phylogeny[] t2 = factory
2432                     .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);",
2433                              new NHXParser() );
2434             final Phylogeny[] ev2 = factory
2435                     .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);",
2436                              new NHXParser() );
2437             for( final Phylogeny target : t2 ) {
2438                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2439             }
2440             //
2441             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2442                                                  new NHXParser() )[ 0 ];
2443             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2444             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2445             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2446                 return false;
2447             }
2448             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2449                 return false;
2450             }
2451             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2452                 return false;
2453             }
2454         }
2455         catch ( final Exception e ) {
2456             e.printStackTrace();
2457             return false;
2458         }
2459         return true;
2460     }
2461
2462     private static boolean testCopyOfNodeData() {
2463         try {
2464             final PhylogenyNode n1 = PhylogenyNode
2465                     .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]" );
2466             final PhylogenyNode n2 = n1.copyNodeData();
2467             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2468                 return false;
2469             }
2470         }
2471         catch ( final Exception e ) {
2472             e.printStackTrace();
2473             return false;
2474         }
2475         return true;
2476     }
2477
2478     private static boolean testCreateBalancedPhylogeny() {
2479         try {
2480             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2481             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2482                 return false;
2483             }
2484             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2485                 return false;
2486             }
2487             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2488             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2489                 return false;
2490             }
2491             if ( p1.getNumberOfExternalNodes() != 100 ) {
2492                 return false;
2493             }
2494         }
2495         catch ( final Exception e ) {
2496             e.printStackTrace();
2497             return false;
2498         }
2499         return true;
2500     }
2501
2502     private static boolean testCreateUriForSeqWeb() {
2503         try {
2504             final PhylogenyNode n = new PhylogenyNode();
2505             n.setName( "tr|B3RJ64" );
2506             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2507                 return false;
2508             }
2509             n.setName( "B0LM41_HUMAN" );
2510             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2511                 return false;
2512             }
2513             n.setName( "NP_001025424" );
2514             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2515                 return false;
2516             }
2517             n.setName( "_NM_001030253-" );
2518             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2519                 return false;
2520             }
2521             n.setName( "XM_002122186" );
2522             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2523                 return false;
2524             }
2525             n.setName( "dgh_AAA34956_gdg" );
2526             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2527                 return false;
2528             }
2529             n.setName( "AAA34956" );
2530             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2531                 return false;
2532             }
2533             n.setName( "GI:394892" );
2534             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2535                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2536                 return false;
2537             }
2538             n.setName( "gi_394892" );
2539             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2540                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2541                 return false;
2542             }
2543             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2544             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2545                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2546                 return false;
2547             }
2548             n.setName( "P12345" );
2549             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2550                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2551                 return false;
2552             }
2553             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2554             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2555                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2556                 return false;
2557             }
2558         }
2559         catch ( final Exception e ) {
2560             e.printStackTrace( System.out );
2561             return false;
2562         }
2563         return true;
2564     }
2565
2566     private static boolean testDataObjects() {
2567         try {
2568             final Confidence s0 = new Confidence();
2569             final Confidence s1 = new Confidence();
2570             if ( !s0.isEqual( s1 ) ) {
2571                 return false;
2572             }
2573             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2574             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2575             if ( s2.isEqual( s1 ) ) {
2576                 return false;
2577             }
2578             if ( !s2.isEqual( s3 ) ) {
2579                 return false;
2580             }
2581             final Confidence s4 = ( Confidence ) s3.copy();
2582             if ( !s4.isEqual( s3 ) ) {
2583                 return false;
2584             }
2585             s3.asSimpleText();
2586             s3.asText();
2587             // Taxonomy
2588             // ----------
2589             final Taxonomy t1 = new Taxonomy();
2590             final Taxonomy t2 = new Taxonomy();
2591             final Taxonomy t3 = new Taxonomy();
2592             final Taxonomy t4 = new Taxonomy();
2593             final Taxonomy t5 = new Taxonomy();
2594             t1.setIdentifier( new Identifier( "ecoli" ) );
2595             t1.setTaxonomyCode( "ECOLI" );
2596             t1.setScientificName( "E. coli" );
2597             t1.setCommonName( "coli" );
2598             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2599             if ( !t1.isEqual( t0 ) ) {
2600                 return false;
2601             }
2602             t2.setIdentifier( new Identifier( "ecoli" ) );
2603             t2.setTaxonomyCode( "OTHER" );
2604             t2.setScientificName( "what" );
2605             t2.setCommonName( "something" );
2606             if ( !t1.isEqual( t2 ) ) {
2607                 return false;
2608             }
2609             t2.setIdentifier( new Identifier( "nemve" ) );
2610             if ( t1.isEqual( t2 ) ) {
2611                 return false;
2612             }
2613             t1.setIdentifier( null );
2614             t3.setTaxonomyCode( "ECOLI" );
2615             t3.setScientificName( "what" );
2616             t3.setCommonName( "something" );
2617             if ( !t1.isEqual( t3 ) ) {
2618                 return false;
2619             }
2620             t1.setIdentifier( null );
2621             t1.setTaxonomyCode( "" );
2622             t4.setScientificName( "E. ColI" );
2623             t4.setCommonName( "something" );
2624             if ( !t1.isEqual( t4 ) ) {
2625                 return false;
2626             }
2627             t4.setScientificName( "B. subtilis" );
2628             t4.setCommonName( "something" );
2629             if ( t1.isEqual( t4 ) ) {
2630                 return false;
2631             }
2632             t1.setIdentifier( null );
2633             t1.setTaxonomyCode( "" );
2634             t1.setScientificName( "" );
2635             t5.setCommonName( "COLI" );
2636             if ( !t1.isEqual( t5 ) ) {
2637                 return false;
2638             }
2639             t5.setCommonName( "vibrio" );
2640             if ( t1.isEqual( t5 ) ) {
2641                 return false;
2642             }
2643             // Identifier
2644             // ----------
2645             final Identifier id0 = new Identifier( "123", "pfam" );
2646             final Identifier id1 = ( Identifier ) id0.copy();
2647             if ( !id1.isEqual( id1 ) ) {
2648                 return false;
2649             }
2650             if ( !id1.isEqual( id0 ) ) {
2651                 return false;
2652             }
2653             if ( !id0.isEqual( id1 ) ) {
2654                 return false;
2655             }
2656             id1.asSimpleText();
2657             id1.asText();
2658             // ProteinDomain
2659             // ---------------
2660             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2661             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2662             if ( !pd1.isEqual( pd1 ) ) {
2663                 return false;
2664             }
2665             if ( !pd1.isEqual( pd0 ) ) {
2666                 return false;
2667             }
2668             pd1.asSimpleText();
2669             pd1.asText();
2670             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2671             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2672             if ( !pd3.isEqual( pd3 ) ) {
2673                 return false;
2674             }
2675             if ( !pd2.isEqual( pd3 ) ) {
2676                 return false;
2677             }
2678             if ( !pd0.isEqual( pd3 ) ) {
2679                 return false;
2680             }
2681             pd3.asSimpleText();
2682             pd3.asText();
2683             // DomainArchitecture
2684             // ------------------
2685             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2686             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2687             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2688             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2689             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2690             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2691             domains0.add( d2 );
2692             domains0.add( d0 );
2693             domains0.add( d3 );
2694             domains0.add( d1 );
2695             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2696             if ( ds0.getNumberOfDomains() != 4 ) {
2697                 return false;
2698             }
2699             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2700             if ( !ds0.isEqual( ds0 ) ) {
2701                 return false;
2702             }
2703             if ( !ds0.isEqual( ds1 ) ) {
2704                 return false;
2705             }
2706             if ( ds1.getNumberOfDomains() != 4 ) {
2707                 return false;
2708             }
2709             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2710             domains1.add( d1 );
2711             domains1.add( d2 );
2712             domains1.add( d4 );
2713             domains1.add( d0 );
2714             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2715             if ( ds0.isEqual( ds2 ) ) {
2716                 return false;
2717             }
2718             ds1.asSimpleText();
2719             ds1.asText();
2720             ds1.toNHX();
2721             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2722             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2723                 System.out.println( ds3.toNHX() );
2724                 return false;
2725             }
2726             if ( ds3.getNumberOfDomains() != 3 ) {
2727                 return false;
2728             }
2729             // Event
2730             // -----
2731             final Event e1 = new Event( Event.EventType.fusion );
2732             if ( e1.isDuplication() ) {
2733                 return false;
2734             }
2735             if ( !e1.isFusion() ) {
2736                 return false;
2737             }
2738             if ( !e1.asText().toString().equals( "fusion" ) ) {
2739                 return false;
2740             }
2741             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2742                 return false;
2743             }
2744             final Event e11 = new Event( Event.EventType.fusion );
2745             if ( !e11.isEqual( e1 ) ) {
2746                 return false;
2747             }
2748             if ( !e11.toNHX().toString().equals( "" ) ) {
2749                 return false;
2750             }
2751             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2752             if ( e2.isDuplication() ) {
2753                 return false;
2754             }
2755             if ( !e2.isSpeciationOrDuplication() ) {
2756                 return false;
2757             }
2758             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2759                 return false;
2760             }
2761             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2762                 return false;
2763             }
2764             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2765                 return false;
2766             }
2767             if ( e11.isEqual( e2 ) ) {
2768                 return false;
2769             }
2770             final Event e2c = ( Event ) e2.copy();
2771             if ( !e2c.isEqual( e2 ) ) {
2772                 return false;
2773             }
2774             Event e3 = new Event( 1, 2, 3 );
2775             if ( e3.isDuplication() ) {
2776                 return false;
2777             }
2778             if ( e3.isSpeciation() ) {
2779                 return false;
2780             }
2781             if ( e3.isGeneLoss() ) {
2782                 return false;
2783             }
2784             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2785                 return false;
2786             }
2787             final Event e3c = ( Event ) e3.copy();
2788             final Event e3cc = ( Event ) e3c.copy();
2789             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2790                 return false;
2791             }
2792             e3 = null;
2793             if ( !e3c.isEqual( e3cc ) ) {
2794                 return false;
2795             }
2796             Event e4 = new Event( 1, 2, 3 );
2797             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2798                 return false;
2799             }
2800             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2801                 return false;
2802             }
2803             final Event e4c = ( Event ) e4.copy();
2804             e4 = null;
2805             final Event e4cc = ( Event ) e4c.copy();
2806             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2807                 return false;
2808             }
2809             if ( !e4c.isEqual( e4cc ) ) {
2810                 return false;
2811             }
2812             final Event e5 = new Event();
2813             if ( !e5.isUnassigned() ) {
2814                 return false;
2815             }
2816             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2817                 return false;
2818             }
2819             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2820                 return false;
2821             }
2822             final Event e6 = new Event( 1, 0, 0 );
2823             if ( !e6.asText().toString().equals( "duplication" ) ) {
2824                 return false;
2825             }
2826             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2827                 return false;
2828             }
2829             final Event e7 = new Event( 0, 1, 0 );
2830             if ( !e7.asText().toString().equals( "speciation" ) ) {
2831                 return false;
2832             }
2833             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2834                 return false;
2835             }
2836             final Event e8 = new Event( 0, 0, 1 );
2837             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2838                 return false;
2839             }
2840             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2841                 return false;
2842             }
2843         }
2844         catch ( final Exception e ) {
2845             e.printStackTrace( System.out );
2846             return false;
2847         }
2848         return true;
2849     }
2850
2851     private static boolean testDeletionOfExternalNodes() {
2852         try {
2853             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2854             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2855             final PhylogenyWriter w = new PhylogenyWriter();
2856             if ( t0.isEmpty() ) {
2857                 return false;
2858             }
2859             if ( t0.getNumberOfExternalNodes() != 1 ) {
2860                 return false;
2861             }
2862             t0.deleteSubtree( t0.getNode( "A" ), false );
2863             if ( t0.getNumberOfExternalNodes() != 0 ) {
2864                 return false;
2865             }
2866             if ( !t0.isEmpty() ) {
2867                 return false;
2868             }
2869             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2870             if ( t1.getNumberOfExternalNodes() != 2 ) {
2871                 return false;
2872             }
2873             t1.deleteSubtree( t1.getNode( "A" ), false );
2874             if ( t1.getNumberOfExternalNodes() != 1 ) {
2875                 return false;
2876             }
2877             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2878                 return false;
2879             }
2880             t1.deleteSubtree( t1.getNode( "B" ), false );
2881             if ( t1.getNumberOfExternalNodes() != 1 ) {
2882                 return false;
2883             }
2884             t1.deleteSubtree( t1.getNode( "r" ), false );
2885             if ( !t1.isEmpty() ) {
2886                 return false;
2887             }
2888             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2889             if ( t2.getNumberOfExternalNodes() != 3 ) {
2890                 return false;
2891             }
2892             t2.deleteSubtree( t2.getNode( "B" ), false );
2893             if ( t2.getNumberOfExternalNodes() != 2 ) {
2894                 return false;
2895             }
2896             t2.toNewHampshireX();
2897             PhylogenyNode n = t2.getNode( "A" );
2898             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2899                 return false;
2900             }
2901             t2.deleteSubtree( t2.getNode( "A" ), false );
2902             if ( t2.getNumberOfExternalNodes() != 2 ) {
2903                 return false;
2904             }
2905             t2.deleteSubtree( t2.getNode( "C" ), true );
2906             if ( t2.getNumberOfExternalNodes() != 1 ) {
2907                 return false;
2908             }
2909             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2910             if ( t3.getNumberOfExternalNodes() != 4 ) {
2911                 return false;
2912             }
2913             t3.deleteSubtree( t3.getNode( "B" ), true );
2914             if ( t3.getNumberOfExternalNodes() != 3 ) {
2915                 return false;
2916             }
2917             n = t3.getNode( "A" );
2918             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2919                 return false;
2920             }
2921             n = n.getNextExternalNode();
2922             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2923                 return false;
2924             }
2925             t3.deleteSubtree( t3.getNode( "A" ), true );
2926             if ( t3.getNumberOfExternalNodes() != 2 ) {
2927                 return false;
2928             }
2929             n = t3.getNode( "C" );
2930             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2931                 return false;
2932             }
2933             t3.deleteSubtree( t3.getNode( "C" ), true );
2934             if ( t3.getNumberOfExternalNodes() != 1 ) {
2935                 return false;
2936             }
2937             t3.deleteSubtree( t3.getNode( "D" ), true );
2938             if ( t3.getNumberOfExternalNodes() != 0 ) {
2939                 return false;
2940             }
2941             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2942             if ( t4.getNumberOfExternalNodes() != 6 ) {
2943                 return false;
2944             }
2945             t4.deleteSubtree( t4.getNode( "B2" ), true );
2946             if ( t4.getNumberOfExternalNodes() != 5 ) {
2947                 return false;
2948             }
2949             String s = w.toNewHampshire( t4, false, true ).toString();
2950             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2951                 return false;
2952             }
2953             t4.deleteSubtree( t4.getNode( "B11" ), true );
2954             if ( t4.getNumberOfExternalNodes() != 4 ) {
2955                 return false;
2956             }
2957             t4.deleteSubtree( t4.getNode( "C" ), true );
2958             if ( t4.getNumberOfExternalNodes() != 3 ) {
2959                 return false;
2960             }
2961             n = t4.getNode( "A" );
2962             n = n.getNextExternalNode();
2963             if ( !n.getName().equals( "B12" ) ) {
2964                 return false;
2965             }
2966             n = n.getNextExternalNode();
2967             if ( !n.getName().equals( "D" ) ) {
2968                 return false;
2969             }
2970             s = w.toNewHampshire( t4, false, true ).toString();
2971             if ( !s.equals( "((A,B12),D);" ) ) {
2972                 return false;
2973             }
2974             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2975             t5.deleteSubtree( t5.getNode( "A" ), true );
2976             if ( t5.getNumberOfExternalNodes() != 5 ) {
2977                 return false;
2978             }
2979             s = w.toNewHampshire( t5, false, true ).toString();
2980             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2981                 return false;
2982             }
2983             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2984             t6.deleteSubtree( t6.getNode( "B11" ), true );
2985             if ( t6.getNumberOfExternalNodes() != 5 ) {
2986                 return false;
2987             }
2988             s = w.toNewHampshire( t6, false, false ).toString();
2989             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2990                 return false;
2991             }
2992             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2993             t7.deleteSubtree( t7.getNode( "B12" ), true );
2994             if ( t7.getNumberOfExternalNodes() != 5 ) {
2995                 return false;
2996             }
2997             s = w.toNewHampshire( t7, false, true ).toString();
2998             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2999                 return false;
3000             }
3001             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3002             t8.deleteSubtree( t8.getNode( "B2" ), true );
3003             if ( t8.getNumberOfExternalNodes() != 5 ) {
3004                 return false;
3005             }
3006             s = w.toNewHampshire( t8, false, false ).toString();
3007             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3008                 return false;
3009             }
3010             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3011             t9.deleteSubtree( t9.getNode( "C" ), true );
3012             if ( t9.getNumberOfExternalNodes() != 5 ) {
3013                 return false;
3014             }
3015             s = w.toNewHampshire( t9, false, true ).toString();
3016             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3017                 return false;
3018             }
3019             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3020             t10.deleteSubtree( t10.getNode( "D" ), true );
3021             if ( t10.getNumberOfExternalNodes() != 5 ) {
3022                 return false;
3023             }
3024             s = w.toNewHampshire( t10, false, true ).toString();
3025             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3026                 return false;
3027             }
3028             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3029             t11.deleteSubtree( t11.getNode( "A" ), true );
3030             if ( t11.getNumberOfExternalNodes() != 2 ) {
3031                 return false;
3032             }
3033             s = w.toNewHampshire( t11, false, true ).toString();
3034             if ( !s.equals( "(B,C);" ) ) {
3035                 return false;
3036             }
3037             t11.deleteSubtree( t11.getNode( "C" ), true );
3038             if ( t11.getNumberOfExternalNodes() != 1 ) {
3039                 return false;
3040             }
3041             s = w.toNewHampshire( t11, false, false ).toString();
3042             if ( !s.equals( "B;" ) ) {
3043                 return false;
3044             }
3045             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3046             t12.deleteSubtree( t12.getNode( "B2" ), true );
3047             if ( t12.getNumberOfExternalNodes() != 8 ) {
3048                 return false;
3049             }
3050             s = w.toNewHampshire( t12, false, true ).toString();
3051             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3052                 return false;
3053             }
3054             t12.deleteSubtree( t12.getNode( "B3" ), true );
3055             if ( t12.getNumberOfExternalNodes() != 7 ) {
3056                 return false;
3057             }
3058             s = w.toNewHampshire( t12, false, true ).toString();
3059             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3060                 return false;
3061             }
3062             t12.deleteSubtree( t12.getNode( "C3" ), true );
3063             if ( t12.getNumberOfExternalNodes() != 6 ) {
3064                 return false;
3065             }
3066             s = w.toNewHampshire( t12, false, true ).toString();
3067             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3068                 return false;
3069             }
3070             t12.deleteSubtree( t12.getNode( "A1" ), true );
3071             if ( t12.getNumberOfExternalNodes() != 5 ) {
3072                 return false;
3073             }
3074             s = w.toNewHampshire( t12, false, true ).toString();
3075             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3076                 return false;
3077             }
3078             t12.deleteSubtree( t12.getNode( "B1" ), true );
3079             if ( t12.getNumberOfExternalNodes() != 4 ) {
3080                 return false;
3081             }
3082             s = w.toNewHampshire( t12, false, true ).toString();
3083             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3084                 return false;
3085             }
3086             t12.deleteSubtree( t12.getNode( "A3" ), true );
3087             if ( t12.getNumberOfExternalNodes() != 3 ) {
3088                 return false;
3089             }
3090             s = w.toNewHampshire( t12, false, true ).toString();
3091             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3092                 return false;
3093             }
3094             t12.deleteSubtree( t12.getNode( "A2" ), true );
3095             if ( t12.getNumberOfExternalNodes() != 2 ) {
3096                 return false;
3097             }
3098             s = w.toNewHampshire( t12, false, true ).toString();
3099             if ( !s.equals( "(C1,C2);" ) ) {
3100                 return false;
3101             }
3102             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3103             t13.deleteSubtree( t13.getNode( "D" ), true );
3104             if ( t13.getNumberOfExternalNodes() != 4 ) {
3105                 return false;
3106             }
3107             s = w.toNewHampshire( t13, false, true ).toString();
3108             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3109                 return false;
3110             }
3111             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3112             t14.deleteSubtree( t14.getNode( "E" ), true );
3113             if ( t14.getNumberOfExternalNodes() != 5 ) {
3114                 return false;
3115             }
3116             s = w.toNewHampshire( t14, false, true ).toString();
3117             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3118                 return false;
3119             }
3120             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3121             t15.deleteSubtree( t15.getNode( "B2" ), true );
3122             if ( t15.getNumberOfExternalNodes() != 11 ) {
3123                 return false;
3124             }
3125             t15.deleteSubtree( t15.getNode( "B1" ), true );
3126             if ( t15.getNumberOfExternalNodes() != 10 ) {
3127                 return false;
3128             }
3129             t15.deleteSubtree( t15.getNode( "B3" ), true );
3130             if ( t15.getNumberOfExternalNodes() != 9 ) {
3131                 return false;
3132             }
3133             t15.deleteSubtree( t15.getNode( "B4" ), true );
3134             if ( t15.getNumberOfExternalNodes() != 8 ) {
3135                 return false;
3136             }
3137             t15.deleteSubtree( t15.getNode( "A1" ), true );
3138             if ( t15.getNumberOfExternalNodes() != 7 ) {
3139                 return false;
3140             }
3141             t15.deleteSubtree( t15.getNode( "C4" ), true );
3142             if ( t15.getNumberOfExternalNodes() != 6 ) {
3143                 return false;
3144             }
3145         }
3146         catch ( final Exception e ) {
3147             e.printStackTrace( System.out );
3148             return false;
3149         }
3150         return true;
3151     }
3152
3153     private static boolean testDescriptiveStatistics() {
3154         try {
3155             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3156             dss1.addValue( 82 );
3157             dss1.addValue( 78 );
3158             dss1.addValue( 70 );
3159             dss1.addValue( 58 );
3160             dss1.addValue( 42 );
3161             if ( dss1.getN() != 5 ) {
3162                 return false;
3163             }
3164             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3165                 return false;
3166             }
3167             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3168                 return false;
3169             }
3170             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3171                 return false;
3172             }
3173             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3174                 return false;
3175             }
3176             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3177                 return false;
3178             }
3179             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3180                 return false;
3181             }
3182             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3183                 return false;
3184             }
3185             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3186                 return false;
3187             }
3188             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3189                 return false;
3190             }
3191             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3192                 return false;
3193             }
3194             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3195                 return false;
3196             }
3197             dss1.addValue( 123 );
3198             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3199                 return false;
3200             }
3201             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3202                 return false;
3203             }
3204             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3205                 return false;
3206             }
3207             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3208             dss2.addValue( -1.85 );
3209             dss2.addValue( 57.5 );
3210             dss2.addValue( 92.78 );
3211             dss2.addValue( 57.78 );
3212             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3213                 return false;
3214             }
3215             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3216                 return false;
3217             }
3218             final double[] a = dss2.getDataAsDoubleArray();
3219             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3220                 return false;
3221             }
3222             dss2.addValue( -100 );
3223             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3224                 return false;
3225             }
3226             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3227                 return false;
3228             }
3229             final double[] ds = new double[ 14 ];
3230             ds[ 0 ] = 34;
3231             ds[ 1 ] = 23;
3232             ds[ 2 ] = 1;
3233             ds[ 3 ] = 32;
3234             ds[ 4 ] = 11;
3235             ds[ 5 ] = 2;
3236             ds[ 6 ] = 12;
3237             ds[ 7 ] = 33;
3238             ds[ 8 ] = 13;
3239             ds[ 9 ] = 22;
3240             ds[ 10 ] = 21;
3241             ds[ 11 ] = 35;
3242             ds[ 12 ] = 24;
3243             ds[ 13 ] = 31;
3244             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3245             if ( bins.length != 4 ) {
3246                 return false;
3247             }
3248             if ( bins[ 0 ] != 2 ) {
3249                 return false;
3250             }
3251             if ( bins[ 1 ] != 3 ) {
3252                 return false;
3253             }
3254             if ( bins[ 2 ] != 4 ) {
3255                 return false;
3256             }
3257             if ( bins[ 3 ] != 5 ) {
3258                 return false;
3259             }
3260             final double[] ds1 = new double[ 9 ];
3261             ds1[ 0 ] = 10.0;
3262             ds1[ 1 ] = 19.0;
3263             ds1[ 2 ] = 9.999;
3264             ds1[ 3 ] = 0.0;
3265             ds1[ 4 ] = 39.9;
3266             ds1[ 5 ] = 39.999;
3267             ds1[ 6 ] = 30.0;
3268             ds1[ 7 ] = 19.999;
3269             ds1[ 8 ] = 30.1;
3270             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3271             if ( bins1.length != 4 ) {
3272                 return false;
3273             }
3274             if ( bins1[ 0 ] != 2 ) {
3275                 return false;
3276             }
3277             if ( bins1[ 1 ] != 3 ) {
3278                 return false;
3279             }
3280             if ( bins1[ 2 ] != 0 ) {
3281                 return false;
3282             }
3283             if ( bins1[ 3 ] != 4 ) {
3284                 return false;
3285             }
3286             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3287             if ( bins1_1.length != 3 ) {
3288                 return false;
3289             }
3290             if ( bins1_1[ 0 ] != 3 ) {
3291                 return false;
3292             }
3293             if ( bins1_1[ 1 ] != 2 ) {
3294                 return false;
3295             }
3296             if ( bins1_1[ 2 ] != 4 ) {
3297                 return false;
3298             }
3299             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3300             if ( bins1_2.length != 3 ) {
3301                 return false;
3302             }
3303             if ( bins1_2[ 0 ] != 2 ) {
3304                 return false;
3305             }
3306             if ( bins1_2[ 1 ] != 2 ) {
3307                 return false;
3308             }
3309             if ( bins1_2[ 2 ] != 2 ) {
3310                 return false;
3311             }
3312             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3313             dss3.addValue( 1 );
3314             dss3.addValue( 1 );
3315             dss3.addValue( 1 );
3316             dss3.addValue( 2 );
3317             dss3.addValue( 3 );
3318             dss3.addValue( 4 );
3319             dss3.addValue( 5 );
3320             dss3.addValue( 5 );
3321             dss3.addValue( 5 );
3322             dss3.addValue( 6 );
3323             dss3.addValue( 7 );
3324             dss3.addValue( 8 );
3325             dss3.addValue( 9 );
3326             dss3.addValue( 10 );
3327             dss3.addValue( 10 );
3328             dss3.addValue( 10 );
3329             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3330             histo.toStringBuffer( 10, '=', 40, 5 );
3331             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3332         }
3333         catch ( final Exception e ) {
3334             e.printStackTrace( System.out );
3335             return false;
3336         }
3337         return true;
3338     }
3339
3340     private static boolean testDir( final String file ) {
3341         try {
3342             final File f = new File( file );
3343             if ( !f.exists() ) {
3344                 return false;
3345             }
3346             if ( !f.isDirectory() ) {
3347                 return false;
3348             }
3349             if ( !f.canRead() ) {
3350                 return false;
3351             }
3352         }
3353         catch ( final Exception e ) {
3354             return false;
3355         }
3356         return true;
3357     }
3358
3359     private static boolean testEmblEntryRetrieval() {
3360         //The format for GenBank Accession numbers are:
3361         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3362         //Protein:    3 letters + 5 numerals
3363         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3364         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
3365             return false;
3366         }
3367         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3368             return false;
3369         }
3370         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3371             return false;
3372         }
3373         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
3374             return false;
3375         }
3376         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
3377             return false;
3378         }
3379         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
3380             return false;
3381         }
3382         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
3383             return false;
3384         }
3385         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
3386             return false;
3387         }
3388         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
3389             return false;
3390         }
3391         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
3392             return false;
3393         }
3394         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
3395             return false;
3396         }
3397         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
3398             return false;
3399         }
3400         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
3401             return false;
3402         }
3403         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
3404             return false;
3405         }
3406         return true;
3407     }
3408
3409     private static boolean testExternalNodeRelatedMethods() {
3410         try {
3411             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3412             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3413             PhylogenyNode n = t1.getNode( "A" );
3414             n = n.getNextExternalNode();
3415             if ( !n.getName().equals( "B" ) ) {
3416                 return false;
3417             }
3418             n = n.getNextExternalNode();
3419             if ( !n.getName().equals( "C" ) ) {
3420                 return false;
3421             }
3422             n = n.getNextExternalNode();
3423             if ( !n.getName().equals( "D" ) ) {
3424                 return false;
3425             }
3426             n = t1.getNode( "B" );
3427             while ( !n.isLastExternalNode() ) {
3428                 n = n.getNextExternalNode();
3429             }
3430             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3431             n = t2.getNode( "A" );
3432             n = n.getNextExternalNode();
3433             if ( !n.getName().equals( "B" ) ) {
3434                 return false;
3435             }
3436             n = n.getNextExternalNode();
3437             if ( !n.getName().equals( "C" ) ) {
3438                 return false;
3439             }
3440             n = n.getNextExternalNode();
3441             if ( !n.getName().equals( "D" ) ) {
3442                 return false;
3443             }
3444             n = t2.getNode( "B" );
3445             while ( !n.isLastExternalNode() ) {
3446                 n = n.getNextExternalNode();
3447             }
3448             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3449             n = t3.getNode( "A" );
3450             n = n.getNextExternalNode();
3451             if ( !n.getName().equals( "B" ) ) {
3452                 return false;
3453             }
3454             n = n.getNextExternalNode();
3455             if ( !n.getName().equals( "C" ) ) {
3456                 return false;
3457             }
3458             n = n.getNextExternalNode();
3459             if ( !n.getName().equals( "D" ) ) {
3460                 return false;
3461             }
3462             n = n.getNextExternalNode();
3463             if ( !n.getName().equals( "E" ) ) {
3464                 return false;
3465             }
3466             n = n.getNextExternalNode();
3467             if ( !n.getName().equals( "F" ) ) {
3468                 return false;
3469             }
3470             n = n.getNextExternalNode();
3471             if ( !n.getName().equals( "G" ) ) {
3472                 return false;
3473             }
3474             n = n.getNextExternalNode();
3475             if ( !n.getName().equals( "H" ) ) {
3476                 return false;
3477             }
3478             n = t3.getNode( "B" );
3479             while ( !n.isLastExternalNode() ) {
3480                 n = n.getNextExternalNode();
3481             }
3482             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3483             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3484                 final PhylogenyNode node = iter.next();
3485             }
3486             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3487             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3488                 final PhylogenyNode node = iter.next();
3489             }
3490             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3491             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3492             if ( !iter.next().getName().equals( "A" ) ) {
3493                 return false;
3494             }
3495             if ( !iter.next().getName().equals( "B" ) ) {
3496                 return false;
3497             }
3498             if ( !iter.next().getName().equals( "C" ) ) {
3499                 return false;
3500             }
3501             if ( !iter.next().getName().equals( "D" ) ) {
3502                 return false;
3503             }
3504             if ( !iter.next().getName().equals( "E" ) ) {
3505                 return false;
3506             }
3507             if ( !iter.next().getName().equals( "F" ) ) {
3508                 return false;
3509             }
3510             if ( iter.hasNext() ) {
3511                 return false;
3512             }
3513         }
3514         catch ( final Exception e ) {
3515             e.printStackTrace( System.out );
3516             return false;
3517         }
3518         return true;
3519     }
3520
3521     private static boolean testExtractSNFromNodeName() {
3522         try {
3523             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3524                 return false;
3525             }
3526             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3527                     .equals( "Mus musculus musculus" ) ) {
3528                 return false;
3529             }
3530             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3531                     .equals( "Mus musculus musculus" ) ) {
3532                 return false;
3533             }
3534             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3535                 return false;
3536             }
3537             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3538                     .equals( "Mus musculus" ) ) {
3539                 return false;
3540             }
3541         }
3542         catch ( final Exception e ) {
3543             e.printStackTrace( System.out );
3544             return false;
3545         }
3546         return true;
3547     }
3548
3549     private static boolean testExtractTaxonomyCodeFromNodeName() {
3550         try {
3551             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3552                 return false;
3553             }
3554             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3555                     .equals( "SOYBN" ) ) {
3556                 return false;
3557             }
3558             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3559                     .equals( "ARATH" ) ) {
3560                 return false;
3561             }
3562             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3563                     .equals( "ARATH" ) ) {
3564                 return false;
3565             }
3566             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3567                 return false;
3568             }
3569             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3570                 return false;
3571             }
3572             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3573                 return false;
3574             }
3575             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3576                     .equals( "SOYBN" ) ) {
3577                 return false;
3578             }
3579             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3580                     .equals( "SOYBN" ) ) {
3581                 return false;
3582             }
3583             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3584                     .equals( "SOYBN" ) ) {
3585                 return false;
3586             }
3587             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3588                     .equals( "SOYBN" ) ) {
3589                 return false;
3590             }
3591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3592                     .equals( "SOYBN" ) ) {
3593                 return false;
3594             }
3595             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3596                     .equals( "SOYBN" ) ) {
3597                 return false;
3598             }
3599             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3600                     .equals( "SOYBN" ) ) {
3601                 return false;
3602             }
3603             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3604                     .equals( "SOYBN" ) ) {
3605                 return false;
3606             }
3607             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3608                 return false;
3609             }
3610             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3611                     .equals( "SOYBN" ) ) {
3612                 return false;
3613             }
3614             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3615                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3616                 return false;
3617             }
3618             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3619                     .equals( "9YX45" ) ) {
3620                 return false;
3621             }
3622             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3623                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3624                     .equals( "MOUSE" ) ) {
3625                 return false;
3626             }
3627             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3628                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3629                     .equals( "MOUSE" ) ) {
3630                 return false;
3631             }
3632             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3633                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3634                     .equals( "MOUSE" ) ) {
3635                 return false;
3636             }
3637             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3638                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3639                 return false;
3640             }
3641             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3642                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3643                 return false;
3644             }
3645             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3646                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3647                 return false;
3648             }
3649             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3650                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3651                 return false;
3652             }
3653             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3654                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3655                 return false;
3656             }
3657             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3658                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3659                 return false;
3660             }
3661             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3662                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3663                 return false;
3664             }
3665             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3666                     .equals( "RAT" ) ) {
3667                 return false;
3668             }
3669             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3670                     .equals( "PIG" ) ) {
3671                 return false;
3672             }
3673             if ( !ParserUtils
3674                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3675                     .equals( "MOUSE" ) ) {
3676                 return false;
3677             }
3678             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3679                     .equals( "MOUSE" ) ) {
3680                 return false;
3681             }
3682             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3683                 return false;
3684             }
3685         }
3686         catch ( final Exception e ) {
3687             e.printStackTrace( System.out );
3688             return false;
3689         }
3690         return true;
3691     }
3692
3693     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3694         try {
3695             PhylogenyNode n = new PhylogenyNode();
3696             n.setName( "tr|B3RJ64" );
3697             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3698                 return false;
3699             }
3700             n.setName( "tr.B3RJ64" );
3701             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3702                 return false;
3703             }
3704             n.setName( "tr=B3RJ64" );
3705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3706                 return false;
3707             }
3708             n.setName( "tr-B3RJ64" );
3709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3710                 return false;
3711             }
3712             n.setName( "tr/B3RJ64" );
3713             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3714                 return false;
3715             }
3716             n.setName( "tr\\B3RJ64" );
3717             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3718                 return false;
3719             }
3720             n.setName( "tr_B3RJ64" );
3721             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3722                 return false;
3723             }
3724             n.setName( " tr|B3RJ64 " );
3725             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3726                 return false;
3727             }
3728             n.setName( "-tr|B3RJ64-" );
3729             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3730                 return false;
3731             }
3732             n.setName( "-tr=B3RJ64-" );
3733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3734                 return false;
3735             }
3736             n.setName( "_tr=B3RJ64_" );
3737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3738                 return false;
3739             }
3740             n.setName( " tr_tr|B3RJ64_sp|123 " );
3741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3742                 return false;
3743             }
3744             n.setName( "B3RJ64" );
3745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3746                 return false;
3747             }
3748             n.setName( "sp|B3RJ64" );
3749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3750                 return false;
3751             }
3752             n.setName( "sp|B3RJ64C" );
3753             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3754                 return false;
3755             }
3756             n.setName( "sp B3RJ64" );
3757             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3758                 return false;
3759             }
3760             n.setName( "sp|B3RJ6X" );
3761             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3762                 return false;
3763             }
3764             n.setName( "sp|B3RJ6" );
3765             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3766                 return false;
3767             }
3768             n.setName( "K1PYK7_CRAGI" );
3769             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3770                 return false;
3771             }
3772             n.setName( "K1PYK7_PEA" );
3773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
3774                 return false;
3775             }
3776             n.setName( "K1PYK7_RAT" );
3777             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
3778                 return false;
3779             }
3780             n.setName( "K1PYK7_PIG" );
3781             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3782                 return false;
3783             }
3784             n.setName( "~K1PYK7_PIG~" );
3785             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3786                 return false;
3787             }
3788             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3789             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3790                 return false;
3791             }
3792             n.setName( "K1PYKX_CRAGI" );
3793             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3794                 return false;
3795             }
3796             n.setName( "XXXXX_CRAGI" );
3797             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
3798                 return false;
3799             }
3800             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3801             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
3802                 return false;
3803             }
3804             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3805             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3806                 return false;
3807             }
3808             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3809             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
3810                 return false;
3811             }
3812             n = new PhylogenyNode();
3813             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3814             seq.setSymbol( "K1PYK7_CRAGI" );
3815             n.getNodeData().addSequence( seq );
3816             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3817                 return false;
3818             }
3819             seq.setSymbol( "tr|B3RJ64" );
3820             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3821                 return false;
3822             }
3823             n = new PhylogenyNode();
3824             seq = new org.forester.phylogeny.data.Sequence();
3825             seq.setName( "K1PYK7_CRAGI" );
3826             n.getNodeData().addSequence( seq );
3827             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3828                 return false;
3829             }
3830             seq.setName( "tr|B3RJ64" );
3831             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3832                 return false;
3833             }
3834             n = new PhylogenyNode();
3835             seq = new org.forester.phylogeny.data.Sequence();
3836             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
3837             n.getNodeData().addSequence( seq );
3838             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
3839                 return false;
3840             }
3841             n = new PhylogenyNode();
3842             seq = new org.forester.phylogeny.data.Sequence();
3843             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
3844             n.getNodeData().addSequence( seq );
3845             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3846                 return false;
3847             }
3848             //
3849             n = new PhylogenyNode();
3850             n.setName( "ACP19736" );
3851             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3852                 return false;
3853             }
3854             n = new PhylogenyNode();
3855             n.setName( "|ACP19736|" );
3856             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3857                 return false;
3858             }
3859         }
3860         catch ( final Exception e ) {
3861             e.printStackTrace( System.out );
3862             return false;
3863         }
3864         return true;
3865     }
3866
3867     private static boolean testFastaParser() {
3868         try {
3869             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
3870                 return false;
3871             }
3872             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
3873                 return false;
3874             }
3875             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
3876             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
3877                 return false;
3878             }
3879             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
3880                 return false;
3881             }
3882             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
3883                 return false;
3884             }
3885             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
3886                 return false;
3887             }
3888             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
3889                 return false;
3890             }
3891             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
3892                 return false;
3893             }
3894         }
3895         catch ( final Exception e ) {
3896             e.printStackTrace();
3897             return false;
3898         }
3899         return true;
3900     }
3901
3902     private static boolean testGeneralMsaParser() {
3903         try {
3904             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
3905             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
3906             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
3907             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
3908             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
3909             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
3910             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
3911             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
3912             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3913                 return false;
3914             }
3915             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3916                 return false;
3917             }
3918             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3919                 return false;
3920             }
3921             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3922                 return false;
3923             }
3924             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3925                 return false;
3926             }
3927             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3928                 return false;
3929             }
3930             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3931                 return false;
3932             }
3933             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3934                 return false;
3935             }
3936             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3937                 return false;
3938             }
3939             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3940                 return false;
3941             }
3942             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3943                 return false;
3944             }
3945             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3946                 return false;
3947             }
3948             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
3949             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3950                 return false;
3951             }
3952             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3953                 return false;
3954             }
3955             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3956                 return false;
3957             }
3958             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
3959             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
3960                 return false;
3961             }
3962             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
3963                 return false;
3964             }
3965             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
3966                 return false;
3967             }
3968             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
3969             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3970                 return false;
3971             }
3972             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3973                 return false;
3974             }
3975             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3976                 return false;
3977             }
3978         }
3979         catch ( final Exception e ) {
3980             e.printStackTrace();
3981             return false;
3982         }
3983         return true;
3984     }
3985
3986     private static boolean testGeneralTable() {
3987         try {
3988             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3989             t0.setValue( 3, 2, "23" );
3990             t0.setValue( 10, 1, "error" );
3991             t0.setValue( 10, 1, "110" );
3992             t0.setValue( 9, 1, "19" );
3993             t0.setValue( 1, 10, "101" );
3994             t0.setValue( 10, 10, "1010" );
3995             t0.setValue( 100, 10, "10100" );
3996             t0.setValue( 0, 0, "00" );
3997             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3998                 return false;
3999             }
4000             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4001                 return false;
4002             }
4003             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4004                 return false;
4005             }
4006             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4007                 return false;
4008             }
4009             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4010                 return false;
4011             }
4012             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4013                 return false;
4014             }
4015             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4016                 return false;
4017             }
4018             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4019                 return false;
4020             }
4021             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4022                 return false;
4023             }
4024             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4025             t1.setValue( "3", "2", "23" );
4026             t1.setValue( "10", "1", "error" );
4027             t1.setValue( "10", "1", "110" );
4028             t1.setValue( "9", "1", "19" );
4029             t1.setValue( "1", "10", "101" );
4030             t1.setValue( "10", "10", "1010" );
4031             t1.setValue( "100", "10", "10100" );
4032             t1.setValue( "0", "0", "00" );
4033             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4034             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4035                 return false;
4036             }
4037             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4038                 return false;
4039             }
4040             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4041                 return false;
4042             }
4043             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4044                 return false;
4045             }
4046             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4047                 return false;
4048             }
4049             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4050                 return false;
4051             }
4052             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4053                 return false;
4054             }
4055             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4056                 return false;
4057             }
4058             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4059                 return false;
4060             }
4061             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4062                 return false;
4063             }
4064         }
4065         catch ( final Exception e ) {
4066             e.printStackTrace( System.out );
4067             return false;
4068         }
4069         return true;
4070     }
4071
4072     private static boolean testGetDistance() {
4073         try {
4074             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4075             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",
4076                                                  new NHXParser() )[ 0 ];
4077             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4078                 return false;
4079             }
4080             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4081                 return false;
4082             }
4083             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4084                 return false;
4085             }
4086             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4087                 return false;
4088             }
4089             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4090                 return false;
4091             }
4092             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4093                 return false;
4094             }
4095             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4096                 return false;
4097             }
4098             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4099                 return false;
4100             }
4101             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4102                 return false;
4103             }
4104             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4105                 return false;
4106             }
4107             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4108                 return false;
4109             }
4110             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4111                 return false;
4112             }
4113             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4114                 return false;
4115             }
4116             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4117                 return false;
4118             }
4119             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4120                 return false;
4121             }
4122             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4123                 return false;
4124             }
4125             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4126                 return false;
4127             }
4128             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4129                 return false;
4130             }
4131             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4132                 return false;
4133             }
4134             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4135                 return false;
4136             }
4137             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4138                 return false;
4139             }
4140             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4141                 return false;
4142             }
4143             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4144                 return false;
4145             }
4146             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4147                 return false;
4148             }
4149             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4150                 return false;
4151             }
4152             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4153                 return false;
4154             }
4155             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4156                 return false;
4157             }
4158             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4159                 return false;
4160             }
4161             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4162                 return false;
4163             }
4164             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4165                 return false;
4166             }
4167             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4168                 return false;
4169             }
4170             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",
4171                                                  new NHXParser() )[ 0 ];
4172             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4173                 return false;
4174             }
4175             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4176                 return false;
4177             }
4178             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4179                 return false;
4180             }
4181             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4182                 return false;
4183             }
4184             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4185                 return false;
4186             }
4187             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4188                 return false;
4189             }
4190             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4191                 return false;
4192             }
4193             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4194                 return false;
4195             }
4196             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4197                 return false;
4198             }
4199             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4200                 return false;
4201             }
4202             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4203                 return false;
4204             }
4205         }
4206         catch ( final Exception e ) {
4207             e.printStackTrace( System.out );
4208             return false;
4209         }
4210         return true;
4211     }
4212
4213     private static boolean testGetLCA() {
4214         try {
4215             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4216             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4217                                                  new NHXParser() )[ 0 ];
4218             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4219             if ( !A.getName().equals( "A" ) ) {
4220                 return false;
4221             }
4222             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4223             if ( !gh.getName().equals( "gh" ) ) {
4224                 return false;
4225             }
4226             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4227             if ( !ab.getName().equals( "ab" ) ) {
4228                 return false;
4229             }
4230             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4231             if ( !ab2.getName().equals( "ab" ) ) {
4232                 return false;
4233             }
4234             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4235             if ( !gh2.getName().equals( "gh" ) ) {
4236                 return false;
4237             }
4238             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4239             if ( !gh3.getName().equals( "gh" ) ) {
4240                 return false;
4241             }
4242             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4243             if ( !abc.getName().equals( "abc" ) ) {
4244                 return false;
4245             }
4246             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4247             if ( !abc2.getName().equals( "abc" ) ) {
4248                 return false;
4249             }
4250             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4251             if ( !abcd.getName().equals( "abcd" ) ) {
4252                 return false;
4253             }
4254             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4255             if ( !abcd2.getName().equals( "abcd" ) ) {
4256                 return false;
4257             }
4258             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4259             if ( !abcdef.getName().equals( "abcdef" ) ) {
4260                 return false;
4261             }
4262             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4263             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4264                 return false;
4265             }
4266             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4267             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4268                 return false;
4269             }
4270             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4271             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4272                 return false;
4273             }
4274             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4275             if ( !abcde.getName().equals( "abcde" ) ) {
4276                 return false;
4277             }
4278             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4279             if ( !abcde2.getName().equals( "abcde" ) ) {
4280                 return false;
4281             }
4282             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4283             if ( !r.getName().equals( "abcdefgh" ) ) {
4284                 return false;
4285             }
4286             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4287             if ( !r2.getName().equals( "abcdefgh" ) ) {
4288                 return false;
4289             }
4290             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4291             if ( !r3.getName().equals( "abcdefgh" ) ) {
4292                 return false;
4293             }
4294             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4295             if ( !abcde3.getName().equals( "abcde" ) ) {
4296                 return false;
4297             }
4298             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4299             if ( !abcde4.getName().equals( "abcde" ) ) {
4300                 return false;
4301             }
4302             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4303             if ( !ab3.getName().equals( "ab" ) ) {
4304                 return false;
4305             }
4306             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4307             if ( !ab4.getName().equals( "ab" ) ) {
4308                 return false;
4309             }
4310             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4311             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4312             if ( !cd.getName().equals( "cd" ) ) {
4313                 return false;
4314             }
4315             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4316             if ( !cd2.getName().equals( "cd" ) ) {
4317                 return false;
4318             }
4319             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4320             if ( !cde.getName().equals( "cde" ) ) {
4321                 return false;
4322             }
4323             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4324             if ( !cde2.getName().equals( "cde" ) ) {
4325                 return false;
4326             }
4327             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4328             if ( !cdef.getName().equals( "cdef" ) ) {
4329                 return false;
4330             }
4331             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4332             if ( !cdef2.getName().equals( "cdef" ) ) {
4333                 return false;
4334             }
4335             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4336             if ( !cdef3.getName().equals( "cdef" ) ) {
4337                 return false;
4338             }
4339             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4340             if ( !rt.getName().equals( "r" ) ) {
4341                 return false;
4342             }
4343             final Phylogeny p3 = factory
4344                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4345                              new NHXParser() )[ 0 ];
4346             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4347             if ( !bc_3.getName().equals( "bc" ) ) {
4348                 return false;
4349             }
4350             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4351             if ( !ac_3.getName().equals( "abc" ) ) {
4352                 return false;
4353             }
4354             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4355             if ( !ad_3.getName().equals( "abcde" ) ) {
4356                 return false;
4357             }
4358             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4359             if ( !af_3.getName().equals( "abcdef" ) ) {
4360                 return false;
4361             }
4362             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4363             if ( !ag_3.getName().equals( "" ) ) {
4364                 return false;
4365             }
4366             if ( !ag_3.isRoot() ) {
4367                 return false;
4368             }
4369             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4370             if ( !al_3.getName().equals( "" ) ) {
4371                 return false;
4372             }
4373             if ( !al_3.isRoot() ) {
4374                 return false;
4375             }
4376             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4377             if ( !kl_3.getName().equals( "" ) ) {
4378                 return false;
4379             }
4380             if ( !kl_3.isRoot() ) {
4381                 return false;
4382             }
4383             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4384             if ( !fl_3.getName().equals( "" ) ) {
4385                 return false;
4386             }
4387             if ( !fl_3.isRoot() ) {
4388                 return false;
4389             }
4390             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4391             if ( !gk_3.getName().equals( "ghijk" ) ) {
4392                 return false;
4393             }
4394             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4395             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4396             if ( !r_4.getName().equals( "r" ) ) {
4397                 return false;
4398             }
4399             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4400             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4401             if ( !r_5.getName().equals( "root" ) ) {
4402                 return false;
4403             }
4404             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4405             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4406             if ( !r_6.getName().equals( "rot" ) ) {
4407                 return false;
4408             }
4409             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4410             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4411             if ( !r_7.getName().equals( "rott" ) ) {
4412                 return false;
4413             }
4414         }
4415         catch ( final Exception e ) {
4416             e.printStackTrace( System.out );
4417             return false;
4418         }
4419         return true;
4420     }
4421
4422     private static boolean testGetLCA2() {
4423         try {
4424             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4425             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4426             PhylogenyMethods.preOrderReId( p_a );
4427             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4428                                                                                               p_a.getNode( "a" ) );
4429             if ( !p_a_1.getName().equals( "a" ) ) {
4430                 return false;
4431             }
4432             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4433             PhylogenyMethods.preOrderReId( p_b );
4434             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4435                                                                                               p_b.getNode( "a" ) );
4436             if ( !p_b_1.getName().equals( "b" ) ) {
4437                 return false;
4438             }
4439             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4440                                                                                               p_b.getNode( "b" ) );
4441             if ( !p_b_2.getName().equals( "b" ) ) {
4442                 return false;
4443             }
4444             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4445             PhylogenyMethods.preOrderReId( p_c );
4446             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4447                                                                                               p_c.getNode( "a" ) );
4448             if ( !p_c_1.getName().equals( "b" ) ) {
4449                 return false;
4450             }
4451             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4452                                                                                               p_c.getNode( "c" ) );
4453             if ( !p_c_2.getName().equals( "c" ) ) {
4454                 System.out.println( p_c_2.getName() );
4455                 System.exit( -1 );
4456                 return false;
4457             }
4458             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4459                                                                                               p_c.getNode( "b" ) );
4460             if ( !p_c_3.getName().equals( "b" ) ) {
4461                 return false;
4462             }
4463             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4464                                                                                               p_c.getNode( "a" ) );
4465             if ( !p_c_4.getName().equals( "c" ) ) {
4466                 return false;
4467             }
4468             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4469                                                  new NHXParser() )[ 0 ];
4470             PhylogenyMethods.preOrderReId( p1 );
4471             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4472                                                                                           p1.getNode( "A" ) );
4473             if ( !A.getName().equals( "A" ) ) {
4474                 return false;
4475             }
4476             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4477                                                                                            p1.getNode( "gh" ) );
4478             if ( !gh.getName().equals( "gh" ) ) {
4479                 return false;
4480             }
4481             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4482                                                                                            p1.getNode( "B" ) );
4483             if ( !ab.getName().equals( "ab" ) ) {
4484                 return false;
4485             }
4486             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4487                                                                                             p1.getNode( "A" ) );
4488             if ( !ab2.getName().equals( "ab" ) ) {
4489                 return false;
4490             }
4491             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4492                                                                                             p1.getNode( "G" ) );
4493             if ( !gh2.getName().equals( "gh" ) ) {
4494                 return false;
4495             }
4496             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4497                                                                                             p1.getNode( "H" ) );
4498             if ( !gh3.getName().equals( "gh" ) ) {
4499                 return false;
4500             }
4501             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4502                                                                                             p1.getNode( "A" ) );
4503             if ( !abc.getName().equals( "abc" ) ) {
4504                 return false;
4505             }
4506             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4507                                                                                              p1.getNode( "C" ) );
4508             if ( !abc2.getName().equals( "abc" ) ) {
4509                 return false;
4510             }
4511             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4512                                                                                              p1.getNode( "D" ) );
4513             if ( !abcd.getName().equals( "abcd" ) ) {
4514                 return false;
4515             }
4516             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4517                                                                                               p1.getNode( "A" ) );
4518             if ( !abcd2.getName().equals( "abcd" ) ) {
4519                 return false;
4520             }
4521             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4522                                                                                                p1.getNode( "F" ) );
4523             if ( !abcdef.getName().equals( "abcdef" ) ) {
4524                 return false;
4525             }
4526             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4527                                                                                                 p1.getNode( "A" ) );
4528             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4529                 return false;
4530             }
4531             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4532                                                                                                 p1.getNode( "F" ) );
4533             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4534                 return false;
4535             }
4536             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4537                                                                                                 p1.getNode( "ab" ) );
4538             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4539                 return false;
4540             }
4541             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4542                                                                                               p1.getNode( "E" ) );
4543             if ( !abcde.getName().equals( "abcde" ) ) {
4544                 return false;
4545             }
4546             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4547                                                                                                p1.getNode( "A" ) );
4548             if ( !abcde2.getName().equals( "abcde" ) ) {
4549                 return false;
4550             }
4551             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4552                                                                                           p1.getNode( "abcdefgh" ) );
4553             if ( !r.getName().equals( "abcdefgh" ) ) {
4554                 return false;
4555             }
4556             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4557                                                                                            p1.getNode( "H" ) );
4558             if ( !r2.getName().equals( "abcdefgh" ) ) {
4559                 return false;
4560             }
4561             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4562                                                                                            p1.getNode( "A" ) );
4563             if ( !r3.getName().equals( "abcdefgh" ) ) {
4564                 return false;
4565             }
4566             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4567                                                                                                p1.getNode( "abcde" ) );
4568             if ( !abcde3.getName().equals( "abcde" ) ) {
4569                 return false;
4570             }
4571             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4572                                                                                                p1.getNode( "E" ) );
4573             if ( !abcde4.getName().equals( "abcde" ) ) {
4574                 return false;
4575             }
4576             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4577                                                                                             p1.getNode( "B" ) );
4578             if ( !ab3.getName().equals( "ab" ) ) {
4579                 return false;
4580             }
4581             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4582                                                                                             p1.getNode( "ab" ) );
4583             if ( !ab4.getName().equals( "ab" ) ) {
4584                 return false;
4585             }
4586             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4587             PhylogenyMethods.preOrderReId( p2 );
4588             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4589                                                                                            p2.getNode( "d" ) );
4590             if ( !cd.getName().equals( "cd" ) ) {
4591                 return false;
4592             }
4593             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4594                                                                                             p2.getNode( "c" ) );
4595             if ( !cd2.getName().equals( "cd" ) ) {
4596                 return false;
4597             }
4598             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4599                                                                                             p2.getNode( "e" ) );
4600             if ( !cde.getName().equals( "cde" ) ) {
4601                 return false;
4602             }
4603             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4604                                                                                              p2.getNode( "c" ) );
4605             if ( !cde2.getName().equals( "cde" ) ) {
4606                 return false;
4607             }
4608             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4609                                                                                              p2.getNode( "f" ) );
4610             if ( !cdef.getName().equals( "cdef" ) ) {
4611                 return false;
4612             }
4613             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4614                                                                                               p2.getNode( "f" ) );
4615             if ( !cdef2.getName().equals( "cdef" ) ) {
4616                 return false;
4617             }
4618             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4619                                                                                               p2.getNode( "d" ) );
4620             if ( !cdef3.getName().equals( "cdef" ) ) {
4621                 return false;
4622             }
4623             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4624                                                                                            p2.getNode( "a" ) );
4625             if ( !rt.getName().equals( "r" ) ) {
4626                 return false;
4627             }
4628             final Phylogeny p3 = factory
4629                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4630                              new NHXParser() )[ 0 ];
4631             PhylogenyMethods.preOrderReId( p3 );
4632             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4633                                                                                              p3.getNode( "c" ) );
4634             if ( !bc_3.getName().equals( "bc" ) ) {
4635                 return false;
4636             }
4637             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4638                                                                                              p3.getNode( "c" ) );
4639             if ( !ac_3.getName().equals( "abc" ) ) {
4640                 return false;
4641             }
4642             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4643                                                                                              p3.getNode( "d" ) );
4644             if ( !ad_3.getName().equals( "abcde" ) ) {
4645                 return false;
4646             }
4647             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4648                                                                                              p3.getNode( "f" ) );
4649             if ( !af_3.getName().equals( "abcdef" ) ) {
4650                 return false;
4651             }
4652             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4653                                                                                              p3.getNode( "g" ) );
4654             if ( !ag_3.getName().equals( "" ) ) {
4655                 return false;
4656             }
4657             if ( !ag_3.isRoot() ) {
4658                 return false;
4659             }
4660             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4661                                                                                              p3.getNode( "l" ) );
4662             if ( !al_3.getName().equals( "" ) ) {
4663                 return false;
4664             }
4665             if ( !al_3.isRoot() ) {
4666                 return false;
4667             }
4668             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4669                                                                                              p3.getNode( "l" ) );
4670             if ( !kl_3.getName().equals( "" ) ) {
4671                 return false;
4672             }
4673             if ( !kl_3.isRoot() ) {
4674                 return false;
4675             }
4676             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4677                                                                                              p3.getNode( "l" ) );
4678             if ( !fl_3.getName().equals( "" ) ) {
4679                 return false;
4680             }
4681             if ( !fl_3.isRoot() ) {
4682                 return false;
4683             }
4684             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4685                                                                                              p3.getNode( "k" ) );
4686             if ( !gk_3.getName().equals( "ghijk" ) ) {
4687                 return false;
4688             }
4689             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4690             PhylogenyMethods.preOrderReId( p4 );
4691             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4692                                                                                             p4.getNode( "c" ) );
4693             if ( !r_4.getName().equals( "r" ) ) {
4694                 return false;
4695             }
4696             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4697             PhylogenyMethods.preOrderReId( p5 );
4698             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4699                                                                                             p5.getNode( "c" ) );
4700             if ( !r_5.getName().equals( "root" ) ) {
4701                 return false;
4702             }
4703             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4704             PhylogenyMethods.preOrderReId( p6 );
4705             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4706                                                                                             p6.getNode( "a" ) );
4707             if ( !r_6.getName().equals( "rot" ) ) {
4708                 return false;
4709             }
4710             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4711             PhylogenyMethods.preOrderReId( p7 );
4712             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4713                                                                                             p7.getNode( "e" ) );
4714             if ( !r_7.getName().equals( "rott" ) ) {
4715                 return false;
4716             }
4717             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4718                                                                                              p7.getNode( "a" ) );
4719             if ( !r_71.getName().equals( "rott" ) ) {
4720                 return false;
4721             }
4722             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4723                                                                                              p7.getNode( "rott" ) );
4724             if ( !r_72.getName().equals( "rott" ) ) {
4725                 return false;
4726             }
4727             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4728                                                                                              p7.getNode( "a" ) );
4729             if ( !r_73.getName().equals( "rott" ) ) {
4730                 return false;
4731             }
4732             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4733                                                                                              p7.getNode( "rott" ) );
4734             if ( !r_74.getName().equals( "rott" ) ) {
4735                 return false;
4736             }
4737             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4738                                                                                              p7.getNode( "e" ) );
4739             if ( !r_75.getName().equals( "e" ) ) {
4740                 return false;
4741             }
4742         }
4743         catch ( final Exception e ) {
4744             e.printStackTrace( System.out );
4745             return false;
4746         }
4747         return true;
4748     }
4749
4750     private static boolean testHmmscanOutputParser() {
4751         final String test_dir = Test.PATH_TO_TEST_DATA;
4752         try {
4753             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4754                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4755             parser1.parse();
4756             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4757                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4758             final List<Protein> proteins = parser2.parse();
4759             if ( parser2.getProteinsEncountered() != 4 ) {
4760                 return false;
4761             }
4762             if ( proteins.size() != 4 ) {
4763                 return false;
4764             }
4765             if ( parser2.getDomainsEncountered() != 69 ) {
4766                 return false;
4767             }
4768             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4769                 return false;
4770             }
4771             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4772                 return false;
4773             }
4774             final Protein p1 = proteins.get( 0 );
4775             if ( p1.getNumberOfProteinDomains() != 15 ) {
4776                 return false;
4777             }
4778             if ( p1.getLength() != 850 ) {
4779                 return false;
4780             }
4781             final Protein p2 = proteins.get( 1 );
4782             if ( p2.getNumberOfProteinDomains() != 51 ) {
4783                 return false;
4784             }
4785             if ( p2.getLength() != 1291 ) {
4786                 return false;
4787             }
4788             final Protein p3 = proteins.get( 2 );
4789             if ( p3.getNumberOfProteinDomains() != 2 ) {
4790                 return false;
4791             }
4792             final Protein p4 = proteins.get( 3 );
4793             if ( p4.getNumberOfProteinDomains() != 1 ) {
4794                 return false;
4795             }
4796             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4797                 return false;
4798             }
4799             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4800                 return false;
4801             }
4802             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4803                 return false;
4804             }
4805             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4806                 return false;
4807             }
4808             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4809                 return false;
4810             }
4811             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4812                 return false;
4813             }
4814             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4815                 return false;
4816             }
4817             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4818                 return false;
4819             }
4820             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4821                 return false;
4822             }
4823         }
4824         catch ( final Exception e ) {
4825             e.printStackTrace( System.out );
4826             return false;
4827         }
4828         return true;
4829     }
4830
4831     private static boolean testLastExternalNodeMethods() {
4832         try {
4833             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4834             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4835             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4836             final PhylogenyNode n1 = t0.getNode( "A" );
4837             if ( n1.isLastExternalNode() ) {
4838                 return false;
4839             }
4840             final PhylogenyNode n2 = t0.getNode( "B" );
4841             if ( n2.isLastExternalNode() ) {
4842                 return false;
4843             }
4844             final PhylogenyNode n3 = t0.getNode( "C" );
4845             if ( n3.isLastExternalNode() ) {
4846                 return false;
4847             }
4848             final PhylogenyNode n4 = t0.getNode( "D" );
4849             if ( !n4.isLastExternalNode() ) {
4850                 return false;
4851             }
4852         }
4853         catch ( final Exception e ) {
4854             e.printStackTrace( System.out );
4855             return false;
4856         }
4857         return true;
4858     }
4859
4860     private static boolean testLevelOrderIterator() {
4861         try {
4862             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4863             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4864             PhylogenyNodeIterator it0;
4865             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4866                 it0.next();
4867             }
4868             for( it0.reset(); it0.hasNext(); ) {
4869                 it0.next();
4870             }
4871             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4872             if ( !it.next().getName().equals( "r" ) ) {
4873                 return false;
4874             }
4875             if ( !it.next().getName().equals( "ab" ) ) {
4876                 return false;
4877             }
4878             if ( !it.next().getName().equals( "cd" ) ) {
4879                 return false;
4880             }
4881             if ( !it.next().getName().equals( "A" ) ) {
4882                 return false;
4883             }
4884             if ( !it.next().getName().equals( "B" ) ) {
4885                 return false;
4886             }
4887             if ( !it.next().getName().equals( "C" ) ) {
4888                 return false;
4889             }
4890             if ( !it.next().getName().equals( "D" ) ) {
4891                 return false;
4892             }
4893             if ( it.hasNext() ) {
4894                 return false;
4895             }
4896             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",
4897                                                  new NHXParser() )[ 0 ];
4898             PhylogenyNodeIterator it2;
4899             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4900                 it2.next();
4901             }
4902             for( it2.reset(); it2.hasNext(); ) {
4903                 it2.next();
4904             }
4905             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4906             if ( !it3.next().getName().equals( "r" ) ) {
4907                 return false;
4908             }
4909             if ( !it3.next().getName().equals( "abc" ) ) {
4910                 return false;
4911             }
4912             if ( !it3.next().getName().equals( "defg" ) ) {
4913                 return false;
4914             }
4915             if ( !it3.next().getName().equals( "A" ) ) {
4916                 return false;
4917             }
4918             if ( !it3.next().getName().equals( "B" ) ) {
4919                 return false;
4920             }
4921             if ( !it3.next().getName().equals( "C" ) ) {
4922                 return false;
4923             }
4924             if ( !it3.next().getName().equals( "D" ) ) {
4925                 return false;
4926             }
4927             if ( !it3.next().getName().equals( "E" ) ) {
4928                 return false;
4929             }
4930             if ( !it3.next().getName().equals( "F" ) ) {
4931                 return false;
4932             }
4933             if ( !it3.next().getName().equals( "G" ) ) {
4934                 return false;
4935             }
4936             if ( !it3.next().getName().equals( "1" ) ) {
4937                 return false;
4938             }
4939             if ( !it3.next().getName().equals( "2" ) ) {
4940                 return false;
4941             }
4942             if ( !it3.next().getName().equals( "3" ) ) {
4943                 return false;
4944             }
4945             if ( !it3.next().getName().equals( "4" ) ) {
4946                 return false;
4947             }
4948             if ( !it3.next().getName().equals( "5" ) ) {
4949                 return false;
4950             }
4951             if ( !it3.next().getName().equals( "6" ) ) {
4952                 return false;
4953             }
4954             if ( !it3.next().getName().equals( "f1" ) ) {
4955                 return false;
4956             }
4957             if ( !it3.next().getName().equals( "f2" ) ) {
4958                 return false;
4959             }
4960             if ( !it3.next().getName().equals( "f3" ) ) {
4961                 return false;
4962             }
4963             if ( !it3.next().getName().equals( "a" ) ) {
4964                 return false;
4965             }
4966             if ( !it3.next().getName().equals( "b" ) ) {
4967                 return false;
4968             }
4969             if ( !it3.next().getName().equals( "f21" ) ) {
4970                 return false;
4971             }
4972             if ( !it3.next().getName().equals( "X" ) ) {
4973                 return false;
4974             }
4975             if ( !it3.next().getName().equals( "Y" ) ) {
4976                 return false;
4977             }
4978             if ( !it3.next().getName().equals( "Z" ) ) {
4979                 return false;
4980             }
4981             if ( it3.hasNext() ) {
4982                 return false;
4983             }
4984             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4985             PhylogenyNodeIterator it4;
4986             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4987                 it4.next();
4988             }
4989             for( it4.reset(); it4.hasNext(); ) {
4990                 it4.next();
4991             }
4992             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4993             if ( !it5.next().getName().equals( "r" ) ) {
4994                 return false;
4995             }
4996             if ( !it5.next().getName().equals( "A" ) ) {
4997                 return false;
4998             }
4999             if ( !it5.next().getName().equals( "B" ) ) {
5000                 return false;
5001             }
5002             if ( !it5.next().getName().equals( "C" ) ) {
5003                 return false;
5004             }
5005             if ( !it5.next().getName().equals( "D" ) ) {
5006                 return false;
5007             }
5008             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5009             PhylogenyNodeIterator it6;
5010             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5011                 it6.next();
5012             }
5013             for( it6.reset(); it6.hasNext(); ) {
5014                 it6.next();
5015             }
5016             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5017             if ( !it7.next().getName().equals( "A" ) ) {
5018                 return false;
5019             }
5020             if ( it.hasNext() ) {
5021                 return false;
5022             }
5023         }
5024         catch ( final Exception e ) {
5025             e.printStackTrace( System.out );
5026             return false;
5027         }
5028         return true;
5029     }
5030
5031     private static boolean testMafft( final String path ) {
5032         try {
5033             final List<String> opts = new ArrayList<String>();
5034             opts.add( "--maxiterate" );
5035             opts.add( "1000" );
5036             opts.add( "--localpair" );
5037             opts.add( "--quiet" );
5038             Msa msa = null;
5039             final MsaInferrer mafft = Mafft.createInstance( path );
5040             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5041             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5042                 return false;
5043             }
5044             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5045                 return false;
5046             }
5047         }
5048         catch ( final Exception e ) {
5049             e.printStackTrace( System.out );
5050             return false;
5051         }
5052         return true;
5053     }
5054
5055     private static boolean testMidpointrooting() {
5056         try {
5057             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5058             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5059             PhylogenyMethods.midpointRoot( t0 );
5060             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5061                 return false;
5062             }
5063             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5064                 return false;
5065             }
5066             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5067                            1 ) ) {
5068                 return false;
5069             }
5070             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",
5071                                                  new NHXParser() )[ 0 ];
5072             if ( !t1.isRooted() ) {
5073                 return false;
5074             }
5075             PhylogenyMethods.midpointRoot( t1 );
5076             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5077                 return false;
5078             }
5079             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5080                 return false;
5081             }
5082             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5083                 return false;
5084             }
5085             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5086                 return false;
5087             }
5088             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5089                 return false;
5090             }
5091             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5092                 return false;
5093             }
5094             t1.reRoot( t1.getNode( "A" ) );
5095             PhylogenyMethods.midpointRoot( t1 );
5096             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5097                 return false;
5098             }
5099             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5100                 return false;
5101             }
5102             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5103                 return false;
5104             }
5105             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5106                 return false;
5107             }
5108             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5109                 System.exit( -1 );
5110                 return false;
5111             }
5112             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5113                 return false;
5114             }
5115         }
5116         catch ( final Exception e ) {
5117             e.printStackTrace( System.out );
5118             return false;
5119         }
5120         return true;
5121     }
5122
5123     private static boolean testMsaQualityMethod() {
5124         try {
5125             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5126             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5127             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5128             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5129             final List<Sequence> l = new ArrayList<Sequence>();
5130             l.add( s0 );
5131             l.add( s1 );
5132             l.add( s2 );
5133             l.add( s3 );
5134             final Msa msa = BasicMsa.createInstance( l );
5135             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5136                 return false;
5137             }
5138             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5139                 return false;
5140             }
5141             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5142                 return false;
5143             }
5144             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5145                 return false;
5146             }
5147         }
5148         catch ( final Exception e ) {
5149             e.printStackTrace( System.out );
5150             return false;
5151         }
5152         return true;
5153     }
5154
5155     private static boolean testNextNodeWithCollapsing() {
5156         try {
5157             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5158             PhylogenyNode n;
5159             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5160             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5161             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5162             t0.getNode( "cd" ).setCollapse( true );
5163             t0.getNode( "cde" ).setCollapse( true );
5164             n = t0.getFirstExternalNode();
5165             while ( n != null ) {
5166                 ext.add( n );
5167                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5168             }
5169             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5170                 return false;
5171             }
5172             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5173                 return false;
5174             }
5175             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5176                 return false;
5177             }
5178             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5179                 return false;
5180             }
5181             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5182                 return false;
5183             }
5184             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5185                 return false;
5186             }
5187             ext.clear();
5188             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5189             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5190             t1.getNode( "ab" ).setCollapse( true );
5191             t1.getNode( "cd" ).setCollapse( true );
5192             t1.getNode( "cde" ).setCollapse( true );
5193             n = t1.getNode( "ab" );
5194             ext = new ArrayList<PhylogenyNode>();
5195             while ( n != null ) {
5196                 ext.add( n );
5197                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5198             }
5199             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5200                 return false;
5201             }
5202             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5203                 return false;
5204             }
5205             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5206                 return false;
5207             }
5208             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5209                 return false;
5210             }
5211             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5212                 return false;
5213             }
5214             //
5215             //
5216             ext.clear();
5217             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5218             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5219             t2.getNode( "ab" ).setCollapse( true );
5220             t2.getNode( "cd" ).setCollapse( true );
5221             t2.getNode( "cde" ).setCollapse( true );
5222             t2.getNode( "c" ).setCollapse( true );
5223             t2.getNode( "d" ).setCollapse( true );
5224             t2.getNode( "e" ).setCollapse( true );
5225             t2.getNode( "gh" ).setCollapse( true );
5226             n = t2.getNode( "ab" );
5227             ext = new ArrayList<PhylogenyNode>();
5228             while ( n != null ) {
5229                 ext.add( n );
5230                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5231             }
5232             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5233                 return false;
5234             }
5235             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5236                 return false;
5237             }
5238             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5239                 return false;
5240             }
5241             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5242                 return false;
5243             }
5244             //
5245             //
5246             ext.clear();
5247             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5248             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5249             t3.getNode( "ab" ).setCollapse( true );
5250             t3.getNode( "cd" ).setCollapse( true );
5251             t3.getNode( "cde" ).setCollapse( true );
5252             t3.getNode( "c" ).setCollapse( true );
5253             t3.getNode( "d" ).setCollapse( true );
5254             t3.getNode( "e" ).setCollapse( true );
5255             t3.getNode( "gh" ).setCollapse( true );
5256             t3.getNode( "fgh" ).setCollapse( true );
5257             n = t3.getNode( "ab" );
5258             ext = new ArrayList<PhylogenyNode>();
5259             while ( n != null ) {
5260                 ext.add( n );
5261                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5262             }
5263             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5264                 return false;
5265             }
5266             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5267                 return false;
5268             }
5269             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5270                 return false;
5271             }
5272             //
5273             //
5274             ext.clear();
5275             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5276             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5277             t4.getNode( "ab" ).setCollapse( true );
5278             t4.getNode( "cd" ).setCollapse( true );
5279             t4.getNode( "cde" ).setCollapse( true );
5280             t4.getNode( "c" ).setCollapse( true );
5281             t4.getNode( "d" ).setCollapse( true );
5282             t4.getNode( "e" ).setCollapse( true );
5283             t4.getNode( "gh" ).setCollapse( true );
5284             t4.getNode( "fgh" ).setCollapse( true );
5285             t4.getNode( "abcdefgh" ).setCollapse( true );
5286             n = t4.getNode( "abcdefgh" );
5287             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5288                 return false;
5289             }
5290             //
5291             //
5292             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5293             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5294             ext.clear();
5295             n = t5.getFirstExternalNode();
5296             while ( n != null ) {
5297                 ext.add( n );
5298                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5299             }
5300             if ( ext.size() != 8 ) {
5301                 return false;
5302             }
5303             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5304                 return false;
5305             }
5306             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5307                 return false;
5308             }
5309             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5310                 return false;
5311             }
5312             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5313                 return false;
5314             }
5315             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5316                 return false;
5317             }
5318             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5319                 return false;
5320             }
5321             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5322                 return false;
5323             }
5324             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5325                 return false;
5326             }
5327             //
5328             //
5329             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5330             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5331             ext.clear();
5332             t6.getNode( "ab" ).setCollapse( true );
5333             n = t6.getNode( "ab" );
5334             while ( n != null ) {
5335                 ext.add( n );
5336                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5337             }
5338             if ( ext.size() != 7 ) {
5339                 return false;
5340             }
5341             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5342                 return false;
5343             }
5344             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5345                 return false;
5346             }
5347             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5348                 return false;
5349             }
5350             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5351                 return false;
5352             }
5353             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5354                 return false;
5355             }
5356             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5357                 return false;
5358             }
5359             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5360                 return false;
5361             }
5362             //
5363             //
5364             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5365             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5366             ext.clear();
5367             t7.getNode( "cd" ).setCollapse( true );
5368             n = t7.getNode( "a" );
5369             while ( n != null ) {
5370                 ext.add( n );
5371                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5372             }
5373             if ( ext.size() != 7 ) {
5374                 return false;
5375             }
5376             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5377                 return false;
5378             }
5379             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5380                 return false;
5381             }
5382             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5383                 return false;
5384             }
5385             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5386                 return false;
5387             }
5388             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5389                 return false;
5390             }
5391             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5392                 return false;
5393             }
5394             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5395                 return false;
5396             }
5397             //
5398             //
5399             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5400             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5401             ext.clear();
5402             t8.getNode( "cd" ).setCollapse( true );
5403             t8.getNode( "c" ).setCollapse( true );
5404             t8.getNode( "d" ).setCollapse( true );
5405             n = t8.getNode( "a" );
5406             while ( n != null ) {
5407                 ext.add( n );
5408                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5409             }
5410             if ( ext.size() != 7 ) {
5411                 return false;
5412             }
5413             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5414                 return false;
5415             }
5416             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5417                 return false;
5418             }
5419             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5420                 System.out.println( "2 fail" );
5421                 return false;
5422             }
5423             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5424                 return false;
5425             }
5426             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5427                 return false;
5428             }
5429             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5430                 return false;
5431             }
5432             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5433                 return false;
5434             }
5435             //
5436             //
5437             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5438             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5439             ext.clear();
5440             t9.getNode( "gh" ).setCollapse( true );
5441             n = t9.getNode( "a" );
5442             while ( n != null ) {
5443                 ext.add( n );
5444                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5445             }
5446             if ( ext.size() != 7 ) {
5447                 return false;
5448             }
5449             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5450                 return false;
5451             }
5452             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5453                 return false;
5454             }
5455             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5456                 return false;
5457             }
5458             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5459                 return false;
5460             }
5461             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5462                 return false;
5463             }
5464             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5465                 return false;
5466             }
5467             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5468                 return false;
5469             }
5470             //
5471             //
5472             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5473             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5474             ext.clear();
5475             t10.getNode( "gh" ).setCollapse( true );
5476             t10.getNode( "g" ).setCollapse( true );
5477             t10.getNode( "h" ).setCollapse( true );
5478             n = t10.getNode( "a" );
5479             while ( n != null ) {
5480                 ext.add( n );
5481                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5482             }
5483             if ( ext.size() != 7 ) {
5484                 return false;
5485             }
5486             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5487                 return false;
5488             }
5489             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5490                 return false;
5491             }
5492             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5493                 return false;
5494             }
5495             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5496                 return false;
5497             }
5498             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5499                 return false;
5500             }
5501             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5502                 return false;
5503             }
5504             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5505                 return false;
5506             }
5507             //
5508             //
5509             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5510             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5511             ext.clear();
5512             t11.getNode( "gh" ).setCollapse( true );
5513             t11.getNode( "fgh" ).setCollapse( true );
5514             n = t11.getNode( "a" );
5515             while ( n != null ) {
5516                 ext.add( n );
5517                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5518             }
5519             if ( ext.size() != 6 ) {
5520                 return false;
5521             }
5522             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5523                 return false;
5524             }
5525             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5526                 return false;
5527             }
5528             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5529                 return false;
5530             }
5531             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5532                 return false;
5533             }
5534             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5535                 return false;
5536             }
5537             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5538                 return false;
5539             }
5540             //
5541             //
5542             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5543             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5544             ext.clear();
5545             t12.getNode( "gh" ).setCollapse( true );
5546             t12.getNode( "fgh" ).setCollapse( true );
5547             t12.getNode( "g" ).setCollapse( true );
5548             t12.getNode( "h" ).setCollapse( true );
5549             t12.getNode( "f" ).setCollapse( true );
5550             n = t12.getNode( "a" );
5551             while ( n != null ) {
5552                 ext.add( n );
5553                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5554             }
5555             if ( ext.size() != 6 ) {
5556                 return false;
5557             }
5558             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5559                 return false;
5560             }
5561             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5562                 return false;
5563             }
5564             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5565                 return false;
5566             }
5567             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5568                 return false;
5569             }
5570             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5571                 return false;
5572             }
5573             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5574                 return false;
5575             }
5576             //
5577             //
5578             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5579             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5580             ext.clear();
5581             t13.getNode( "ab" ).setCollapse( true );
5582             t13.getNode( "b" ).setCollapse( true );
5583             t13.getNode( "fgh" ).setCollapse( true );
5584             t13.getNode( "gh" ).setCollapse( true );
5585             n = t13.getNode( "ab" );
5586             while ( n != null ) {
5587                 ext.add( n );
5588                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5589             }
5590             if ( ext.size() != 5 ) {
5591                 return false;
5592             }
5593             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5594                 return false;
5595             }
5596             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5597                 return false;
5598             }
5599             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5600                 return false;
5601             }
5602             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5603                 return false;
5604             }
5605             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5606                 return false;
5607             }
5608             //
5609             //
5610             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5611             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5612             ext.clear();
5613             t14.getNode( "ab" ).setCollapse( true );
5614             t14.getNode( "a" ).setCollapse( true );
5615             t14.getNode( "fgh" ).setCollapse( true );
5616             t14.getNode( "gh" ).setCollapse( true );
5617             n = t14.getNode( "ab" );
5618             while ( n != null ) {
5619                 ext.add( n );
5620                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5621             }
5622             if ( ext.size() != 5 ) {
5623                 return false;
5624             }
5625             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5626                 return false;
5627             }
5628             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5629                 return false;
5630             }
5631             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5632                 return false;
5633             }
5634             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5635                 return false;
5636             }
5637             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5638                 return false;
5639             }
5640             //
5641             //
5642             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" );
5643             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5644             ext.clear();
5645             t15.getNode( "ab" ).setCollapse( true );
5646             t15.getNode( "a" ).setCollapse( true );
5647             t15.getNode( "fgh" ).setCollapse( true );
5648             t15.getNode( "gh" ).setCollapse( true );
5649             n = t15.getNode( "ab" );
5650             while ( n != null ) {
5651                 ext.add( n );
5652                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5653             }
5654             if ( ext.size() != 6 ) {
5655                 return false;
5656             }
5657             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5658                 return false;
5659             }
5660             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5661                 return false;
5662             }
5663             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5664                 return false;
5665             }
5666             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5667                 return false;
5668             }
5669             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5670                 return false;
5671             }
5672             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5673                 return false;
5674             }
5675             //
5676             //
5677             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" );
5678             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5679             ext.clear();
5680             t16.getNode( "ab" ).setCollapse( true );
5681             t16.getNode( "a" ).setCollapse( true );
5682             t16.getNode( "fgh" ).setCollapse( true );
5683             t16.getNode( "gh" ).setCollapse( true );
5684             t16.getNode( "cd" ).setCollapse( true );
5685             t16.getNode( "cde" ).setCollapse( true );
5686             t16.getNode( "d" ).setCollapse( true );
5687             t16.getNode( "x" ).setCollapse( true );
5688             n = t16.getNode( "ab" );
5689             while ( n != null ) {
5690                 ext.add( n );
5691                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5692             }
5693             if ( ext.size() != 4 ) {
5694                 return false;
5695             }
5696             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5697                 return false;
5698             }
5699             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5700                 return false;
5701             }
5702             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5703                 return false;
5704             }
5705             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5706                 return false;
5707             }
5708         }
5709         catch ( final Exception e ) {
5710             e.printStackTrace( System.out );
5711             return false;
5712         }
5713         return true;
5714     }
5715
5716     private static boolean testNexusCharactersParsing() {
5717         try {
5718             final NexusCharactersParser parser = new NexusCharactersParser();
5719             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5720             parser.parse();
5721             String[] labels = parser.getCharStateLabels();
5722             if ( labels.length != 7 ) {
5723                 return false;
5724             }
5725             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5726                 return false;
5727             }
5728             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5729                 return false;
5730             }
5731             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5732                 return false;
5733             }
5734             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5735                 return false;
5736             }
5737             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5738                 return false;
5739             }
5740             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5741                 return false;
5742             }
5743             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5744                 return false;
5745             }
5746             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5747             parser.parse();
5748             labels = parser.getCharStateLabels();
5749             if ( labels.length != 7 ) {
5750                 return false;
5751             }
5752             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5753                 return false;
5754             }
5755             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5756                 return false;
5757             }
5758             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5759                 return false;
5760             }
5761             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5762                 return false;
5763             }
5764             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5765                 return false;
5766             }
5767             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5768                 return false;
5769             }
5770             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5771                 return false;
5772             }
5773         }
5774         catch ( final Exception e ) {
5775             e.printStackTrace( System.out );
5776             return false;
5777         }
5778         return true;
5779     }
5780
5781     private static boolean testNexusMatrixParsing() {
5782         try {
5783             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5784             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5785             parser.parse();
5786             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5787             if ( m.getNumberOfCharacters() != 9 ) {
5788                 return false;
5789             }
5790             if ( m.getNumberOfIdentifiers() != 5 ) {
5791                 return false;
5792             }
5793             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5794                 return false;
5795             }
5796             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5797                 return false;
5798             }
5799             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5800                 return false;
5801             }
5802             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5803                 return false;
5804             }
5805             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5806                 return false;
5807             }
5808             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5809                 return false;
5810             }
5811             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5812                 return false;
5813             }
5814             //            if ( labels.length != 7 ) {
5815             //                return false;
5816             //            }
5817             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5818             //                return false;
5819             //            }
5820             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5821             //                return false;
5822             //            }
5823             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5824             //                return false;
5825             //            }
5826             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5827             //                return false;
5828             //            }
5829             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5830             //                return false;
5831             //            }
5832             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5833             //                return false;
5834             //            }
5835             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5836             //                return false;
5837             //            }
5838             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5839             //            parser.parse();
5840             //            labels = parser.getCharStateLabels();
5841             //            if ( labels.length != 7 ) {
5842             //                return false;
5843             //            }
5844             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5845             //                return false;
5846             //            }
5847             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5848             //                return false;
5849             //            }
5850             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5851             //                return false;
5852             //            }
5853             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5854             //                return false;
5855             //            }
5856             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5857             //                return false;
5858             //            }
5859             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5860             //                return false;
5861             //            }
5862             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5863             //                return false;
5864             //            }
5865         }
5866         catch ( final Exception e ) {
5867             e.printStackTrace( System.out );
5868             return false;
5869         }
5870         return true;
5871     }
5872
5873     private static boolean testNexusTreeParsing() {
5874         try {
5875             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5876             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5877             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
5878             if ( phylogenies.length != 1 ) {
5879                 return false;
5880             }
5881             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
5882                 return false;
5883             }
5884             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5885                 return false;
5886             }
5887             phylogenies = null;
5888             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
5889             if ( phylogenies.length != 1 ) {
5890                 return false;
5891             }
5892             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5893                 return false;
5894             }
5895             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
5896                 return false;
5897             }
5898             phylogenies = null;
5899             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
5900             if ( phylogenies.length != 1 ) {
5901                 return false;
5902             }
5903             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5904                 return false;
5905             }
5906             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5907                 return false;
5908             }
5909             if ( phylogenies[ 0 ].isRooted() ) {
5910                 return false;
5911             }
5912             phylogenies = null;
5913             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
5914             if ( phylogenies.length != 18 ) {
5915                 return false;
5916             }
5917             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5918                 return false;
5919             }
5920             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
5921                 return false;
5922             }
5923             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
5924                 return false;
5925             }
5926             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
5927                 return false;
5928             }
5929             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5930                 return false;
5931             }
5932             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
5933                 return false;
5934             }
5935             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
5936                 return false;
5937             }
5938             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
5939                 return false;
5940             }
5941             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
5942                 return false;
5943             }
5944             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
5945                 return false;
5946             }
5947             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
5948                 return false;
5949             }
5950             if ( phylogenies[ 8 ].isRooted() ) {
5951                 return false;
5952             }
5953             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
5954                 return false;
5955             }
5956             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
5957                 return false;
5958             }
5959             if ( !phylogenies[ 9 ].isRooted() ) {
5960                 return false;
5961             }
5962             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
5963                 return false;
5964             }
5965             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
5966                 return false;
5967             }
5968             if ( !phylogenies[ 10 ].isRooted() ) {
5969                 return false;
5970             }
5971             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
5972                 return false;
5973             }
5974             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
5975                 return false;
5976             }
5977             if ( phylogenies[ 11 ].isRooted() ) {
5978                 return false;
5979             }
5980             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
5981                 return false;
5982             }
5983             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
5984                 return false;
5985             }
5986             if ( !phylogenies[ 12 ].isRooted() ) {
5987                 return false;
5988             }
5989             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
5990                 return false;
5991             }
5992             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
5993                 return false;
5994             }
5995             if ( !phylogenies[ 13 ].isRooted() ) {
5996                 return false;
5997             }
5998             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
5999                 return false;
6000             }
6001             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6002                 return false;
6003             }
6004             if ( !phylogenies[ 14 ].isRooted() ) {
6005                 return false;
6006             }
6007             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6008                 return false;
6009             }
6010             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6011                 return false;
6012             }
6013             if ( phylogenies[ 15 ].isRooted() ) {
6014                 return false;
6015             }
6016             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6017                 return false;
6018             }
6019             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6020                 return false;
6021             }
6022             if ( !phylogenies[ 16 ].isRooted() ) {
6023                 return false;
6024             }
6025             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6026                 return false;
6027             }
6028             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6029                 return false;
6030             }
6031             if ( phylogenies[ 17 ].isRooted() ) {
6032                 return false;
6033             }
6034             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6035                 return false;
6036             }
6037         }
6038         catch ( final Exception e ) {
6039             e.printStackTrace( System.out );
6040             return false;
6041         }
6042         return true;
6043     }
6044
6045     private static boolean testNexusTreeParsingIterating() {
6046         try {
6047             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6048             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6049             if ( !p.hasNext() ) {
6050                 return false;
6051             }
6052             Phylogeny phy = p.next();
6053             if ( phy == null ) {
6054                 return false;
6055             }
6056             if ( phy.getNumberOfExternalNodes() != 25 ) {
6057                 return false;
6058             }
6059             if ( !phy.getName().equals( "" ) ) {
6060                 return false;
6061             }
6062             if ( p.hasNext() ) {
6063                 return false;
6064             }
6065             phy = p.next();
6066             if ( phy != null ) {
6067                 return false;
6068             }
6069             //
6070             p.reset();
6071             if ( !p.hasNext() ) {
6072                 return false;
6073             }
6074             phy = p.next();
6075             if ( phy == null ) {
6076                 return false;
6077             }
6078             if ( phy.getNumberOfExternalNodes() != 25 ) {
6079                 return false;
6080             }
6081             if ( !phy.getName().equals( "" ) ) {
6082                 return false;
6083             }
6084             if ( p.hasNext() ) {
6085                 return false;
6086             }
6087             phy = p.next();
6088             if ( phy != null ) {
6089                 return false;
6090             }
6091             ////
6092             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6093             if ( !p.hasNext() ) {
6094                 return false;
6095             }
6096             phy = p.next();
6097             if ( phy == null ) {
6098                 return false;
6099             }
6100             if ( phy.getNumberOfExternalNodes() != 10 ) {
6101                 return false;
6102             }
6103             if ( !phy.getName().equals( "name" ) ) {
6104                 return false;
6105             }
6106             if ( p.hasNext() ) {
6107                 return false;
6108             }
6109             phy = p.next();
6110             if ( phy != null ) {
6111                 return false;
6112             }
6113             //
6114             p.reset();
6115             if ( !p.hasNext() ) {
6116                 return false;
6117             }
6118             phy = p.next();
6119             if ( phy == null ) {
6120                 return false;
6121             }
6122             if ( phy.getNumberOfExternalNodes() != 10 ) {
6123                 return false;
6124             }
6125             if ( !phy.getName().equals( "name" ) ) {
6126                 return false;
6127             }
6128             if ( p.hasNext() ) {
6129                 return false;
6130             }
6131             phy = p.next();
6132             if ( phy != null ) {
6133                 return false;
6134             }
6135             ////
6136             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6137             if ( !p.hasNext() ) {
6138                 return false;
6139             }
6140             phy = p.next();
6141             if ( phy == null ) {
6142                 return false;
6143             }
6144             if ( phy.getNumberOfExternalNodes() != 3 ) {
6145                 return false;
6146             }
6147             if ( !phy.getName().equals( "" ) ) {
6148                 return false;
6149             }
6150             if ( phy.isRooted() ) {
6151                 return false;
6152             }
6153             if ( p.hasNext() ) {
6154                 return false;
6155             }
6156             phy = p.next();
6157             if ( phy != null ) {
6158                 return false;
6159             }
6160             //
6161             p.reset();
6162             if ( !p.hasNext() ) {
6163                 return false;
6164             }
6165             phy = p.next();
6166             if ( phy == null ) {
6167                 return false;
6168             }
6169             if ( phy.getNumberOfExternalNodes() != 3 ) {
6170                 return false;
6171             }
6172             if ( !phy.getName().equals( "" ) ) {
6173                 return false;
6174             }
6175             if ( p.hasNext() ) {
6176                 return false;
6177             }
6178             phy = p.next();
6179             if ( phy != null ) {
6180                 return false;
6181             }
6182             ////
6183             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6184             //            if ( phylogenies.length != 18 ) {
6185             //                return false;
6186             //            }
6187             //0
6188             if ( !p.hasNext() ) {
6189                 return false;
6190             }
6191             phy = p.next();
6192             if ( phy == null ) {
6193                 return false;
6194             }
6195             if ( phy.getNumberOfExternalNodes() != 10 ) {
6196                 return false;
6197             }
6198             if ( !phy.getName().equals( "tree 0" ) ) {
6199                 return false;
6200             }
6201             //1
6202             if ( !p.hasNext() ) {
6203                 return false;
6204             }
6205             phy = p.next();
6206             if ( phy == null ) {
6207                 return false;
6208             }
6209             if ( phy.getNumberOfExternalNodes() != 10 ) {
6210                 return false;
6211             }
6212             if ( !phy.getName().equals( "tree 1" ) ) {
6213                 return false;
6214             }
6215             //2
6216             if ( !p.hasNext() ) {
6217                 return false;
6218             }
6219             phy = p.next();
6220             if ( phy == null ) {
6221                 return false;
6222             }
6223             if ( phy.getNumberOfExternalNodes() != 3 ) {
6224                 return false;
6225             }
6226             if ( !phy.getName().equals( "" ) ) {
6227                 return false;
6228             }
6229             if ( phy.isRooted() ) {
6230                 return false;
6231             }
6232             //3
6233             if ( !p.hasNext() ) {
6234                 return false;
6235             }
6236             phy = p.next();
6237             if ( phy == null ) {
6238                 return false;
6239             }
6240             if ( phy.getNumberOfExternalNodes() != 4 ) {
6241                 return false;
6242             }
6243             if ( !phy.getName().equals( "" ) ) {
6244                 return false;
6245             }
6246             if ( !phy.isRooted() ) {
6247                 return false;
6248             }
6249             //4
6250             if ( !p.hasNext() ) {
6251                 return false;
6252             }
6253             phy = p.next();
6254             if ( phy == null ) {
6255                 return false;
6256             }
6257             if ( phy.getNumberOfExternalNodes() != 5 ) {
6258                 System.out.println( phy.getNumberOfExternalNodes() );
6259                 return false;
6260             }
6261             if ( !phy.getName().equals( "" ) ) {
6262                 return false;
6263             }
6264             if ( !phy.isRooted() ) {
6265                 return false;
6266             }
6267             //5
6268             if ( !p.hasNext() ) {
6269                 return false;
6270             }
6271             phy = p.next();
6272             if ( phy == null ) {
6273                 return false;
6274             }
6275             if ( phy.getNumberOfExternalNodes() != 3 ) {
6276                 return false;
6277             }
6278             if ( !phy.getName().equals( "" ) ) {
6279                 return false;
6280             }
6281             if ( phy.isRooted() ) {
6282                 return false;
6283             }
6284             //6
6285             if ( !p.hasNext() ) {
6286                 return false;
6287             }
6288             phy = p.next();
6289             if ( phy == null ) {
6290                 return false;
6291             }
6292             if ( phy.getNumberOfExternalNodes() != 2 ) {
6293                 return false;
6294             }
6295             if ( !phy.getName().equals( "" ) ) {
6296                 return false;
6297             }
6298             if ( !phy.isRooted() ) {
6299                 return false;
6300             }
6301             //7
6302             if ( !p.hasNext() ) {
6303                 return false;
6304             }
6305             phy = p.next();
6306             if ( phy.getNumberOfExternalNodes() != 3 ) {
6307                 return false;
6308             }
6309             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6310                 return false;
6311             }
6312             if ( !phy.isRooted() ) {
6313                 return false;
6314             }
6315             //8
6316             if ( !p.hasNext() ) {
6317                 return false;
6318             }
6319             phy = p.next();
6320             if ( phy.getNumberOfExternalNodes() != 3 ) {
6321                 return false;
6322             }
6323             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6324                 return false;
6325             }
6326             if ( !phy.getName().equals( "tree 8" ) ) {
6327                 return false;
6328             }
6329             //9
6330             if ( !p.hasNext() ) {
6331                 return false;
6332             }
6333             phy = p.next();
6334             if ( phy.getNumberOfExternalNodes() != 3 ) {
6335                 return false;
6336             }
6337             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6338                 return false;
6339             }
6340             if ( !phy.getName().equals( "tree 9" ) ) {
6341                 return false;
6342             }
6343             //10
6344             if ( !p.hasNext() ) {
6345                 return false;
6346             }
6347             phy = p.next();
6348             if ( phy.getNumberOfExternalNodes() != 3 ) {
6349                 return false;
6350             }
6351             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6352                 return false;
6353             }
6354             if ( !phy.getName().equals( "tree 10" ) ) {
6355                 return false;
6356             }
6357             if ( !phy.isRooted() ) {
6358                 return false;
6359             }
6360             //11
6361             if ( !p.hasNext() ) {
6362                 return false;
6363             }
6364             phy = p.next();
6365             if ( phy.getNumberOfExternalNodes() != 3 ) {
6366                 return false;
6367             }
6368             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6369                 return false;
6370             }
6371             if ( !phy.getName().equals( "tree 11" ) ) {
6372                 return false;
6373             }
6374             if ( phy.isRooted() ) {
6375                 return false;
6376             }
6377             //12
6378             if ( !p.hasNext() ) {
6379                 return false;
6380             }
6381             phy = p.next();
6382             if ( phy.getNumberOfExternalNodes() != 3 ) {
6383                 return false;
6384             }
6385             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6386                 return false;
6387             }
6388             if ( !phy.getName().equals( "tree 12" ) ) {
6389                 return false;
6390             }
6391             if ( !phy.isRooted() ) {
6392                 return false;
6393             }
6394             //13
6395             if ( !p.hasNext() ) {
6396                 return false;
6397             }
6398             phy = p.next();
6399             if ( phy.getNumberOfExternalNodes() != 3 ) {
6400                 return false;
6401             }
6402             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6403                 return false;
6404             }
6405             if ( !phy.getName().equals( "tree 13" ) ) {
6406                 return false;
6407             }
6408             if ( !phy.isRooted() ) {
6409                 return false;
6410             }
6411             //14
6412             if ( !p.hasNext() ) {
6413                 return false;
6414             }
6415             phy = p.next();
6416             if ( phy.getNumberOfExternalNodes() != 10 ) {
6417                 System.out.println( phy.getNumberOfExternalNodes() );
6418                 return false;
6419             }
6420             if ( !phy
6421                     .toNewHampshire()
6422                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6423                 System.out.println( phy.toNewHampshire() );
6424                 return false;
6425             }
6426             if ( !phy.getName().equals( "tree 14" ) ) {
6427                 return false;
6428             }
6429             if ( !phy.isRooted() ) {
6430                 return false;
6431             }
6432             //15
6433             if ( !p.hasNext() ) {
6434                 return false;
6435             }
6436             phy = p.next();
6437             if ( phy.getNumberOfExternalNodes() != 10 ) {
6438                 System.out.println( phy.getNumberOfExternalNodes() );
6439                 return false;
6440             }
6441             if ( !phy
6442                     .toNewHampshire()
6443                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6444                 System.out.println( phy.toNewHampshire() );
6445                 return false;
6446             }
6447             if ( !phy.getName().equals( "tree 15" ) ) {
6448                 return false;
6449             }
6450             if ( phy.isRooted() ) {
6451                 return false;
6452             }
6453             //16
6454             if ( !p.hasNext() ) {
6455                 return false;
6456             }
6457             phy = p.next();
6458             if ( phy.getNumberOfExternalNodes() != 10 ) {
6459                 System.out.println( phy.getNumberOfExternalNodes() );
6460                 return false;
6461             }
6462             if ( !phy
6463                     .toNewHampshire()
6464                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6465                 System.out.println( phy.toNewHampshire() );
6466                 return false;
6467             }
6468             if ( !phy.getName().equals( "tree 16" ) ) {
6469                 return false;
6470             }
6471             if ( !phy.isRooted() ) {
6472                 return false;
6473             }
6474             //17
6475             if ( !p.hasNext() ) {
6476                 return false;
6477             }
6478             phy = p.next();
6479             if ( phy.getNumberOfExternalNodes() != 10 ) {
6480                 System.out.println( phy.getNumberOfExternalNodes() );
6481                 return false;
6482             }
6483             if ( !phy
6484                     .toNewHampshire()
6485                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6486                 System.out.println( phy.toNewHampshire() );
6487                 return false;
6488             }
6489             if ( !phy.getName().equals( "tree 17" ) ) {
6490                 return false;
6491             }
6492             if ( phy.isRooted() ) {
6493                 return false;
6494             }
6495             //
6496             if ( p.hasNext() ) {
6497                 return false;
6498             }
6499             phy = p.next();
6500             if ( phy != null ) {
6501                 return false;
6502             }
6503             p.reset();
6504             //0
6505             if ( !p.hasNext() ) {
6506                 return false;
6507             }
6508             phy = p.next();
6509             if ( phy == null ) {
6510                 return false;
6511             }
6512             if ( phy.getNumberOfExternalNodes() != 10 ) {
6513                 return false;
6514             }
6515             if ( !phy.getName().equals( "tree 0" ) ) {
6516                 return false;
6517             }
6518             //1
6519             if ( !p.hasNext() ) {
6520                 return false;
6521             }
6522             phy = p.next();
6523             if ( phy == null ) {
6524                 return false;
6525             }
6526             if ( phy.getNumberOfExternalNodes() != 10 ) {
6527                 return false;
6528             }
6529             if ( !phy.getName().equals( "tree 1" ) ) {
6530                 return false;
6531             }
6532             //2
6533             if ( !p.hasNext() ) {
6534                 return false;
6535             }
6536             phy = p.next();
6537             if ( phy == null ) {
6538                 return false;
6539             }
6540             if ( phy.getNumberOfExternalNodes() != 3 ) {
6541                 return false;
6542             }
6543             if ( !phy.getName().equals( "" ) ) {
6544                 return false;
6545             }
6546             if ( phy.isRooted() ) {
6547                 return false;
6548             }
6549             //3
6550             if ( !p.hasNext() ) {
6551                 return false;
6552             }
6553             phy = p.next();
6554             if ( phy == null ) {
6555                 return false;
6556             }
6557             if ( phy.getNumberOfExternalNodes() != 4 ) {
6558                 return false;
6559             }
6560             if ( !phy.getName().equals( "" ) ) {
6561                 return false;
6562             }
6563             if ( !phy.isRooted() ) {
6564                 return false;
6565             }
6566             //4
6567             if ( !p.hasNext() ) {
6568                 return false;
6569             }
6570             phy = p.next();
6571             if ( phy == null ) {
6572                 return false;
6573             }
6574             if ( phy.getNumberOfExternalNodes() != 5 ) {
6575                 System.out.println( phy.getNumberOfExternalNodes() );
6576                 return false;
6577             }
6578             if ( !phy.getName().equals( "" ) ) {
6579                 return false;
6580             }
6581             if ( !phy.isRooted() ) {
6582                 return false;
6583             }
6584             //5
6585             if ( !p.hasNext() ) {
6586                 return false;
6587             }
6588             phy = p.next();
6589             if ( phy == null ) {
6590                 return false;
6591             }
6592             if ( phy.getNumberOfExternalNodes() != 3 ) {
6593                 return false;
6594             }
6595             if ( !phy.getName().equals( "" ) ) {
6596                 return false;
6597             }
6598             if ( phy.isRooted() ) {
6599                 return false;
6600             }
6601         }
6602         catch ( final Exception e ) {
6603             e.printStackTrace( System.out );
6604             return false;
6605         }
6606         return true;
6607     }
6608
6609     private static boolean testNexusTreeParsingTranslating() {
6610         try {
6611             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6612             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6613             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6614             if ( phylogenies.length != 1 ) {
6615                 return false;
6616             }
6617             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6618                 return false;
6619             }
6620             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6621                 return false;
6622             }
6623             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6624                 return false;
6625             }
6626             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6627                 return false;
6628             }
6629             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6630                     .equals( "Aranaeus" ) ) {
6631                 return false;
6632             }
6633             phylogenies = null;
6634             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6635             if ( phylogenies.length != 3 ) {
6636                 return false;
6637             }
6638             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6639                 return false;
6640             }
6641             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6642                 return false;
6643             }
6644             if ( phylogenies[ 0 ].isRooted() ) {
6645                 return false;
6646             }
6647             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6648                 return false;
6649             }
6650             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6651                 return false;
6652             }
6653             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6654                     .equals( "Aranaeus" ) ) {
6655                 return false;
6656             }
6657             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6658                 return false;
6659             }
6660             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6661                 return false;
6662             }
6663             if ( phylogenies[ 1 ].isRooted() ) {
6664                 return false;
6665             }
6666             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6667                 return false;
6668             }
6669             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6670                 return false;
6671             }
6672             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6673                     .equals( "Aranaeus" ) ) {
6674                 return false;
6675             }
6676             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6677                 return false;
6678             }
6679             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6680                 return false;
6681             }
6682             if ( !phylogenies[ 2 ].isRooted() ) {
6683                 return false;
6684             }
6685             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6686                 return false;
6687             }
6688             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6689                 return false;
6690             }
6691             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6692                     .equals( "Aranaeus" ) ) {
6693                 return false;
6694             }
6695             phylogenies = null;
6696             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6697             if ( phylogenies.length != 3 ) {
6698                 return false;
6699             }
6700             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6701                 return false;
6702             }
6703             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6704                 return false;
6705             }
6706             if ( phylogenies[ 0 ].isRooted() ) {
6707                 return false;
6708             }
6709             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6710                 return false;
6711             }
6712             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6713                 return false;
6714             }
6715             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6716                     .equals( "Aranaeus" ) ) {
6717                 return false;
6718             }
6719             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6720                 return false;
6721             }
6722             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6723                 return false;
6724             }
6725             if ( phylogenies[ 1 ].isRooted() ) {
6726                 return false;
6727             }
6728             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6729                 return false;
6730             }
6731             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6732                 return false;
6733             }
6734             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6735                     .equals( "Aranaeus" ) ) {
6736                 return false;
6737             }
6738             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6739                 return false;
6740             }
6741             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6742                 return false;
6743             }
6744             if ( !phylogenies[ 2 ].isRooted() ) {
6745                 return false;
6746             }
6747             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6748                 return false;
6749             }
6750             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6751                 return false;
6752             }
6753             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6754                     .equals( "Aranaeus" ) ) {
6755                 return false;
6756             }
6757         }
6758         catch ( final Exception e ) {
6759             e.printStackTrace( System.out );
6760             return false;
6761         }
6762         return true;
6763     }
6764
6765     private static boolean testNHParsing() {
6766         try {
6767             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6768             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6769             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6770                 return false;
6771             }
6772             final NHXParser nhxp = new NHXParser();
6773             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6774             nhxp.setReplaceUnderscores( true );
6775             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6776             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6777                 return false;
6778             }
6779             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6780                 return false;
6781             }
6782             final Phylogeny p1b = factory
6783                     .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 ",
6784                              new NHXParser() )[ 0 ];
6785             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6786                 return false;
6787             }
6788             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6789                 return false;
6790             }
6791             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6792             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6793             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6794             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6795             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6796             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6797             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6798             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6799             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6800             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6801             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6802                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6803                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6804                                                     new NHXParser() );
6805             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6806                 return false;
6807             }
6808             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6809                 return false;
6810             }
6811             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6812                 return false;
6813             }
6814             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6815                 return false;
6816             }
6817             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6818             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6819             final String p16_S = "((A,B),C)";
6820             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6821             if ( p16.length != 1 ) {
6822                 return false;
6823             }
6824             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6825                 return false;
6826             }
6827             final String p17_S = "(C,(A,B))";
6828             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6829             if ( p17.length != 1 ) {
6830                 return false;
6831             }
6832             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
6833                 return false;
6834             }
6835             final String p18_S = "((A,B),(C,D))";
6836             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
6837             if ( p18.length != 1 ) {
6838                 return false;
6839             }
6840             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
6841                 return false;
6842             }
6843             final String p19_S = "(((A,B),C),D)";
6844             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
6845             if ( p19.length != 1 ) {
6846                 return false;
6847             }
6848             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
6849                 return false;
6850             }
6851             final String p20_S = "(A,(B,(C,D)))";
6852             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
6853             if ( p20.length != 1 ) {
6854                 return false;
6855             }
6856             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
6857                 return false;
6858             }
6859             final String p21_S = "(A,(B,(C,(D,E))))";
6860             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
6861             if ( p21.length != 1 ) {
6862                 return false;
6863             }
6864             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
6865                 return false;
6866             }
6867             final String p22_S = "((((A,B),C),D),E)";
6868             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
6869             if ( p22.length != 1 ) {
6870                 return false;
6871             }
6872             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
6873                 return false;
6874             }
6875             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6876             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
6877             if ( p23.length != 1 ) {
6878                 System.out.println( "xl=" + p23.length );
6879                 System.exit( -1 );
6880                 return false;
6881             }
6882             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
6883                 return false;
6884             }
6885             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6886             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
6887             if ( p24.length != 1 ) {
6888                 return false;
6889             }
6890             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
6891                 return false;
6892             }
6893             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6894             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6895             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
6896             if ( p241.length != 2 ) {
6897                 return false;
6898             }
6899             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
6900                 return false;
6901             }
6902             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
6903                 return false;
6904             }
6905             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
6906                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
6907                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
6908                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
6909                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
6910                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
6911                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
6912                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
6913             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
6914             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
6915                 return false;
6916             }
6917             final String p26_S = "(A,B)ab";
6918             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
6919             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
6920                 return false;
6921             }
6922             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6923             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
6924             if ( p27s.length != 1 ) {
6925                 System.out.println( "xxl=" + p27s.length );
6926                 System.exit( -1 );
6927                 return false;
6928             }
6929             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6930                 System.out.println( p27s[ 0 ].toNewHampshireX() );
6931                 System.exit( -1 );
6932                 return false;
6933             }
6934             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
6935                                                     new NHXParser() );
6936             if ( p27.length != 1 ) {
6937                 System.out.println( "yl=" + p27.length );
6938                 System.exit( -1 );
6939                 return false;
6940             }
6941             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6942                 System.out.println( p27[ 0 ].toNewHampshireX() );
6943                 System.exit( -1 );
6944                 return false;
6945             }
6946             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6947             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6948             final String p28_S3 = "(A,B)ab";
6949             final String p28_S4 = "((((A,B),C),D),;E;)";
6950             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
6951                                                     new NHXParser() );
6952             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
6953                 return false;
6954             }
6955             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
6956                 return false;
6957             }
6958             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
6959                 return false;
6960             }
6961             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
6962                 return false;
6963             }
6964             if ( p28.length != 4 ) {
6965                 return false;
6966             }
6967             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";
6968             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
6969             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
6970                 return false;
6971             }
6972             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";
6973             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
6974             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
6975                 return false;
6976             }
6977             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
6978             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
6979             if ( ( p32.length != 0 ) ) {
6980                 return false;
6981             }
6982             final String p33_S = "A";
6983             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
6984             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
6985                 return false;
6986             }
6987             final String p34_S = "B;";
6988             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
6989             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
6990                 return false;
6991             }
6992             final String p35_S = "B:0.2";
6993             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
6994             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
6995                 return false;
6996             }
6997             final String p36_S = "(A)";
6998             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
6999             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7000                 return false;
7001             }
7002             final String p37_S = "((A))";
7003             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7004             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7005                 return false;
7006             }
7007             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7008             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7009             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7010                 return false;
7011             }
7012             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7013             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7014             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7015                 return false;
7016             }
7017             final String p40_S = "(A,B,C)";
7018             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7019             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7020                 return false;
7021             }
7022             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7023             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7024             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7025                 return false;
7026             }
7027             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7028             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7029             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7030                 return false;
7031             }
7032             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)";
7033             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7034             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7035                 return false;
7036             }
7037             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)))";
7038             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7039             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7040                 return false;
7041             }
7042             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7043             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7044             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7045                 return false;
7046             }
7047             final String p46_S = "";
7048             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7049             if ( p46.length != 0 ) {
7050                 return false;
7051             }
7052             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7053             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7054                 return false;
7055             }
7056             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7057             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7058                 return false;
7059             }
7060             final Phylogeny p49 = factory
7061                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7062                              new NHXParser() )[ 0 ];
7063             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7064                 return false;
7065             }
7066             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7067             if ( p50.getNode( "A" ) == null ) {
7068                 return false;
7069             }
7070             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7071                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7072                 return false;
7073             }
7074             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7075                 return false;
7076             }
7077             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7078                     .equals( "((A,B)88:2.0,C);" ) ) {
7079                 return false;
7080             }
7081             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7082             if ( p51.getNode( "A(A" ) == null ) {
7083                 return false;
7084             }
7085             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7086             if ( p52.getNode( "A(A" ) == null ) {
7087                 return false;
7088             }
7089             final Phylogeny p53 = factory
7090                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7091                              new NHXParser() )[ 0 ];
7092             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7093                 return false;
7094             }
7095             // 
7096             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7097             if ( p54.getNode( "A" ) == null ) {
7098                 return false;
7099             }
7100             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7101                     .equals( "((A,B)[88],C);" ) ) {
7102                 return false;
7103             }
7104         }
7105         catch ( final Exception e ) {
7106             e.printStackTrace( System.out );
7107             return false;
7108         }
7109         return true;
7110     }
7111
7112     private static boolean testNHParsingIter() {
7113         try {
7114             final String p0_str = "(A,B);";
7115             final NHXParser p = new NHXParser();
7116             p.setSource( p0_str );
7117             if ( !p.hasNext() ) {
7118                 return false;
7119             }
7120             final Phylogeny p0 = p.next();
7121             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7122                 System.out.println( p0.toNewHampshire() );
7123                 return false;
7124             }
7125             if ( p.hasNext() ) {
7126                 return false;
7127             }
7128             if ( p.next() != null ) {
7129                 return false;
7130             }
7131             //
7132             final String p00_str = "(A,B)root;";
7133             p.setSource( p00_str );
7134             final Phylogeny p00 = p.next();
7135             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7136                 System.out.println( p00.toNewHampshire() );
7137                 return false;
7138             }
7139             //
7140             final String p000_str = "A;";
7141             p.setSource( p000_str );
7142             final Phylogeny p000 = p.next();
7143             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7144                 System.out.println( p000.toNewHampshire() );
7145                 return false;
7146             }
7147             //
7148             final String p0000_str = "A";
7149             p.setSource( p0000_str );
7150             final Phylogeny p0000 = p.next();
7151             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7152                 System.out.println( p0000.toNewHampshire() );
7153                 return false;
7154             }
7155             //
7156             p.setSource( "(A)" );
7157             final Phylogeny p00000 = p.next();
7158             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7159                 System.out.println( p00000.toNewHampshire() );
7160                 return false;
7161             }
7162             //
7163             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7164             p.setSource( p1_str );
7165             if ( !p.hasNext() ) {
7166                 return false;
7167             }
7168             final Phylogeny p1_0 = p.next();
7169             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7170                 System.out.println( p1_0.toNewHampshire() );
7171                 return false;
7172             }
7173             if ( !p.hasNext() ) {
7174                 return false;
7175             }
7176             final Phylogeny p1_1 = p.next();
7177             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7178                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7179                 return false;
7180             }
7181             if ( !p.hasNext() ) {
7182                 return false;
7183             }
7184             final Phylogeny p1_2 = p.next();
7185             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7186                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7187                 return false;
7188             }
7189             if ( !p.hasNext() ) {
7190                 return false;
7191             }
7192             final Phylogeny p1_3 = p.next();
7193             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7194                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7195                 return false;
7196             }
7197             if ( p.hasNext() ) {
7198                 return false;
7199             }
7200             if ( p.next() != null ) {
7201                 return false;
7202             }
7203             //
7204             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7205             p.setSource( p2_str );
7206             if ( !p.hasNext() ) {
7207                 return false;
7208             }
7209             Phylogeny p2_0 = p.next();
7210             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7211                 System.out.println( p2_0.toNewHampshire() );
7212                 return false;
7213             }
7214             if ( !p.hasNext() ) {
7215                 return false;
7216             }
7217             Phylogeny p2_1 = p.next();
7218             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7219                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7220                 return false;
7221             }
7222             if ( !p.hasNext() ) {
7223                 return false;
7224             }
7225             Phylogeny p2_2 = p.next();
7226             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7227                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7228                 return false;
7229             }
7230             if ( !p.hasNext() ) {
7231                 return false;
7232             }
7233             Phylogeny p2_3 = p.next();
7234             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7235                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7236                 return false;
7237             }
7238             if ( !p.hasNext() ) {
7239                 return false;
7240             }
7241             Phylogeny p2_4 = p.next();
7242             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7243                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7244                 return false;
7245             }
7246             if ( p.hasNext() ) {
7247                 return false;
7248             }
7249             if ( p.next() != null ) {
7250                 return false;
7251             }
7252             ////
7253             p.reset();
7254             if ( !p.hasNext() ) {
7255                 return false;
7256             }
7257             p2_0 = p.next();
7258             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7259                 System.out.println( p2_0.toNewHampshire() );
7260                 return false;
7261             }
7262             if ( !p.hasNext() ) {
7263                 return false;
7264             }
7265             p2_1 = p.next();
7266             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7267                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7268                 return false;
7269             }
7270             if ( !p.hasNext() ) {
7271                 return false;
7272             }
7273             p2_2 = p.next();
7274             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7275                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7276                 return false;
7277             }
7278             if ( !p.hasNext() ) {
7279                 return false;
7280             }
7281             p2_3 = p.next();
7282             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7283                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7284                 return false;
7285             }
7286             if ( !p.hasNext() ) {
7287                 return false;
7288             }
7289             p2_4 = p.next();
7290             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7291                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7292                 return false;
7293             }
7294             if ( p.hasNext() ) {
7295                 return false;
7296             }
7297             if ( p.next() != null ) {
7298                 return false;
7299             }
7300             //
7301             final String p3_str = "((A,B),C)abc";
7302             p.setSource( p3_str );
7303             if ( !p.hasNext() ) {
7304                 return false;
7305             }
7306             final Phylogeny p3_0 = p.next();
7307             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7308                 return false;
7309             }
7310             if ( p.hasNext() ) {
7311                 return false;
7312             }
7313             if ( p.next() != null ) {
7314                 return false;
7315             }
7316             //
7317             final String p4_str = "((A,B)ab,C)abc";
7318             p.setSource( p4_str );
7319             if ( !p.hasNext() ) {
7320                 return false;
7321             }
7322             final Phylogeny p4_0 = p.next();
7323             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7324                 return false;
7325             }
7326             if ( p.hasNext() ) {
7327                 return false;
7328             }
7329             if ( p.next() != null ) {
7330                 return false;
7331             }
7332             //
7333             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7334             p.setSource( p5_str );
7335             if ( !p.hasNext() ) {
7336                 return false;
7337             }
7338             final Phylogeny p5_0 = p.next();
7339             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7340                 return false;
7341             }
7342             if ( p.hasNext() ) {
7343                 return false;
7344             }
7345             if ( p.next() != null ) {
7346                 return false;
7347             }
7348             //
7349             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7350             p.setSource( p6_str );
7351             if ( !p.hasNext() ) {
7352                 return false;
7353             }
7354             Phylogeny p6_0 = p.next();
7355             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7356                 return false;
7357             }
7358             if ( p.hasNext() ) {
7359                 return false;
7360             }
7361             if ( p.next() != null ) {
7362                 return false;
7363             }
7364             p.reset();
7365             if ( !p.hasNext() ) {
7366                 return false;
7367             }
7368             p6_0 = p.next();
7369             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7370                 return false;
7371             }
7372             if ( p.hasNext() ) {
7373                 return false;
7374             }
7375             if ( p.next() != null ) {
7376                 return false;
7377             }
7378             //
7379             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7380             p.setSource( p7_str );
7381             if ( !p.hasNext() ) {
7382                 return false;
7383             }
7384             Phylogeny p7_0 = p.next();
7385             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7386                 return false;
7387             }
7388             if ( p.hasNext() ) {
7389                 return false;
7390             }
7391             if ( p.next() != null ) {
7392                 return false;
7393             }
7394             p.reset();
7395             if ( !p.hasNext() ) {
7396                 return false;
7397             }
7398             p7_0 = p.next();
7399             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7400                 return false;
7401             }
7402             if ( p.hasNext() ) {
7403                 return false;
7404             }
7405             if ( p.next() != null ) {
7406                 return false;
7407             }
7408             //
7409             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7410             p.setSource( p8_str );
7411             if ( !p.hasNext() ) {
7412                 return false;
7413             }
7414             Phylogeny p8_0 = p.next();
7415             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7416                 return false;
7417             }
7418             if ( !p.hasNext() ) {
7419                 return false;
7420             }
7421             if ( !p.hasNext() ) {
7422                 return false;
7423             }
7424             Phylogeny p8_1 = p.next();
7425             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7426                 return false;
7427             }
7428             if ( p.hasNext() ) {
7429                 return false;
7430             }
7431             if ( p.next() != null ) {
7432                 return false;
7433             }
7434             p.reset();
7435             if ( !p.hasNext() ) {
7436                 return false;
7437             }
7438             p8_0 = p.next();
7439             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7440                 return false;
7441             }
7442             if ( !p.hasNext() ) {
7443                 return false;
7444             }
7445             p8_1 = p.next();
7446             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7447                 return false;
7448             }
7449             if ( p.hasNext() ) {
7450                 return false;
7451             }
7452             if ( p.next() != null ) {
7453                 return false;
7454             }
7455             p.reset();
7456             //
7457             p.setSource( "" );
7458             if ( p.hasNext() ) {
7459                 return false;
7460             }
7461             //
7462             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7463             if ( !p.hasNext() ) {
7464                 return false;
7465             }
7466             Phylogeny p_27 = p.next();
7467             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7468                 System.out.println( p_27.toNewHampshireX() );
7469                 System.exit( -1 );
7470                 return false;
7471             }
7472             if ( p.hasNext() ) {
7473                 return false;
7474             }
7475             if ( p.next() != null ) {
7476                 return false;
7477             }
7478             p.reset();
7479             if ( !p.hasNext() ) {
7480                 return false;
7481             }
7482             p_27 = p.next();
7483             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7484                 System.out.println( p_27.toNewHampshireX() );
7485                 System.exit( -1 );
7486                 return false;
7487             }
7488             if ( p.hasNext() ) {
7489                 return false;
7490             }
7491             if ( p.next() != null ) {
7492                 return false;
7493             }
7494         }
7495         catch ( final Exception e ) {
7496             e.printStackTrace( System.out );
7497             return false;
7498         }
7499         return true;
7500     }
7501
7502     private static boolean testNHXconversion() {
7503         try {
7504             final PhylogenyNode n1 = new PhylogenyNode();
7505             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7506             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7507             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7508             final PhylogenyNode n5 = PhylogenyNode
7509                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7510             final PhylogenyNode n6 = PhylogenyNode
7511                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7512             if ( !n1.toNewHampshireX().equals( "" ) ) {
7513                 return false;
7514             }
7515             if ( !n2.toNewHampshireX().equals( "" ) ) {
7516                 return false;
7517             }
7518             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7519                 return false;
7520             }
7521             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7522                 return false;
7523             }
7524             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7525                 return false;
7526             }
7527             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7528                 System.out.println( n6.toNewHampshireX() );
7529                 return false;
7530             }
7531         }
7532         catch ( final Exception e ) {
7533             e.printStackTrace( System.out );
7534             return false;
7535         }
7536         return true;
7537     }
7538
7539     private static boolean testNHXNodeParsing() {
7540         try {
7541             final PhylogenyNode n1 = new PhylogenyNode();
7542             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7543             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7544             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7545             final PhylogenyNode n5 = PhylogenyNode
7546                     .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]" );
7547             if ( !n3.getName().equals( "n3" ) ) {
7548                 return false;
7549             }
7550             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7551                 return false;
7552             }
7553             if ( n3.isDuplication() ) {
7554                 return false;
7555             }
7556             if ( n3.isHasAssignedEvent() ) {
7557                 return false;
7558             }
7559             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7560                 return false;
7561             }
7562             if ( !n4.getName().equals( "n4" ) ) {
7563                 return false;
7564             }
7565             if ( n4.getDistanceToParent() != 0.01 ) {
7566                 return false;
7567             }
7568             if ( !n5.getName().equals( "n5" ) ) {
7569                 return false;
7570             }
7571             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7572                 return false;
7573             }
7574             if ( n5.getDistanceToParent() != 0.1 ) {
7575                 return false;
7576             }
7577             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7578                 return false;
7579             }
7580             if ( !n5.isDuplication() ) {
7581                 return false;
7582             }
7583             if ( !n5.isHasAssignedEvent() ) {
7584                 return false;
7585             }
7586             final PhylogenyNode n8 = PhylogenyNode
7587                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7588                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7589             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7590                 return false;
7591             }
7592             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7593                 return false;
7594             }
7595             final PhylogenyNode n9 = PhylogenyNode
7596                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7597                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7598             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7599                 return false;
7600             }
7601             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7602                 return false;
7603             }
7604             final PhylogenyNode n10 = PhylogenyNode
7605                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7606             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7607                 return false;
7608             }
7609             final PhylogenyNode n20 = PhylogenyNode
7610                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7611             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7612                 return false;
7613             }
7614             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7615                 return false;
7616             }
7617             final PhylogenyNode n20x = PhylogenyNode
7618                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7619             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7620                 return false;
7621             }
7622             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7623                 return false;
7624             }
7625             final PhylogenyNode n20xx = PhylogenyNode
7626                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7627             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7628                 return false;
7629             }
7630             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7631                 return false;
7632             }
7633             final PhylogenyNode n20xxx = PhylogenyNode
7634                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7635             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7636                 return false;
7637             }
7638             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7639                 return false;
7640             }
7641             final PhylogenyNode n20xxxx = PhylogenyNode
7642                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7643             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7644                 return false;
7645             }
7646             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7647                 return false;
7648             }
7649             final PhylogenyNode n21 = PhylogenyNode
7650                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7651             if ( !n21.getName().equals( "N21_PIG" ) ) {
7652                 return false;
7653             }
7654             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7655                 return false;
7656             }
7657             final PhylogenyNode n21x = PhylogenyNode
7658                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7659             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7660                 return false;
7661             }
7662             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7663                 return false;
7664             }
7665             final PhylogenyNode n22 = PhylogenyNode
7666                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7667             if ( !n22.getName().equals( "n22/PIG" ) ) {
7668                 return false;
7669             }
7670             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7671                 return false;
7672             }
7673             final PhylogenyNode n23 = PhylogenyNode
7674                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7675             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7676                 return false;
7677             }
7678             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7679                 return false;
7680             }
7681             final PhylogenyNode a = PhylogenyNode
7682                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7683             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7684                 return false;
7685             }
7686             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7687                 return false;
7688             }
7689             final PhylogenyNode c1 = PhylogenyNode
7690                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7691                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7692             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7693                 return false;
7694             }
7695             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7696                 return false;
7697             }
7698             final PhylogenyNode c2 = PhylogenyNode
7699                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7700                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7701             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7702                 return false;
7703             }
7704             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7705                 return false;
7706             }
7707             final PhylogenyNode e3 = PhylogenyNode
7708                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7709             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7710                 return false;
7711             }
7712             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7713                 return false;
7714             }
7715             final PhylogenyNode n11 = PhylogenyNode
7716                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7717                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7718             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7719                 return false;
7720             }
7721             if ( n11.getDistanceToParent() != 0.4 ) {
7722                 return false;
7723             }
7724             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7725                 return false;
7726             }
7727             final PhylogenyNode n12 = PhylogenyNode
7728                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7729                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7730             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7731                 return false;
7732             }
7733             if ( n12.getDistanceToParent() != 0.4 ) {
7734                 return false;
7735             }
7736             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7737                 return false;
7738             }
7739             final PhylogenyNode o = PhylogenyNode
7740                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7741             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7742                 return false;
7743             }
7744             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7745                 return false;
7746             }
7747             if ( n1.getName().compareTo( "" ) != 0 ) {
7748                 return false;
7749             }
7750             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7751                 return false;
7752             }
7753             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7754                 return false;
7755             }
7756             if ( n2.getName().compareTo( "" ) != 0 ) {
7757                 return false;
7758             }
7759             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7760                 return false;
7761             }
7762             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7763                 return false;
7764             }
7765             final PhylogenyNode n00 = PhylogenyNode
7766                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7767             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7768                 return false;
7769             }
7770             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7771                 return false;
7772             }
7773             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7774             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7775                 return false;
7776             }
7777             final PhylogenyNode n13 = PhylogenyNode
7778                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7779             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7780                 return false;
7781             }
7782             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7783                 return false;
7784             }
7785             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7786                 return false;
7787             }
7788             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7789                 return false;
7790             }
7791             final PhylogenyNode n14 = PhylogenyNode
7792                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7793             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7794                 return false;
7795             }
7796             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7797                 return false;
7798             }
7799             final PhylogenyNode n15 = PhylogenyNode
7800                     .createInstanceFromNhxString( "something_wicked[123]",
7801                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7802             if ( !n15.getName().equals( "something_wicked" ) ) {
7803                 return false;
7804             }
7805             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7806                 return false;
7807             }
7808             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7809                 return false;
7810             }
7811             final PhylogenyNode n16 = PhylogenyNode
7812                     .createInstanceFromNhxString( "something_wicked2[9]",
7813                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7814             if ( !n16.getName().equals( "something_wicked2" ) ) {
7815                 return false;
7816             }
7817             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7818                 return false;
7819             }
7820             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7821                 return false;
7822             }
7823             final PhylogenyNode n17 = PhylogenyNode
7824                     .createInstanceFromNhxString( "something_wicked3[a]",
7825                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7826             if ( !n17.getName().equals( "something_wicked3" ) ) {
7827                 return false;
7828             }
7829             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7830                 return false;
7831             }
7832             final PhylogenyNode n18 = PhylogenyNode
7833                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7834             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
7835                 return false;
7836             }
7837             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
7838                 return false;
7839             }
7840             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
7841                 return false;
7842             }
7843             final PhylogenyNode n19 = PhylogenyNode
7844                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7845             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
7846                 return false;
7847             }
7848             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7849                 return false;
7850             }
7851             final PhylogenyNode n30 = PhylogenyNode
7852                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
7853                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7854             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
7855                 return false;
7856             }
7857             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7858                 return false;
7859             }
7860             final PhylogenyNode n31 = PhylogenyNode
7861                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
7862                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7863             if ( n31.getNodeData().isHasTaxonomy() ) {
7864                 return false;
7865             }
7866             final PhylogenyNode n32 = PhylogenyNode
7867                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7868             if ( n32.getNodeData().isHasTaxonomy() ) {
7869                 return false;
7870             }
7871             final PhylogenyNode n40 = PhylogenyNode
7872                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7873             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7874                 return false;
7875             }
7876             final PhylogenyNode n41 = PhylogenyNode
7877                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7878             if ( n41.getNodeData().isHasTaxonomy() ) {
7879                 return false;
7880             }
7881             final PhylogenyNode n42 = PhylogenyNode
7882                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7883             if ( n42.getNodeData().isHasTaxonomy() ) {
7884                 return false;
7885             }
7886             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
7887                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
7888             if ( n43.getNodeData().isHasTaxonomy() ) {
7889                 return false;
7890             }
7891             final PhylogenyNode n44 = PhylogenyNode
7892                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7893             if ( n44.getNodeData().isHasTaxonomy() ) {
7894                 return false;
7895             }
7896         }
7897         catch ( final Exception e ) {
7898             e.printStackTrace( System.out );
7899             return false;
7900         }
7901         return true;
7902     }
7903
7904     private static boolean testNHXParsing() {
7905         try {
7906             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7907             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
7908             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
7909                 return false;
7910             }
7911             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]";
7912             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
7913             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7914                 return false;
7915             }
7916             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]";
7917             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
7918             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
7919                 return false;
7920             }
7921             final Phylogeny[] p3 = factory
7922                     .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]",
7923                              new NHXParser() );
7924             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7925                 return false;
7926             }
7927             final Phylogeny[] p4 = factory
7928                     .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(]",
7929                              new NHXParser() );
7930             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7931                 return false;
7932             }
7933             final Phylogeny[] p5 = factory
7934                     .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(((]",
7935                              new NHXParser() );
7936             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7937                 return false;
7938             }
7939             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)";
7940             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)";
7941             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
7942             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
7943                 return false;
7944             }
7945             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)))";
7946             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)))";
7947             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
7948             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
7949                 return false;
7950             }
7951             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])   ))[,,, ])))))))";
7952             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
7953             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
7954             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
7955                 return false;
7956             }
7957             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
7958             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7959                 return false;
7960             }
7961             final Phylogeny p10 = factory
7962                     .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]",
7963                              new NHXParser() )[ 0 ];
7964             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7965                 return false;
7966             }
7967         }
7968         catch ( final Exception e ) {
7969             e.printStackTrace( System.out );
7970             return false;
7971         }
7972         return true;
7973     }
7974
7975     private static boolean testNHXParsingMB() {
7976         try {
7977             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7978             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7979                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7980                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7981                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7982                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7983                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7984                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7985                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7986                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
7987             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
7988                 return false;
7989             }
7990             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
7991                 return false;
7992             }
7993             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
7994                            0.1100000000000000e+00 ) ) {
7995                 return false;
7996             }
7997             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
7998                 return false;
7999             }
8000             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8001                 return false;
8002             }
8003             final Phylogeny p2 = factory
8004                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8005                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8006                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8007                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8008                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8009                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8010                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8011                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8012                                      + "7.369400000000000e-02}])",
8013                              new NHXParser() )[ 0 ];
8014             if ( p2.getNode( "1" ) == null ) {
8015                 return false;
8016             }
8017             if ( p2.getNode( "2" ) == null ) {
8018                 return false;
8019             }
8020         }
8021         catch ( final Exception e ) {
8022             e.printStackTrace( System.out );
8023             System.exit( -1 );
8024             return false;
8025         }
8026         return true;
8027     }
8028
8029     private static boolean testNHXParsingQuotes() {
8030         try {
8031             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8032             final NHXParser p = new NHXParser();
8033             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8034             if ( phylogenies_0.length != 5 ) {
8035                 return false;
8036             }
8037             final Phylogeny phy = phylogenies_0[ 4 ];
8038             if ( phy.getNumberOfExternalNodes() != 7 ) {
8039                 return false;
8040             }
8041             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8042                 return false;
8043             }
8044             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8045                 return false;
8046             }
8047             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8048                     .getScientificName().equals( "hsapiens" ) ) {
8049                 return false;
8050             }
8051             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8052                 return false;
8053             }
8054             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8055                 return false;
8056             }
8057             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8058                 return false;
8059             }
8060             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8061                 return false;
8062             }
8063             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8064                 return false;
8065             }
8066             final NHXParser p1p = new NHXParser();
8067             p1p.setIgnoreQuotes( true );
8068             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8069             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8070                 return false;
8071             }
8072             final NHXParser p2p = new NHXParser();
8073             p1p.setIgnoreQuotes( false );
8074             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8075             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8076                 return false;
8077             }
8078             final NHXParser p3p = new NHXParser();
8079             p3p.setIgnoreQuotes( false );
8080             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8081             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8082                 return false;
8083             }
8084             final NHXParser p4p = new NHXParser();
8085             p4p.setIgnoreQuotes( false );
8086             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8087             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8088                 return false;
8089             }
8090             final Phylogeny p10 = factory
8091                     .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]",
8092                              new NHXParser() )[ 0 ];
8093             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]";
8094             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8095                 return false;
8096             }
8097             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8098             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8099                 return false;
8100             }
8101             //
8102             final Phylogeny p12 = factory
8103                     .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]",
8104                              new NHXParser() )[ 0 ];
8105             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]";
8106             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8107                 return false;
8108             }
8109             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8110             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8111                 return false;
8112             }
8113             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;";
8114             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8115                 return false;
8116             }
8117             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8118             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8119                 return false;
8120             }
8121         }
8122         catch ( final Exception e ) {
8123             e.printStackTrace( System.out );
8124             return false;
8125         }
8126         return true;
8127     }
8128
8129     private static boolean testNodeRemoval() {
8130         try {
8131             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8132             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8133             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8134             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8135                 return false;
8136             }
8137             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8138             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8139             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8140                 return false;
8141             }
8142             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8143             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8144             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8145                 return false;
8146             }
8147         }
8148         catch ( final Exception e ) {
8149             e.printStackTrace( System.out );
8150             return false;
8151         }
8152         return true;
8153     }
8154
8155     private static boolean testPhylogenyBranch() {
8156         try {
8157             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8158             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8159             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8160             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8161             if ( !a1b1.equals( a1b1 ) ) {
8162                 return false;
8163             }
8164             if ( !a1b1.equals( b1a1 ) ) {
8165                 return false;
8166             }
8167             if ( !b1a1.equals( a1b1 ) ) {
8168                 return false;
8169             }
8170             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8171             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8172             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8173             if ( a1_b1.equals( b1_a1 ) ) {
8174                 return false;
8175             }
8176             if ( a1_b1.equals( a1_b1_ ) ) {
8177                 return false;
8178             }
8179             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8180             if ( !a1_b1.equals( b1_a1_ ) ) {
8181                 return false;
8182             }
8183             if ( a1_b1_.equals( b1_a1_ ) ) {
8184                 return false;
8185             }
8186             if ( !a1_b1_.equals( b1_a1 ) ) {
8187                 return false;
8188             }
8189         }
8190         catch ( final Exception e ) {
8191             e.printStackTrace( System.out );
8192             return false;
8193         }
8194         return true;
8195     }
8196
8197     private static boolean testPhyloXMLparsingOfDistributionElement() {
8198         try {
8199             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8200             PhyloXmlParser xml_parser = null;
8201             try {
8202                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8203             }
8204             catch ( final Exception e ) {
8205                 // Do nothing -- means were not running from jar.
8206             }
8207             if ( xml_parser == null ) {
8208                 xml_parser = new PhyloXmlParser();
8209                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8210                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8211                 }
8212                 else {
8213                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8214                 }
8215             }
8216             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8217                                                               xml_parser );
8218             if ( xml_parser.getErrorCount() > 0 ) {
8219                 System.out.println( xml_parser.getErrorMessages().toString() );
8220                 return false;
8221             }
8222             if ( phylogenies_0.length != 1 ) {
8223                 return false;
8224             }
8225             final Phylogeny t1 = phylogenies_0[ 0 ];
8226             PhylogenyNode n = null;
8227             Distribution d = null;
8228             n = t1.getNode( "root node" );
8229             if ( !n.getNodeData().isHasDistribution() ) {
8230                 return false;
8231             }
8232             if ( n.getNodeData().getDistributions().size() != 1 ) {
8233                 return false;
8234             }
8235             d = n.getNodeData().getDistribution();
8236             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8237                 return false;
8238             }
8239             if ( d.getPoints().size() != 1 ) {
8240                 return false;
8241             }
8242             if ( d.getPolygons() != null ) {
8243                 return false;
8244             }
8245             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8246                 return false;
8247             }
8248             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8249                 return false;
8250             }
8251             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8252                 return false;
8253             }
8254             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8255                 return false;
8256             }
8257             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8258                 return false;
8259             }
8260             n = t1.getNode( "node a" );
8261             if ( !n.getNodeData().isHasDistribution() ) {
8262                 return false;
8263             }
8264             if ( n.getNodeData().getDistributions().size() != 2 ) {
8265                 return false;
8266             }
8267             d = n.getNodeData().getDistribution( 1 );
8268             if ( !d.getDesc().equals( "San Diego" ) ) {
8269                 return false;
8270             }
8271             if ( d.getPoints().size() != 1 ) {
8272                 return false;
8273             }
8274             if ( d.getPolygons() != null ) {
8275                 return false;
8276             }
8277             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8278                 return false;
8279             }
8280             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8281                 return false;
8282             }
8283             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8284                 return false;
8285             }
8286             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8287                 return false;
8288             }
8289             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8290                 return false;
8291             }
8292             n = t1.getNode( "node bb" );
8293             if ( !n.getNodeData().isHasDistribution() ) {
8294                 return false;
8295             }
8296             if ( n.getNodeData().getDistributions().size() != 1 ) {
8297                 return false;
8298             }
8299             d = n.getNodeData().getDistribution( 0 );
8300             if ( d.getPoints().size() != 3 ) {
8301                 return false;
8302             }
8303             if ( d.getPolygons().size() != 2 ) {
8304                 return false;
8305             }
8306             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8307                 return false;
8308             }
8309             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8310                 return false;
8311             }
8312             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8313                 return false;
8314             }
8315             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8316                 return false;
8317             }
8318             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8319                 return false;
8320             }
8321             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8322                 return false;
8323             }
8324             Polygon p = d.getPolygons().get( 0 );
8325             if ( p.getPoints().size() != 3 ) {
8326                 return false;
8327             }
8328             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8329                 return false;
8330             }
8331             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8332                 return false;
8333             }
8334             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8335                 return false;
8336             }
8337             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8338                 return false;
8339             }
8340             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8341                 return false;
8342             }
8343             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8344                 return false;
8345             }
8346             p = d.getPolygons().get( 1 );
8347             if ( p.getPoints().size() != 3 ) {
8348                 return false;
8349             }
8350             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8351                 return false;
8352             }
8353             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8354                 return false;
8355             }
8356             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8357                 return false;
8358             }
8359             // Roundtrip:
8360             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8361             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8362             if ( rt.length != 1 ) {
8363                 return false;
8364             }
8365             final Phylogeny t1_rt = rt[ 0 ];
8366             n = t1_rt.getNode( "root node" );
8367             if ( !n.getNodeData().isHasDistribution() ) {
8368                 return false;
8369             }
8370             if ( n.getNodeData().getDistributions().size() != 1 ) {
8371                 return false;
8372             }
8373             d = n.getNodeData().getDistribution();
8374             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8375                 return false;
8376             }
8377             if ( d.getPoints().size() != 1 ) {
8378                 return false;
8379             }
8380             if ( d.getPolygons() != null ) {
8381                 return false;
8382             }
8383             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8384                 return false;
8385             }
8386             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8387                 return false;
8388             }
8389             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8390                 return false;
8391             }
8392             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8393                 return false;
8394             }
8395             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8396                 return false;
8397             }
8398             n = t1_rt.getNode( "node a" );
8399             if ( !n.getNodeData().isHasDistribution() ) {
8400                 return false;
8401             }
8402             if ( n.getNodeData().getDistributions().size() != 2 ) {
8403                 return false;
8404             }
8405             d = n.getNodeData().getDistribution( 1 );
8406             if ( !d.getDesc().equals( "San Diego" ) ) {
8407                 return false;
8408             }
8409             if ( d.getPoints().size() != 1 ) {
8410                 return false;
8411             }
8412             if ( d.getPolygons() != null ) {
8413                 return false;
8414             }
8415             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8416                 return false;
8417             }
8418             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8419                 return false;
8420             }
8421             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8422                 return false;
8423             }
8424             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8425                 return false;
8426             }
8427             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8428                 return false;
8429             }
8430             n = t1_rt.getNode( "node bb" );
8431             if ( !n.getNodeData().isHasDistribution() ) {
8432                 return false;
8433             }
8434             if ( n.getNodeData().getDistributions().size() != 1 ) {
8435                 return false;
8436             }
8437             d = n.getNodeData().getDistribution( 0 );
8438             if ( d.getPoints().size() != 3 ) {
8439                 return false;
8440             }
8441             if ( d.getPolygons().size() != 2 ) {
8442                 return false;
8443             }
8444             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8445                 return false;
8446             }
8447             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8448                 return false;
8449             }
8450             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8451                 return false;
8452             }
8453             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8454                 return false;
8455             }
8456             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8457                 return false;
8458             }
8459             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8460                 return false;
8461             }
8462             p = d.getPolygons().get( 0 );
8463             if ( p.getPoints().size() != 3 ) {
8464                 return false;
8465             }
8466             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8467                 return false;
8468             }
8469             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8470                 return false;
8471             }
8472             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8473                 return false;
8474             }
8475             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8476                 return false;
8477             }
8478             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8479                 return false;
8480             }
8481             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8482                 return false;
8483             }
8484             p = d.getPolygons().get( 1 );
8485             if ( p.getPoints().size() != 3 ) {
8486                 return false;
8487             }
8488             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8489                 return false;
8490             }
8491             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8492                 return false;
8493             }
8494             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8495                 return false;
8496             }
8497         }
8498         catch ( final Exception e ) {
8499             e.printStackTrace( System.out );
8500             return false;
8501         }
8502         return true;
8503     }
8504
8505     private static boolean testPostOrderIterator() {
8506         try {
8507             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8508             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8509             PhylogenyNodeIterator it0;
8510             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8511                 it0.next();
8512             }
8513             for( it0.reset(); it0.hasNext(); ) {
8514                 it0.next();
8515             }
8516             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8517             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8518             if ( !it.next().getName().equals( "A" ) ) {
8519                 return false;
8520             }
8521             if ( !it.next().getName().equals( "B" ) ) {
8522                 return false;
8523             }
8524             if ( !it.next().getName().equals( "ab" ) ) {
8525                 return false;
8526             }
8527             if ( !it.next().getName().equals( "C" ) ) {
8528                 return false;
8529             }
8530             if ( !it.next().getName().equals( "D" ) ) {
8531                 return false;
8532             }
8533             if ( !it.next().getName().equals( "cd" ) ) {
8534                 return false;
8535             }
8536             if ( !it.next().getName().equals( "abcd" ) ) {
8537                 return false;
8538             }
8539             if ( !it.next().getName().equals( "E" ) ) {
8540                 return false;
8541             }
8542             if ( !it.next().getName().equals( "F" ) ) {
8543                 return false;
8544             }
8545             if ( !it.next().getName().equals( "ef" ) ) {
8546                 return false;
8547             }
8548             if ( !it.next().getName().equals( "G" ) ) {
8549                 return false;
8550             }
8551             if ( !it.next().getName().equals( "H" ) ) {
8552                 return false;
8553             }
8554             if ( !it.next().getName().equals( "gh" ) ) {
8555                 return false;
8556             }
8557             if ( !it.next().getName().equals( "efgh" ) ) {
8558                 return false;
8559             }
8560             if ( !it.next().getName().equals( "r" ) ) {
8561                 return false;
8562             }
8563             if ( it.hasNext() ) {
8564                 return false;
8565             }
8566         }
8567         catch ( final Exception e ) {
8568             e.printStackTrace( System.out );
8569             return false;
8570         }
8571         return true;
8572     }
8573
8574     private static boolean testPreOrderIterator() {
8575         try {
8576             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8577             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8578             PhylogenyNodeIterator it0;
8579             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8580                 it0.next();
8581             }
8582             for( it0.reset(); it0.hasNext(); ) {
8583                 it0.next();
8584             }
8585             PhylogenyNodeIterator it = t0.iteratorPreorder();
8586             if ( !it.next().getName().equals( "r" ) ) {
8587                 return false;
8588             }
8589             if ( !it.next().getName().equals( "ab" ) ) {
8590                 return false;
8591             }
8592             if ( !it.next().getName().equals( "A" ) ) {
8593                 return false;
8594             }
8595             if ( !it.next().getName().equals( "B" ) ) {
8596                 return false;
8597             }
8598             if ( !it.next().getName().equals( "cd" ) ) {
8599                 return false;
8600             }
8601             if ( !it.next().getName().equals( "C" ) ) {
8602                 return false;
8603             }
8604             if ( !it.next().getName().equals( "D" ) ) {
8605                 return false;
8606             }
8607             if ( it.hasNext() ) {
8608                 return false;
8609             }
8610             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8611             it = t1.iteratorPreorder();
8612             if ( !it.next().getName().equals( "r" ) ) {
8613                 return false;
8614             }
8615             if ( !it.next().getName().equals( "abcd" ) ) {
8616                 return false;
8617             }
8618             if ( !it.next().getName().equals( "ab" ) ) {
8619                 return false;
8620             }
8621             if ( !it.next().getName().equals( "A" ) ) {
8622                 return false;
8623             }
8624             if ( !it.next().getName().equals( "B" ) ) {
8625                 return false;
8626             }
8627             if ( !it.next().getName().equals( "cd" ) ) {
8628                 return false;
8629             }
8630             if ( !it.next().getName().equals( "C" ) ) {
8631                 return false;
8632             }
8633             if ( !it.next().getName().equals( "D" ) ) {
8634                 return false;
8635             }
8636             if ( !it.next().getName().equals( "efgh" ) ) {
8637                 return false;
8638             }
8639             if ( !it.next().getName().equals( "ef" ) ) {
8640                 return false;
8641             }
8642             if ( !it.next().getName().equals( "E" ) ) {
8643                 return false;
8644             }
8645             if ( !it.next().getName().equals( "F" ) ) {
8646                 return false;
8647             }
8648             if ( !it.next().getName().equals( "gh" ) ) {
8649                 return false;
8650             }
8651             if ( !it.next().getName().equals( "G" ) ) {
8652                 return false;
8653             }
8654             if ( !it.next().getName().equals( "H" ) ) {
8655                 return false;
8656             }
8657             if ( it.hasNext() ) {
8658                 return false;
8659             }
8660         }
8661         catch ( final Exception e ) {
8662             e.printStackTrace( System.out );
8663             return false;
8664         }
8665         return true;
8666     }
8667
8668     private static boolean testPropertiesMap() {
8669         try {
8670             final PropertiesMap pm = new PropertiesMap();
8671             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8672             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8673             final Property p2 = new Property( "something:else",
8674                                               "?",
8675                                               "improbable:research",
8676                                               "xsd:decimal",
8677                                               AppliesTo.NODE );
8678             pm.addProperty( p0 );
8679             pm.addProperty( p1 );
8680             pm.addProperty( p2 );
8681             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8682                 return false;
8683             }
8684             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8685                 return false;
8686             }
8687             if ( pm.getProperties().size() != 3 ) {
8688                 return false;
8689             }
8690             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8691                 return false;
8692             }
8693             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8694                 return false;
8695             }
8696             if ( pm.getProperties().size() != 3 ) {
8697                 return false;
8698             }
8699             pm.removeProperty( "dimensions:diameter" );
8700             if ( pm.getProperties().size() != 2 ) {
8701                 return false;
8702             }
8703             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8704                 return false;
8705             }
8706             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8707                 return false;
8708             }
8709         }
8710         catch ( final Exception e ) {
8711             e.printStackTrace( System.out );
8712             return false;
8713         }
8714         return true;
8715     }
8716
8717     private static boolean testProteinId() {
8718         try {
8719             final ProteinId id1 = new ProteinId( "a" );
8720             final ProteinId id2 = new ProteinId( "a" );
8721             final ProteinId id3 = new ProteinId( "A" );
8722             final ProteinId id4 = new ProteinId( "b" );
8723             if ( !id1.equals( id1 ) ) {
8724                 return false;
8725             }
8726             if ( id1.getId().equals( "x" ) ) {
8727                 return false;
8728             }
8729             if ( id1.getId().equals( null ) ) {
8730                 return false;
8731             }
8732             if ( !id1.equals( id2 ) ) {
8733                 return false;
8734             }
8735             if ( id1.equals( id3 ) ) {
8736                 return false;
8737             }
8738             if ( id1.hashCode() != id1.hashCode() ) {
8739                 return false;
8740             }
8741             if ( id1.hashCode() != id2.hashCode() ) {
8742                 return false;
8743             }
8744             if ( id1.hashCode() == id3.hashCode() ) {
8745                 return false;
8746             }
8747             if ( id1.compareTo( id1 ) != 0 ) {
8748                 return false;
8749             }
8750             if ( id1.compareTo( id2 ) != 0 ) {
8751                 return false;
8752             }
8753             if ( id1.compareTo( id3 ) != 0 ) {
8754                 return false;
8755             }
8756             if ( id1.compareTo( id4 ) >= 0 ) {
8757                 return false;
8758             }
8759             if ( id4.compareTo( id1 ) <= 0 ) {
8760                 return false;
8761             }
8762             if ( !id4.getId().equals( "b" ) ) {
8763                 return false;
8764             }
8765             final ProteinId id5 = new ProteinId( " C " );
8766             if ( !id5.getId().equals( "C" ) ) {
8767                 return false;
8768             }
8769             if ( id5.equals( id1 ) ) {
8770                 return false;
8771             }
8772         }
8773         catch ( final Exception e ) {
8774             e.printStackTrace( System.out );
8775             return false;
8776         }
8777         return true;
8778     }
8779
8780     private static boolean testReIdMethods() {
8781         try {
8782             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8783             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8784             final long count = PhylogenyNode.getNodeCount();
8785             p.levelOrderReID();
8786             if ( p.getNode( "r" ).getId() != count ) {
8787                 return false;
8788             }
8789             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8790                 return false;
8791             }
8792             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8793                 return false;
8794             }
8795             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8796                 return false;
8797             }
8798             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8799                 return false;
8800             }
8801             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8802                 return false;
8803             }
8804             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8805                 return false;
8806             }
8807             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8808                 return false;
8809             }
8810             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8811                 return false;
8812             }
8813             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8814                 return false;
8815             }
8816             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8817                 return false;
8818             }
8819             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8820                 return false;
8821             }
8822             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8823                 return false;
8824             }
8825             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8826                 return false;
8827             }
8828             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8829                 return false;
8830             }
8831         }
8832         catch ( final Exception e ) {
8833             e.printStackTrace( System.out );
8834             return false;
8835         }
8836         return true;
8837     }
8838
8839     private static boolean testRerooting() {
8840         try {
8841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8842             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",
8843                                                  new NHXParser() )[ 0 ];
8844             if ( !t1.isRooted() ) {
8845                 return false;
8846             }
8847             t1.reRoot( t1.getNode( "D" ) );
8848             t1.reRoot( t1.getNode( "CD" ) );
8849             t1.reRoot( t1.getNode( "A" ) );
8850             t1.reRoot( t1.getNode( "B" ) );
8851             t1.reRoot( t1.getNode( "AB" ) );
8852             t1.reRoot( t1.getNode( "D" ) );
8853             t1.reRoot( t1.getNode( "C" ) );
8854             t1.reRoot( t1.getNode( "CD" ) );
8855             t1.reRoot( t1.getNode( "A" ) );
8856             t1.reRoot( t1.getNode( "B" ) );
8857             t1.reRoot( t1.getNode( "AB" ) );
8858             t1.reRoot( t1.getNode( "D" ) );
8859             t1.reRoot( t1.getNode( "D" ) );
8860             t1.reRoot( t1.getNode( "C" ) );
8861             t1.reRoot( t1.getNode( "A" ) );
8862             t1.reRoot( t1.getNode( "B" ) );
8863             t1.reRoot( t1.getNode( "AB" ) );
8864             t1.reRoot( t1.getNode( "C" ) );
8865             t1.reRoot( t1.getNode( "D" ) );
8866             t1.reRoot( t1.getNode( "CD" ) );
8867             t1.reRoot( t1.getNode( "D" ) );
8868             t1.reRoot( t1.getNode( "A" ) );
8869             t1.reRoot( t1.getNode( "B" ) );
8870             t1.reRoot( t1.getNode( "AB" ) );
8871             t1.reRoot( t1.getNode( "C" ) );
8872             t1.reRoot( t1.getNode( "D" ) );
8873             t1.reRoot( t1.getNode( "CD" ) );
8874             t1.reRoot( t1.getNode( "D" ) );
8875             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
8876                 return false;
8877             }
8878             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
8879                 return false;
8880             }
8881             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
8882                 return false;
8883             }
8884             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
8885                 return false;
8886             }
8887             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
8888                 return false;
8889             }
8890             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
8891                 return false;
8892             }
8893             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",
8894                                                  new NHXParser() )[ 0 ];
8895             t2.reRoot( t2.getNode( "A" ) );
8896             t2.reRoot( t2.getNode( "D" ) );
8897             t2.reRoot( t2.getNode( "ABC" ) );
8898             t2.reRoot( t2.getNode( "A" ) );
8899             t2.reRoot( t2.getNode( "B" ) );
8900             t2.reRoot( t2.getNode( "D" ) );
8901             t2.reRoot( t2.getNode( "C" ) );
8902             t2.reRoot( t2.getNode( "ABC" ) );
8903             t2.reRoot( t2.getNode( "A" ) );
8904             t2.reRoot( t2.getNode( "B" ) );
8905             t2.reRoot( t2.getNode( "AB" ) );
8906             t2.reRoot( t2.getNode( "AB" ) );
8907             t2.reRoot( t2.getNode( "D" ) );
8908             t2.reRoot( t2.getNode( "C" ) );
8909             t2.reRoot( t2.getNode( "B" ) );
8910             t2.reRoot( t2.getNode( "AB" ) );
8911             t2.reRoot( t2.getNode( "D" ) );
8912             t2.reRoot( t2.getNode( "D" ) );
8913             t2.reRoot( t2.getNode( "ABC" ) );
8914             t2.reRoot( t2.getNode( "A" ) );
8915             t2.reRoot( t2.getNode( "B" ) );
8916             t2.reRoot( t2.getNode( "AB" ) );
8917             t2.reRoot( t2.getNode( "D" ) );
8918             t2.reRoot( t2.getNode( "C" ) );
8919             t2.reRoot( t2.getNode( "ABC" ) );
8920             t2.reRoot( t2.getNode( "A" ) );
8921             t2.reRoot( t2.getNode( "B" ) );
8922             t2.reRoot( t2.getNode( "AB" ) );
8923             t2.reRoot( t2.getNode( "D" ) );
8924             t2.reRoot( t2.getNode( "D" ) );
8925             t2.reRoot( t2.getNode( "C" ) );
8926             t2.reRoot( t2.getNode( "A" ) );
8927             t2.reRoot( t2.getNode( "B" ) );
8928             t2.reRoot( t2.getNode( "AB" ) );
8929             t2.reRoot( t2.getNode( "C" ) );
8930             t2.reRoot( t2.getNode( "D" ) );
8931             t2.reRoot( t2.getNode( "ABC" ) );
8932             t2.reRoot( t2.getNode( "D" ) );
8933             t2.reRoot( t2.getNode( "A" ) );
8934             t2.reRoot( t2.getNode( "B" ) );
8935             t2.reRoot( t2.getNode( "AB" ) );
8936             t2.reRoot( t2.getNode( "C" ) );
8937             t2.reRoot( t2.getNode( "D" ) );
8938             t2.reRoot( t2.getNode( "ABC" ) );
8939             t2.reRoot( t2.getNode( "D" ) );
8940             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8941                 return false;
8942             }
8943             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8944                 return false;
8945             }
8946             t2.reRoot( t2.getNode( "ABC" ) );
8947             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8948                 return false;
8949             }
8950             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8951                 return false;
8952             }
8953             t2.reRoot( t2.getNode( "AB" ) );
8954             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8955                 return false;
8956             }
8957             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8958                 return false;
8959             }
8960             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8961                 return false;
8962             }
8963             t2.reRoot( t2.getNode( "AB" ) );
8964             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8965                 return false;
8966             }
8967             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8968                 return false;
8969             }
8970             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8971                 return false;
8972             }
8973             t2.reRoot( t2.getNode( "D" ) );
8974             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8975                 return false;
8976             }
8977             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8978                 return false;
8979             }
8980             t2.reRoot( t2.getNode( "ABC" ) );
8981             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8982                 return false;
8983             }
8984             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8985                 return false;
8986             }
8987             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
8988                                                  new NHXParser() )[ 0 ];
8989             t3.reRoot( t3.getNode( "B" ) );
8990             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8991                 return false;
8992             }
8993             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8994                 return false;
8995             }
8996             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8997                 return false;
8998             }
8999             t3.reRoot( t3.getNode( "B" ) );
9000             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9001                 return false;
9002             }
9003             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9004                 return false;
9005             }
9006             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9007                 return false;
9008             }
9009             t3.reRoot( t3.getRoot() );
9010             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9011                 return false;
9012             }
9013             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9014                 return false;
9015             }
9016             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9017                 return false;
9018             }
9019         }
9020         catch ( final Exception e ) {
9021             e.printStackTrace( System.out );
9022             return false;
9023         }
9024         return true;
9025     }
9026
9027     private static boolean testSDIse() {
9028         try {
9029             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9030             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9031             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9032             gene1.setRooted( true );
9033             species1.setRooted( true );
9034             final SDI sdi = new SDI( gene1, species1 );
9035             if ( !gene1.getRoot().isDuplication() ) {
9036                 return false;
9037             }
9038             final Phylogeny species2 = factory
9039                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9040                              new NHXParser() )[ 0 ];
9041             final Phylogeny gene2 = factory
9042                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9043                              new NHXParser() )[ 0 ];
9044             species2.setRooted( true );
9045             gene2.setRooted( true );
9046             final SDI sdi2 = new SDI( gene2, species2 );
9047             if ( sdi2.getDuplicationsSum() != 0 ) {
9048                 return false;
9049             }
9050             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9051                 return false;
9052             }
9053             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9054                 return false;
9055             }
9056             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9057                 return false;
9058             }
9059             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9060                 return false;
9061             }
9062             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9063                 return false;
9064             }
9065             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9066                 return false;
9067             }
9068             final Phylogeny species3 = factory
9069                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9070                              new NHXParser() )[ 0 ];
9071             final Phylogeny gene3 = factory
9072                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9073                              new NHXParser() )[ 0 ];
9074             species3.setRooted( true );
9075             gene3.setRooted( true );
9076             final SDI sdi3 = new SDI( gene3, species3 );
9077             if ( sdi3.getDuplicationsSum() != 1 ) {
9078                 return false;
9079             }
9080             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9081                 return false;
9082             }
9083             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9084                 return false;
9085             }
9086             final Phylogeny species4 = factory
9087                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9088                              new NHXParser() )[ 0 ];
9089             final Phylogeny gene4 = factory
9090                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9091                              new NHXParser() )[ 0 ];
9092             species4.setRooted( true );
9093             gene4.setRooted( true );
9094             final SDI sdi4 = new SDI( gene4, species4 );
9095             if ( sdi4.getDuplicationsSum() != 1 ) {
9096                 return false;
9097             }
9098             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9099                 return false;
9100             }
9101             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9102                 return false;
9103             }
9104             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9105                 return false;
9106             }
9107             if ( species4.getNumberOfExternalNodes() != 6 ) {
9108                 return false;
9109             }
9110             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9111                 return false;
9112             }
9113             final Phylogeny species5 = factory
9114                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9115                              new NHXParser() )[ 0 ];
9116             final Phylogeny gene5 = factory
9117                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9118                              new NHXParser() )[ 0 ];
9119             species5.setRooted( true );
9120             gene5.setRooted( true );
9121             final SDI sdi5 = new SDI( gene5, species5 );
9122             if ( sdi5.getDuplicationsSum() != 2 ) {
9123                 return false;
9124             }
9125             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9126                 return false;
9127             }
9128             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9129                 return false;
9130             }
9131             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9132                 return false;
9133             }
9134             if ( species5.getNumberOfExternalNodes() != 6 ) {
9135                 return false;
9136             }
9137             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9138                 return false;
9139             }
9140             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9141             // Conjecture for Comparing Molecular Phylogenies"
9142             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9143             final Phylogeny species6 = factory
9144                     .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,"
9145                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9146                              new NHXParser() )[ 0 ];
9147             final Phylogeny gene6 = factory
9148                     .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,"
9149                                      + "((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,"
9150                                      + "(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;",
9151                              new NHXParser() )[ 0 ];
9152             species6.setRooted( true );
9153             gene6.setRooted( true );
9154             final SDI sdi6 = new SDI( gene6, species6 );
9155             if ( sdi6.getDuplicationsSum() != 3 ) {
9156                 return false;
9157             }
9158             if ( !gene6.getNode( "r" ).isDuplication() ) {
9159                 return false;
9160             }
9161             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9162                 return false;
9163             }
9164             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9165                 return false;
9166             }
9167             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9168                 return false;
9169             }
9170             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9171                 return false;
9172             }
9173             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9174                 return false;
9175             }
9176             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9177                 return false;
9178             }
9179             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9180                 return false;
9181             }
9182             sdi6.computeMappingCostL();
9183             if ( sdi6.computeMappingCostL() != 17 ) {
9184                 return false;
9185             }
9186             if ( species6.getNumberOfExternalNodes() != 9 ) {
9187                 return false;
9188             }
9189             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9190                 return false;
9191             }
9192             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9193                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9194                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9195                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9196                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9197             species7.setRooted( true );
9198             final Phylogeny gene7_1 = Test
9199                     .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])" );
9200             gene7_1.setRooted( true );
9201             final SDI sdi7 = new SDI( gene7_1, species7 );
9202             if ( sdi7.getDuplicationsSum() != 0 ) {
9203                 return false;
9204             }
9205             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9206                 return false;
9207             }
9208             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9209                 return false;
9210             }
9211             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9212                 return false;
9213             }
9214             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9215                 return false;
9216             }
9217             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9218                 return false;
9219             }
9220             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9221                 return false;
9222             }
9223             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9224                 return false;
9225             }
9226             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9227                 return false;
9228             }
9229             final Phylogeny gene7_2 = Test
9230                     .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])" );
9231             gene7_2.setRooted( true );
9232             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9233             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9234                 return false;
9235             }
9236             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9237                 return false;
9238             }
9239             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9240                 return false;
9241             }
9242             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9243                 return false;
9244             }
9245             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9246                 return false;
9247             }
9248             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9249                 return false;
9250             }
9251             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9252                 return false;
9253             }
9254             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9255                 return false;
9256             }
9257             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9258                 return false;
9259             }
9260             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9261                 return false;
9262             }
9263         }
9264         catch ( final Exception e ) {
9265             return false;
9266         }
9267         return true;
9268     }
9269
9270     private static boolean testSDIunrooted() {
9271         try {
9272             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9273             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9274             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9275             final Iterator<PhylogenyBranch> iter = l.iterator();
9276             PhylogenyBranch br = iter.next();
9277             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9278                 return false;
9279             }
9280             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9281                 return false;
9282             }
9283             br = iter.next();
9284             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9285                 return false;
9286             }
9287             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9288                 return false;
9289             }
9290             br = iter.next();
9291             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9292                 return false;
9293             }
9294             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9295                 return false;
9296             }
9297             br = iter.next();
9298             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9299                 return false;
9300             }
9301             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9302                 return false;
9303             }
9304             br = iter.next();
9305             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9306                 return false;
9307             }
9308             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9309                 return false;
9310             }
9311             br = iter.next();
9312             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9313                 return false;
9314             }
9315             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9316                 return false;
9317             }
9318             br = iter.next();
9319             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9320                 return false;
9321             }
9322             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9323                 return false;
9324             }
9325             br = iter.next();
9326             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9327                 return false;
9328             }
9329             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9330                 return false;
9331             }
9332             br = iter.next();
9333             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9334                 return false;
9335             }
9336             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9337                 return false;
9338             }
9339             br = iter.next();
9340             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9341                 return false;
9342             }
9343             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9344                 return false;
9345             }
9346             br = iter.next();
9347             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9348                 return false;
9349             }
9350             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9351                 return false;
9352             }
9353             br = iter.next();
9354             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9355                 return false;
9356             }
9357             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9358                 return false;
9359             }
9360             br = iter.next();
9361             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9362                 return false;
9363             }
9364             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9365                 return false;
9366             }
9367             br = iter.next();
9368             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9369                 return false;
9370             }
9371             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9372                 return false;
9373             }
9374             br = iter.next();
9375             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9376                 return false;
9377             }
9378             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9379                 return false;
9380             }
9381             if ( iter.hasNext() ) {
9382                 return false;
9383             }
9384             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9385             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9386             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9387             br = iter1.next();
9388             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9389                 return false;
9390             }
9391             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9392                 return false;
9393             }
9394             br = iter1.next();
9395             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9396                 return false;
9397             }
9398             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9399                 return false;
9400             }
9401             br = iter1.next();
9402             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9403                 return false;
9404             }
9405             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9406                 return false;
9407             }
9408             if ( iter1.hasNext() ) {
9409                 return false;
9410             }
9411             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9412             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9413             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9414             br = iter2.next();
9415             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9416                 return false;
9417             }
9418             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9419                 return false;
9420             }
9421             br = iter2.next();
9422             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9423                 return false;
9424             }
9425             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9426                 return false;
9427             }
9428             br = iter2.next();
9429             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9430                 return false;
9431             }
9432             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9433                 return false;
9434             }
9435             if ( iter2.hasNext() ) {
9436                 return false;
9437             }
9438             final Phylogeny species0 = factory
9439                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9440                              new NHXParser() )[ 0 ];
9441             final Phylogeny gene1 = factory
9442                     .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])",
9443                              new NHXParser() )[ 0 ];
9444             species0.setRooted( true );
9445             gene1.setRooted( true );
9446             final SDIR sdi_unrooted = new SDIR();
9447             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9448             if ( sdi_unrooted.getCount() != 1 ) {
9449                 return false;
9450             }
9451             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9452                 return false;
9453             }
9454             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9455                 return false;
9456             }
9457             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9458                 return false;
9459             }
9460             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9461                 return false;
9462             }
9463             final Phylogeny gene2 = factory
9464                     .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])",
9465                              new NHXParser() )[ 0 ];
9466             gene2.setRooted( true );
9467             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9468             if ( sdi_unrooted.getCount() != 1 ) {
9469                 return false;
9470             }
9471             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9472                 return false;
9473             }
9474             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9475                 return false;
9476             }
9477             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9478                 return false;
9479             }
9480             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9481                 return false;
9482             }
9483             final Phylogeny species6 = factory
9484                     .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,"
9485                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9486                              new NHXParser() )[ 0 ];
9487             final Phylogeny gene6 = factory
9488                     .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],"
9489                                      + "(((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],"
9490                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9491                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9492                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9493                              new NHXParser() )[ 0 ];
9494             species6.setRooted( true );
9495             gene6.setRooted( true );
9496             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9497             if ( sdi_unrooted.getCount() != 1 ) {
9498                 return false;
9499             }
9500             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9501                 return false;
9502             }
9503             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9504                 return false;
9505             }
9506             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9507                 return false;
9508             }
9509             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9510                 return false;
9511             }
9512             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9513                 return false;
9514             }
9515             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9516                 return false;
9517             }
9518             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9519                 return false;
9520             }
9521             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9522                 return false;
9523             }
9524             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9525                 return false;
9526             }
9527             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9528                 return false;
9529             }
9530             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9531                 return false;
9532             }
9533             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9534                 return false;
9535             }
9536             p6 = null;
9537             final Phylogeny species7 = factory
9538                     .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,"
9539                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9540                              new NHXParser() )[ 0 ];
9541             final Phylogeny gene7 = factory
9542                     .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],"
9543                                      + "(((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],"
9544                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9545                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9546                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9547                              new NHXParser() )[ 0 ];
9548             species7.setRooted( true );
9549             gene7.setRooted( true );
9550             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9551             if ( sdi_unrooted.getCount() != 1 ) {
9552                 return false;
9553             }
9554             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9555                 return false;
9556             }
9557             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9558                 return false;
9559             }
9560             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9561                 return false;
9562             }
9563             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9564                 return false;
9565             }
9566             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9567                 return false;
9568             }
9569             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9570                 return false;
9571             }
9572             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9573                 return false;
9574             }
9575             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9576                 return false;
9577             }
9578             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9579                 return false;
9580             }
9581             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9582                 return false;
9583             }
9584             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9585                 return false;
9586             }
9587             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9588                 return false;
9589             }
9590             p7 = null;
9591             final Phylogeny species8 = factory
9592                     .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,"
9593                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9594                              new NHXParser() )[ 0 ];
9595             final Phylogeny gene8 = factory
9596                     .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],"
9597                                      + "(((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],"
9598                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9599                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9600                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9601                              new NHXParser() )[ 0 ];
9602             species8.setRooted( true );
9603             gene8.setRooted( true );
9604             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9605             if ( sdi_unrooted.getCount() != 1 ) {
9606                 return false;
9607             }
9608             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9609                 return false;
9610             }
9611             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9612                 return false;
9613             }
9614             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9615                 return false;
9616             }
9617             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9618                 return false;
9619             }
9620             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9621                 return false;
9622             }
9623             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9624                 return false;
9625             }
9626             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9627                 return false;
9628             }
9629             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9630                 return false;
9631             }
9632             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9633                 return false;
9634             }
9635             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9636                 return false;
9637             }
9638             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9639                 return false;
9640             }
9641             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9642                 return false;
9643             }
9644             p8 = null;
9645         }
9646         catch ( final Exception e ) {
9647             e.printStackTrace( System.out );
9648             return false;
9649         }
9650         return true;
9651     }
9652
9653     private static boolean testSequenceIdParsing() {
9654         try {
9655             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
9656             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9657                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9658                 if ( id != null ) {
9659                     System.out.println( "value   =" + id.getValue() );
9660                     System.out.println( "provider=" + id.getSource() );
9661                 }
9662                 return false;
9663             }
9664             //
9665             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
9666             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9667                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9668                 if ( id != null ) {
9669                     System.out.println( "value   =" + id.getValue() );
9670                     System.out.println( "provider=" + id.getSource() );
9671                 }
9672                 return false;
9673             }
9674             //
9675             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
9676             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9677                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9678                 if ( id != null ) {
9679                     System.out.println( "value   =" + id.getValue() );
9680                     System.out.println( "provider=" + id.getSource() );
9681                 }
9682                 return false;
9683             }
9684             // 
9685             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
9686             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9687                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
9688                 if ( id != null ) {
9689                     System.out.println( "value   =" + id.getValue() );
9690                     System.out.println( "provider=" + id.getSource() );
9691                 }
9692                 return false;
9693             }
9694             // 
9695             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
9696             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9697                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
9698                 if ( id != null ) {
9699                     System.out.println( "value   =" + id.getValue() );
9700                     System.out.println( "provider=" + id.getSource() );
9701                 }
9702                 return false;
9703             }
9704             // 
9705             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
9706             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9707                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
9708                 if ( id != null ) {
9709                     System.out.println( "value   =" + id.getValue() );
9710                     System.out.println( "provider=" + id.getSource() );
9711                 }
9712                 return false;
9713             }
9714             // 
9715             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
9716             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9717                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
9718                 if ( id != null ) {
9719                     System.out.println( "value   =" + id.getValue() );
9720                     System.out.println( "provider=" + id.getSource() );
9721                 }
9722                 return false;
9723             }
9724             // 
9725             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
9726             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9727                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9728                 if ( id != null ) {
9729                     System.out.println( "value   =" + id.getValue() );
9730                     System.out.println( "provider=" + id.getSource() );
9731                 }
9732                 return false;
9733             }
9734             // 
9735             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
9736             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9737                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9738                 if ( id != null ) {
9739                     System.out.println( "value   =" + id.getValue() );
9740                     System.out.println( "provider=" + id.getSource() );
9741                 }
9742                 return false;
9743             }
9744             // 
9745             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
9746             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9747                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
9748                 if ( id != null ) {
9749                     System.out.println( "value   =" + id.getValue() );
9750                     System.out.println( "provider=" + id.getSource() );
9751                 }
9752                 return false;
9753             }
9754             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
9755             if ( id != null ) {
9756                 System.out.println( "value   =" + id.getValue() );
9757                 System.out.println( "provider=" + id.getSource() );
9758                 return false;
9759             }
9760         }
9761         catch ( final Exception e ) {
9762             e.printStackTrace( System.out );
9763             return false;
9764         }
9765         return true;
9766     }
9767
9768     private static boolean testSequenceWriter() {
9769         try {
9770             final String n = ForesterUtil.LINE_SEPARATOR;
9771             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9772                 return false;
9773             }
9774             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9775                 return false;
9776             }
9777             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9778                 return false;
9779             }
9780             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9781                 return false;
9782             }
9783             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9784                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9785                 return false;
9786             }
9787             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9788                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9789                 return false;
9790             }
9791         }
9792         catch ( final Exception e ) {
9793             e.printStackTrace();
9794             return false;
9795         }
9796         return true;
9797     }
9798
9799     private static boolean testSpecies() {
9800         try {
9801             final Species s1 = new BasicSpecies( "a" );
9802             final Species s2 = new BasicSpecies( "a" );
9803             final Species s3 = new BasicSpecies( "A" );
9804             final Species s4 = new BasicSpecies( "b" );
9805             if ( !s1.equals( s1 ) ) {
9806                 return false;
9807             }
9808             if ( s1.getSpeciesId().equals( "x" ) ) {
9809                 return false;
9810             }
9811             if ( s1.getSpeciesId().equals( null ) ) {
9812                 return false;
9813             }
9814             if ( !s1.equals( s2 ) ) {
9815                 return false;
9816             }
9817             if ( s1.equals( s3 ) ) {
9818                 return false;
9819             }
9820             if ( s1.hashCode() != s1.hashCode() ) {
9821                 return false;
9822             }
9823             if ( s1.hashCode() != s2.hashCode() ) {
9824                 return false;
9825             }
9826             if ( s1.hashCode() == s3.hashCode() ) {
9827                 return false;
9828             }
9829             if ( s1.compareTo( s1 ) != 0 ) {
9830                 return false;
9831             }
9832             if ( s1.compareTo( s2 ) != 0 ) {
9833                 return false;
9834             }
9835             if ( s1.compareTo( s3 ) != 0 ) {
9836                 return false;
9837             }
9838             if ( s1.compareTo( s4 ) >= 0 ) {
9839                 return false;
9840             }
9841             if ( s4.compareTo( s1 ) <= 0 ) {
9842                 return false;
9843             }
9844             if ( !s4.getSpeciesId().equals( "b" ) ) {
9845                 return false;
9846             }
9847             final Species s5 = new BasicSpecies( " C " );
9848             if ( !s5.getSpeciesId().equals( "C" ) ) {
9849                 return false;
9850             }
9851             if ( s5.equals( s1 ) ) {
9852                 return false;
9853             }
9854         }
9855         catch ( final Exception e ) {
9856             e.printStackTrace( System.out );
9857             return false;
9858         }
9859         return true;
9860     }
9861
9862     private static boolean testSplit() {
9863         try {
9864             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9865             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
9866             //Archaeopteryx.createApplication( p0 );
9867             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
9868             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9869             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9870             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9871             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9872             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9873             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9874             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9875             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
9876             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
9877             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
9878             // System.out.println( s0.toString() );
9879             //
9880             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
9881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9883             if ( s0.match( query_nodes ) ) {
9884                 return false;
9885             }
9886             query_nodes = new HashSet<PhylogenyNode>();
9887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9894             if ( !s0.match( query_nodes ) ) {
9895                 return false;
9896             }
9897             //
9898             query_nodes = new HashSet<PhylogenyNode>();
9899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9902             if ( !s0.match( query_nodes ) ) {
9903                 return false;
9904             }
9905             //
9906             query_nodes = new HashSet<PhylogenyNode>();
9907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9911             if ( !s0.match( query_nodes ) ) {
9912                 return false;
9913             }
9914             //
9915             query_nodes = new HashSet<PhylogenyNode>();
9916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9920             if ( !s0.match( query_nodes ) ) {
9921                 return false;
9922             }
9923             //
9924             query_nodes = new HashSet<PhylogenyNode>();
9925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9928             if ( !s0.match( query_nodes ) ) {
9929                 return false;
9930             }
9931             //
9932             query_nodes = new HashSet<PhylogenyNode>();
9933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9935             if ( !s0.match( query_nodes ) ) {
9936                 return false;
9937             }
9938             //
9939             query_nodes = new HashSet<PhylogenyNode>();
9940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9945             if ( !s0.match( query_nodes ) ) {
9946                 return false;
9947             }
9948             //
9949             query_nodes = new HashSet<PhylogenyNode>();
9950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9953             if ( !s0.match( query_nodes ) ) {
9954                 return false;
9955             }
9956             //
9957             query_nodes = new HashSet<PhylogenyNode>();
9958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9962             if ( !s0.match( query_nodes ) ) {
9963                 return false;
9964             }
9965             //
9966             query_nodes = new HashSet<PhylogenyNode>();
9967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9969             if ( s0.match( query_nodes ) ) {
9970                 return false;
9971             }
9972             //
9973             query_nodes = new HashSet<PhylogenyNode>();
9974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9978             if ( s0.match( query_nodes ) ) {
9979                 return false;
9980             }
9981             //
9982             query_nodes = new HashSet<PhylogenyNode>();
9983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9988             if ( s0.match( query_nodes ) ) {
9989                 return false;
9990             }
9991             //
9992             query_nodes = new HashSet<PhylogenyNode>();
9993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9996             if ( s0.match( query_nodes ) ) {
9997                 return false;
9998             }
9999             //
10000             query_nodes = new HashSet<PhylogenyNode>();
10001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10003             if ( s0.match( query_nodes ) ) {
10004                 return false;
10005             }
10006             //
10007             query_nodes = new HashSet<PhylogenyNode>();
10008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10010             if ( s0.match( query_nodes ) ) {
10011                 return false;
10012             }
10013             //
10014             query_nodes = new HashSet<PhylogenyNode>();
10015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10017             if ( s0.match( query_nodes ) ) {
10018                 return false;
10019             }
10020             //
10021             query_nodes = new HashSet<PhylogenyNode>();
10022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10024             if ( s0.match( query_nodes ) ) {
10025                 return false;
10026             }
10027             //
10028             query_nodes = new HashSet<PhylogenyNode>();
10029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10031             if ( s0.match( query_nodes ) ) {
10032                 return false;
10033             }
10034             //
10035             query_nodes = new HashSet<PhylogenyNode>();
10036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10038             if ( s0.match( query_nodes ) ) {
10039                 return false;
10040             }
10041             //
10042             query_nodes = new HashSet<PhylogenyNode>();
10043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10046             if ( s0.match( query_nodes ) ) {
10047                 return false;
10048             }
10049             //
10050             query_nodes = new HashSet<PhylogenyNode>();
10051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10054             if ( s0.match( query_nodes ) ) {
10055                 return false;
10056             }
10057             //
10058             query_nodes = new HashSet<PhylogenyNode>();
10059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10062             if ( s0.match( query_nodes ) ) {
10063                 return false;
10064             }
10065             //
10066             query_nodes = new HashSet<PhylogenyNode>();
10067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10071             if ( s0.match( query_nodes ) ) {
10072                 return false;
10073             }
10074             /////////
10075             //            query_nodes = new HashSet<PhylogenyNode>();
10076             //            query_nodes.add( new PhylogenyNode( "X" ) );
10077             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10078             //            query_nodes.add( new PhylogenyNode( "A" ) );
10079             //            query_nodes.add( new PhylogenyNode( "B" ) );
10080             //            query_nodes.add( new PhylogenyNode( "C" ) );
10081             //            query_nodes.add( new PhylogenyNode( "D" ) );
10082             //            query_nodes.add( new PhylogenyNode( "E" ) );
10083             //            query_nodes.add( new PhylogenyNode( "F" ) );
10084             //            query_nodes.add( new PhylogenyNode( "G" ) );
10085             //            if ( !s0.match( query_nodes ) ) {
10086             //                return false;
10087             //            }
10088             //            query_nodes = new HashSet<PhylogenyNode>();
10089             //            query_nodes.add( new PhylogenyNode( "X" ) );
10090             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10091             //            query_nodes.add( new PhylogenyNode( "A" ) );
10092             //            query_nodes.add( new PhylogenyNode( "B" ) );
10093             //            query_nodes.add( new PhylogenyNode( "C" ) );
10094             //            if ( !s0.match( query_nodes ) ) {
10095             //                return false;
10096             //            }
10097             //            //
10098             //            query_nodes = new HashSet<PhylogenyNode>();
10099             //            query_nodes.add( new PhylogenyNode( "X" ) );
10100             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10101             //            query_nodes.add( new PhylogenyNode( "D" ) );
10102             //            query_nodes.add( new PhylogenyNode( "E" ) );
10103             //            query_nodes.add( new PhylogenyNode( "F" ) );
10104             //            query_nodes.add( new PhylogenyNode( "G" ) );
10105             //            if ( !s0.match( query_nodes ) ) {
10106             //                return false;
10107             //            }
10108             //            //
10109             //            query_nodes = new HashSet<PhylogenyNode>();
10110             //            query_nodes.add( new PhylogenyNode( "X" ) );
10111             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10112             //            query_nodes.add( new PhylogenyNode( "A" ) );
10113             //            query_nodes.add( new PhylogenyNode( "B" ) );
10114             //            query_nodes.add( new PhylogenyNode( "C" ) );
10115             //            query_nodes.add( new PhylogenyNode( "D" ) );
10116             //            if ( !s0.match( query_nodes ) ) {
10117             //                return false;
10118             //            }
10119             //            //
10120             //            query_nodes = new HashSet<PhylogenyNode>();
10121             //            query_nodes.add( new PhylogenyNode( "X" ) );
10122             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10123             //            query_nodes.add( new PhylogenyNode( "E" ) );
10124             //            query_nodes.add( new PhylogenyNode( "F" ) );
10125             //            query_nodes.add( new PhylogenyNode( "G" ) );
10126             //            if ( !s0.match( query_nodes ) ) {
10127             //                return false;
10128             //            }
10129             //            //
10130             //            query_nodes = new HashSet<PhylogenyNode>();
10131             //            query_nodes.add( new PhylogenyNode( "X" ) );
10132             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10133             //            query_nodes.add( new PhylogenyNode( "F" ) );
10134             //            query_nodes.add( new PhylogenyNode( "G" ) );
10135             //            if ( !s0.match( query_nodes ) ) {
10136             //                return false;
10137             //            }
10138             //
10139             query_nodes = new HashSet<PhylogenyNode>();
10140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10144             if ( s0.match( query_nodes ) ) {
10145                 return false;
10146             }
10147             //
10148             query_nodes = new HashSet<PhylogenyNode>();
10149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10153             if ( s0.match( query_nodes ) ) {
10154                 return false;
10155             }
10156             ///////////////////////////
10157             //
10158             query_nodes = new HashSet<PhylogenyNode>();
10159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10161             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10162             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10163             if ( s0.match( query_nodes ) ) {
10164                 return false;
10165             }
10166             //
10167             query_nodes = new HashSet<PhylogenyNode>();
10168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10170             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10171             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10172             if ( s0.match( query_nodes ) ) {
10173                 return false;
10174             }
10175             //
10176             query_nodes = new HashSet<PhylogenyNode>();
10177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10178             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10179             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10181             if ( s0.match( query_nodes ) ) {
10182                 return false;
10183             }
10184             //
10185             query_nodes = new HashSet<PhylogenyNode>();
10186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10187             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10190             if ( s0.match( query_nodes ) ) {
10191                 return false;
10192             }
10193             //
10194             query_nodes = new HashSet<PhylogenyNode>();
10195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10198             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10199             if ( s0.match( query_nodes ) ) {
10200                 return false;
10201             }
10202             //
10203             query_nodes = new HashSet<PhylogenyNode>();
10204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10206             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10207             if ( s0.match( query_nodes ) ) {
10208                 return false;
10209             }
10210             //
10211             query_nodes = new HashSet<PhylogenyNode>();
10212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10213             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10214             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10215             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10217             if ( s0.match( query_nodes ) ) {
10218                 return false;
10219             }
10220             //
10221             query_nodes = new HashSet<PhylogenyNode>();
10222             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10227             if ( s0.match( query_nodes ) ) {
10228                 return false;
10229             }
10230             //
10231             query_nodes = new HashSet<PhylogenyNode>();
10232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10235             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10237             if ( s0.match( query_nodes ) ) {
10238                 return false;
10239             }
10240             //
10241             query_nodes = new HashSet<PhylogenyNode>();
10242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10248             if ( s0.match( query_nodes ) ) {
10249                 return false;
10250             }
10251         }
10252         catch ( final Exception e ) {
10253             e.printStackTrace();
10254             return false;
10255         }
10256         return true;
10257     }
10258
10259     private static boolean testSplitStrict() {
10260         try {
10261             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10262             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10263             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10264             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10265             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10266             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10267             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10268             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10269             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10270             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10271             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10272             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10275             if ( s0.match( query_nodes ) ) {
10276                 return false;
10277             }
10278             query_nodes = new HashSet<PhylogenyNode>();
10279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10286             if ( !s0.match( query_nodes ) ) {
10287                 return false;
10288             }
10289             //
10290             query_nodes = new HashSet<PhylogenyNode>();
10291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10294             if ( !s0.match( query_nodes ) ) {
10295                 return false;
10296             }
10297             //
10298             query_nodes = new HashSet<PhylogenyNode>();
10299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10303             if ( !s0.match( query_nodes ) ) {
10304                 return false;
10305             }
10306             //
10307             query_nodes = new HashSet<PhylogenyNode>();
10308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10312             if ( !s0.match( query_nodes ) ) {
10313                 return false;
10314             }
10315             //
10316             query_nodes = new HashSet<PhylogenyNode>();
10317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10320             if ( !s0.match( query_nodes ) ) {
10321                 return false;
10322             }
10323             //
10324             query_nodes = new HashSet<PhylogenyNode>();
10325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10327             if ( !s0.match( query_nodes ) ) {
10328                 return false;
10329             }
10330             //
10331             query_nodes = new HashSet<PhylogenyNode>();
10332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10337             if ( !s0.match( query_nodes ) ) {
10338                 return false;
10339             }
10340             //
10341             query_nodes = new HashSet<PhylogenyNode>();
10342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10343             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10344             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10345             if ( !s0.match( query_nodes ) ) {
10346                 return false;
10347             }
10348             //
10349             query_nodes = new HashSet<PhylogenyNode>();
10350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10354             if ( !s0.match( query_nodes ) ) {
10355                 return false;
10356             }
10357             //
10358             query_nodes = new HashSet<PhylogenyNode>();
10359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10361             if ( s0.match( query_nodes ) ) {
10362                 return false;
10363             }
10364             //
10365             query_nodes = new HashSet<PhylogenyNode>();
10366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10370             if ( s0.match( query_nodes ) ) {
10371                 return false;
10372             }
10373             //
10374             query_nodes = new HashSet<PhylogenyNode>();
10375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10380             if ( s0.match( query_nodes ) ) {
10381                 return false;
10382             }
10383             //
10384             query_nodes = new HashSet<PhylogenyNode>();
10385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10388             if ( s0.match( query_nodes ) ) {
10389                 return false;
10390             }
10391             //
10392             query_nodes = new HashSet<PhylogenyNode>();
10393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10395             if ( s0.match( query_nodes ) ) {
10396                 return false;
10397             }
10398             //
10399             query_nodes = new HashSet<PhylogenyNode>();
10400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10402             if ( s0.match( query_nodes ) ) {
10403                 return false;
10404             }
10405             //
10406             query_nodes = new HashSet<PhylogenyNode>();
10407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10409             if ( s0.match( query_nodes ) ) {
10410                 return false;
10411             }
10412             //
10413             query_nodes = new HashSet<PhylogenyNode>();
10414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10415             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10416             if ( s0.match( query_nodes ) ) {
10417                 return false;
10418             }
10419             //
10420             query_nodes = new HashSet<PhylogenyNode>();
10421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10423             if ( s0.match( query_nodes ) ) {
10424                 return false;
10425             }
10426             //
10427             query_nodes = new HashSet<PhylogenyNode>();
10428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10430             if ( s0.match( query_nodes ) ) {
10431                 return false;
10432             }
10433             //
10434             query_nodes = new HashSet<PhylogenyNode>();
10435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10438             if ( s0.match( query_nodes ) ) {
10439                 return false;
10440             }
10441             //
10442             query_nodes = new HashSet<PhylogenyNode>();
10443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10446             if ( s0.match( query_nodes ) ) {
10447                 return false;
10448             }
10449             //
10450             query_nodes = new HashSet<PhylogenyNode>();
10451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10454             if ( s0.match( query_nodes ) ) {
10455                 return false;
10456             }
10457             //
10458             query_nodes = new HashSet<PhylogenyNode>();
10459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10463             if ( s0.match( query_nodes ) ) {
10464                 return false;
10465             }
10466         }
10467         catch ( final Exception e ) {
10468             e.printStackTrace();
10469             return false;
10470         }
10471         return true;
10472     }
10473
10474     private static boolean testSubtreeDeletion() {
10475         try {
10476             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10477             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10478             t1.deleteSubtree( t1.getNode( "A" ), false );
10479             if ( t1.getNumberOfExternalNodes() != 5 ) {
10480                 return false;
10481             }
10482             t1.toNewHampshireX();
10483             t1.deleteSubtree( t1.getNode( "E" ), false );
10484             if ( t1.getNumberOfExternalNodes() != 4 ) {
10485                 return false;
10486             }
10487             t1.toNewHampshireX();
10488             t1.deleteSubtree( t1.getNode( "F" ), false );
10489             if ( t1.getNumberOfExternalNodes() != 3 ) {
10490                 return false;
10491             }
10492             t1.toNewHampshireX();
10493             t1.deleteSubtree( t1.getNode( "D" ), false );
10494             t1.toNewHampshireX();
10495             if ( t1.getNumberOfExternalNodes() != 3 ) {
10496                 return false;
10497             }
10498             t1.deleteSubtree( t1.getNode( "def" ), false );
10499             t1.toNewHampshireX();
10500             if ( t1.getNumberOfExternalNodes() != 2 ) {
10501                 return false;
10502             }
10503             t1.deleteSubtree( t1.getNode( "B" ), false );
10504             t1.toNewHampshireX();
10505             if ( t1.getNumberOfExternalNodes() != 1 ) {
10506                 return false;
10507             }
10508             t1.deleteSubtree( t1.getNode( "C" ), false );
10509             t1.toNewHampshireX();
10510             if ( t1.getNumberOfExternalNodes() != 1 ) {
10511                 return false;
10512             }
10513             t1.deleteSubtree( t1.getNode( "abc" ), false );
10514             t1.toNewHampshireX();
10515             if ( t1.getNumberOfExternalNodes() != 1 ) {
10516                 return false;
10517             }
10518             t1.deleteSubtree( t1.getNode( "r" ), false );
10519             if ( t1.getNumberOfExternalNodes() != 0 ) {
10520                 return false;
10521             }
10522             if ( !t1.isEmpty() ) {
10523                 return false;
10524             }
10525             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10526             t2.deleteSubtree( t2.getNode( "A" ), false );
10527             t2.toNewHampshireX();
10528             if ( t2.getNumberOfExternalNodes() != 5 ) {
10529                 return false;
10530             }
10531             t2.deleteSubtree( t2.getNode( "abc" ), false );
10532             t2.toNewHampshireX();
10533             if ( t2.getNumberOfExternalNodes() != 3 ) {
10534                 return false;
10535             }
10536             t2.deleteSubtree( t2.getNode( "def" ), false );
10537             t2.toNewHampshireX();
10538             if ( t2.getNumberOfExternalNodes() != 1 ) {
10539                 return false;
10540             }
10541         }
10542         catch ( final Exception e ) {
10543             e.printStackTrace( System.out );
10544             return false;
10545         }
10546         return true;
10547     }
10548
10549     private static boolean testSupportCount() {
10550         try {
10551             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10552             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10553             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10554                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10555                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10556                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10557                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10558                                                               new NHXParser() );
10559             SupportCount.count( t0_1, phylogenies_1, true, false );
10560             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10561             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10562                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10563                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10564                                                                       + "(((((A,B),C),D),E),(F,G))"
10565                                                                       + "(((((A,B),C),D),E),(F,G))"
10566                                                                       + "(((((A,B),C),D),E),(F,G))"
10567                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10568                                                                       + "(((((A,B),C),D),E),(F,G))"
10569                                                                       + "((((((A,B),C),D),E),F),G)"
10570                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10571                                                               new NHXParser() );
10572             SupportCount.count( t0_2, phylogenies_2, true, false );
10573             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10574             while ( it.hasNext() ) {
10575                 final PhylogenyNode n = it.next();
10576                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10577                     return false;
10578                 }
10579             }
10580             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10581             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10582                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10583             SupportCount.count( t0_3, phylogenies_3, true, false );
10584             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10585             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10586                 return false;
10587             }
10588             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10589                 return false;
10590             }
10591             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10592                 return false;
10593             }
10594             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10595                 return false;
10596             }
10597             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10598                 return false;
10599             }
10600             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10601                 return false;
10602             }
10603             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10604                 return false;
10605             }
10606             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10607                 return false;
10608             }
10609             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10610                 return false;
10611             }
10612             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10613                 return false;
10614             }
10615             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10616             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10617                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10618             SupportCount.count( t0_4, phylogenies_4, true, false );
10619             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10620             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10621                 return false;
10622             }
10623             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10624                 return false;
10625             }
10626             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10627                 return false;
10628             }
10629             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10630                 return false;
10631             }
10632             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10633                 return false;
10634             }
10635             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10636                 return false;
10637             }
10638             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10639                 return false;
10640             }
10641             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10642                 return false;
10643             }
10644             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10645                 return false;
10646             }
10647             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10648                 return false;
10649             }
10650             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10651             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10652             double d = SupportCount.compare( b1, a, true, true, true );
10653             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10654                 return false;
10655             }
10656             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10657             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10658             d = SupportCount.compare( b2, a, true, true, true );
10659             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10660                 return false;
10661             }
10662             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10663             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10664             d = SupportCount.compare( b3, a, true, true, true );
10665             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10666                 return false;
10667             }
10668             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10669             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10670             d = SupportCount.compare( b4, a, true, true, false );
10671             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10672                 return false;
10673             }
10674         }
10675         catch ( final Exception e ) {
10676             e.printStackTrace( System.out );
10677             return false;
10678         }
10679         return true;
10680     }
10681
10682     private static boolean testSupportTransfer() {
10683         try {
10684             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10685             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)",
10686                                                  new NHXParser() )[ 0 ];
10687             final Phylogeny p2 = factory
10688                     .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 ];
10689             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10690                 return false;
10691             }
10692             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10693                 return false;
10694             }
10695             support_transfer.moveBranchLengthsToBootstrap( p1 );
10696             support_transfer.transferSupportValues( p1, p2 );
10697             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10698                 return false;
10699             }
10700             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10701                 return false;
10702             }
10703             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10704                 return false;
10705             }
10706             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10707                 return false;
10708             }
10709             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10710                 return false;
10711             }
10712             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10713                 return false;
10714             }
10715             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10716                 return false;
10717             }
10718             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10719                 return false;
10720             }
10721         }
10722         catch ( final Exception e ) {
10723             e.printStackTrace( System.out );
10724             return false;
10725         }
10726         return true;
10727     }
10728
10729     private static boolean testTaxonomyExtraction() {
10730         try {
10731             final PhylogenyNode n0 = PhylogenyNode
10732                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10733             if ( n0.getNodeData().isHasTaxonomy() ) {
10734                 return false;
10735             }
10736             final PhylogenyNode n1 = PhylogenyNode
10737                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10738             if ( n1.getNodeData().isHasTaxonomy() ) {
10739                 System.out.println( n1.toString() );
10740                 return false;
10741             }
10742             final PhylogenyNode n2x = PhylogenyNode
10743                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10744             if ( n2x.getNodeData().isHasTaxonomy() ) {
10745                 return false;
10746             }
10747             final PhylogenyNode n3 = PhylogenyNode
10748                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10749             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10750                 System.out.println( n3.toString() );
10751                 return false;
10752             }
10753             final PhylogenyNode n4 = PhylogenyNode
10754                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10755             if ( n4.getNodeData().isHasTaxonomy() ) {
10756                 System.out.println( n4.toString() );
10757                 return false;
10758             }
10759             final PhylogenyNode n5 = PhylogenyNode
10760                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10761             if ( n5.getNodeData().isHasTaxonomy() ) {
10762                 System.out.println( n5.toString() );
10763                 return false;
10764             }
10765             final PhylogenyNode n6 = PhylogenyNode
10766                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10767             if ( n6.getNodeData().isHasTaxonomy() ) {
10768                 System.out.println( n6.toString() );
10769                 return false;
10770             }
10771             final PhylogenyNode n7 = PhylogenyNode
10772                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10773             if ( n7.getNodeData().isHasTaxonomy() ) {
10774                 System.out.println( n7.toString() );
10775                 return false;
10776             }
10777             final PhylogenyNode n8 = PhylogenyNode
10778                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10779             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10780                 System.out.println( n8.toString() );
10781                 return false;
10782             }
10783             final PhylogenyNode n9 = PhylogenyNode
10784                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10785             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10786                 System.out.println( n9.toString() );
10787                 return false;
10788             }
10789             final PhylogenyNode n10x = PhylogenyNode
10790                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10791             if ( n10x.getNodeData().isHasTaxonomy() ) {
10792                 System.out.println( n10x.toString() );
10793                 return false;
10794             }
10795             final PhylogenyNode n10xx = PhylogenyNode
10796                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10797             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10798                 System.out.println( n10xx.toString() );
10799                 return false;
10800             }
10801             final PhylogenyNode n10 = PhylogenyNode
10802                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10803             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10804                 System.out.println( n10.toString() );
10805                 return false;
10806             }
10807             final PhylogenyNode n11 = PhylogenyNode
10808                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10809             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10810                 System.out.println( n11.toString() );
10811                 return false;
10812             }
10813             final PhylogenyNode n12 = PhylogenyNode
10814                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10815                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10816             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10817                 System.out.println( n12.toString() );
10818                 return false;
10819             }
10820             final PhylogenyNode n13 = PhylogenyNode
10821                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10822             if ( n13.getNodeData().isHasTaxonomy() ) {
10823                 System.out.println( n13.toString() );
10824                 return false;
10825             }
10826         }
10827         catch ( final Exception e ) {
10828             e.printStackTrace( System.out );
10829             return false;
10830         }
10831         return true;
10832     }
10833
10834     private static boolean testTreeMethods() {
10835         try {
10836             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10837             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
10838             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
10839             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
10840                 System.out.println( t0.toNewHampshireX() );
10841                 return false;
10842             }
10843             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
10844             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
10845             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
10846                 return false;
10847             }
10848             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
10849                 return false;
10850             }
10851             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
10852                 return false;
10853             }
10854         }
10855         catch ( final Exception e ) {
10856             e.printStackTrace( System.out );
10857             return false;
10858         }
10859         return true;
10860     }
10861
10862     private static boolean testSequenceDbWsTools1() {
10863         try {
10864             PhylogenyNode n = new PhylogenyNode();
10865             n.setName( "NP_001025424" );
10866             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10867             if ( acc == null || !acc.getSource().equals( Source.REFSEQ.toString() )
10868                     || !acc.getValue().equals( "NP_001025424" ) ) {
10869                 return false;
10870             }
10871             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10872             acc = SequenceDbWsTools.obtainSeqAccession( n );
10873             if ( acc == null || !acc.getSource().equals( Source.REFSEQ.toString() )
10874                     || !acc.getValue().equals( "NP_001025424" ) ) {
10875                 return false;
10876             }
10877             n.setName( "NP_001025424.1" );
10878             acc = SequenceDbWsTools.obtainSeqAccession( n );
10879             if ( acc == null || !acc.getSource().equals( Source.REFSEQ.toString() )
10880                     || !acc.getValue().equals( "NP_001025424" ) ) {
10881                 return false;
10882             }
10883             n.setName( "NM_001030253" );
10884             acc = SequenceDbWsTools.obtainSeqAccession( n );
10885             if ( acc == null || !acc.getSource().equals( Source.REFSEQ.toString() )
10886                     || !acc.getValue().equals( "NM_001030253" ) ) {
10887                 return false;
10888             }
10889             n.setName( "BCL2_HUMAN" );
10890             acc = SequenceDbWsTools.obtainSeqAccession( n );
10891             if ( acc == null || !acc.getSource().equals( Source.UNIPROT.toString() )
10892                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10893                 System.out.println( acc.toString() );
10894                 return false;
10895             }
10896             n.setName( "P10415" );
10897             acc = SequenceDbWsTools.obtainSeqAccession( n );
10898             if ( acc == null || !acc.getSource().equals( Source.UNIPROT.toString() )
10899                     || !acc.getValue().equals( "P10415" ) ) {
10900                 System.out.println( acc.toString() );
10901                 return false;
10902             }
10903             n.setName( " P10415 " );
10904             acc = SequenceDbWsTools.obtainSeqAccession( n );
10905             if ( acc == null || !acc.getSource().equals( Source.UNIPROT.toString() )
10906                     || !acc.getValue().equals( "P10415" ) ) {
10907                 System.out.println( acc.toString() );
10908                 return false;
10909             }
10910             n.setName( "_P10415|" );
10911             acc = SequenceDbWsTools.obtainSeqAccession( n );
10912             if ( acc == null || !acc.getSource().equals( Source.UNIPROT.toString() )
10913                     || !acc.getValue().equals( "P10415" ) ) {
10914                 System.out.println( acc.toString() );
10915                 return false;
10916             }
10917             n.setName( "AY695820" );
10918             acc = SequenceDbWsTools.obtainSeqAccession( n );
10919             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10920                     || !acc.getValue().equals( "AY695820" ) ) {
10921                 System.out.println( acc.toString() );
10922                 return false;
10923             }
10924             n.setName( "_AY695820_" );
10925             acc = SequenceDbWsTools.obtainSeqAccession( n );
10926             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10927                     || !acc.getValue().equals( "AY695820" ) ) {
10928                 System.out.println( acc.toString() );
10929                 return false;
10930             }
10931             n.setName( "AAA59452" );
10932             acc = SequenceDbWsTools.obtainSeqAccession( n );
10933             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10934                     || !acc.getValue().equals( "AAA59452" ) ) {
10935                 System.out.println( acc.toString() );
10936                 return false;
10937             }
10938             n.setName( "_AAA59452_" );
10939             acc = SequenceDbWsTools.obtainSeqAccession( n );
10940             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10941                     || !acc.getValue().equals( "AAA59452" ) ) {
10942                 System.out.println( acc.toString() );
10943                 return false;
10944             }
10945             n.setName( "AAA59452.1" );
10946             acc = SequenceDbWsTools.obtainSeqAccession( n );
10947             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10948                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10949                 System.out.println( acc.toString() );
10950                 return false;
10951             }
10952             n.setName( "_AAA59452.1_" );
10953             acc = SequenceDbWsTools.obtainSeqAccession( n );
10954             if ( acc == null || !acc.getSource().equals( Source.NCBI.toString() )
10955                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10956                 System.out.println( acc.toString() );
10957                 return false;
10958             }
10959             n.setName( "GI:94894583" );
10960             acc = SequenceDbWsTools.obtainSeqAccession( n );
10961             if ( acc == null || !acc.getSource().equals( Source.GI.toString() ) || !acc.getValue().equals( "94894583" ) ) {
10962                 System.out.println( acc.toString() );
10963                 return false;
10964             }
10965         }
10966         //        catch ( final IOException e ) {
10967         //            System.out.println();
10968         //            System.out.println( "the following might be due to absence internet connection:" );
10969         //            e.printStackTrace( System.out );
10970         //            return true;
10971         //        }
10972         catch ( final Exception e ) {
10973             return false;
10974         }
10975         return true;
10976     }
10977
10978     private static boolean testSequenceDbWsTools2() {
10979         try {
10980             PhylogenyNode n1 = new PhylogenyNode();
10981             n1.setName( "NP_001025424" );
10982             SequenceDbWsTools.obtainSeqInformation( false, 4000, new TreeSet<String>(), n1 );
10983             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10984                 return false;
10985             }
10986             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10987                 return false;
10988             }
10989             PhylogenyNode n2 = new PhylogenyNode();
10990             n2.setName( "NM_001030253" );
10991             SequenceDbWsTools.obtainSeqInformation( false, 4000, new TreeSet<String>(), n2 );
10992             System.out.println( n2.toString() );
10993             if ( !n2.getNodeData().getSequence().getName()
10994                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10995                 return false;
10996             }
10997             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10998                 return false;
10999             }
11000         }
11001         catch ( final IOException e ) {
11002             System.out.println();
11003             System.out.println( "the following might be due to absence internet connection:" );
11004             e.printStackTrace( System.out );
11005             return true;
11006         }
11007         catch ( final Exception e ) {
11008             return false;
11009         }
11010         return true;
11011     }
11012
11013     private static boolean testUniprotEntryRetrieval() {
11014         try {
11015             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11016             if ( !entry.getAccession().equals( "P12345" ) ) {
11017                 return false;
11018             }
11019             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11020                 return false;
11021             }
11022             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11023                 return false;
11024             }
11025             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11026                 return false;
11027             }
11028             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11029                 return false;
11030             }
11031             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11032                 return false;
11033             }
11034         }
11035         catch ( final IOException e ) {
11036             System.out.println();
11037             System.out.println( "the following might be due to absence internet connection:" );
11038             e.printStackTrace( System.out );
11039             return true;
11040         }
11041         catch ( final Exception e ) {
11042             return false;
11043         }
11044         return true;
11045     }
11046
11047     private static boolean testUniprotTaxonomySearch() {
11048         try {
11049             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11050                                                                                                  10 );
11051             if ( results.size() != 1 ) {
11052                 return false;
11053             }
11054             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11055                 return false;
11056             }
11057             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11058                 return false;
11059             }
11060             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11061                 return false;
11062             }
11063             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11064                 return false;
11065             }
11066             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11067                 return false;
11068             }
11069             results = null;
11070             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11071             if ( results.size() != 1 ) {
11072                 return false;
11073             }
11074             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11075                 return false;
11076             }
11077             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11078                 return false;
11079             }
11080             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11081                 return false;
11082             }
11083             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11084                 return false;
11085             }
11086             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11087                 return false;
11088             }
11089             results = null;
11090             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11091             if ( results.size() != 1 ) {
11092                 return false;
11093             }
11094             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11095                 return false;
11096             }
11097             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11098                 return false;
11099             }
11100             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11101                 return false;
11102             }
11103             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11104                 return false;
11105             }
11106             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11107                 return false;
11108             }
11109             results = null;
11110             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11111             if ( results.size() != 1 ) {
11112                 return false;
11113             }
11114             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11115                 return false;
11116             }
11117             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11118                 return false;
11119             }
11120             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11121                 return false;
11122             }
11123             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11124                 return false;
11125             }
11126             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11127                 return false;
11128             }
11129             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11130                 return false;
11131             }
11132             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11133                 return false;
11134             }
11135             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11136                     .equals( "Nematostella vectensis" ) ) {
11137                 System.out.println( results.get( 0 ).getLineage() );
11138                 return false;
11139             }
11140             //
11141             results = null;
11142             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11143             if ( results.size() != 1 ) {
11144                 return false;
11145             }
11146             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11147                 return false;
11148             }
11149             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11150                 return false;
11151             }
11152             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11153                 return false;
11154             }
11155             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11156                 return false;
11157             }
11158             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11159                 return false;
11160             }
11161             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11162                     .equals( "Xenopus tropicalis" ) ) {
11163                 System.out.println( results.get( 0 ).getLineage() );
11164                 return false;
11165             }
11166             //
11167             results = null;
11168             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11169             if ( results.size() != 1 ) {
11170                 return false;
11171             }
11172             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11173                 return false;
11174             }
11175             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11176                 return false;
11177             }
11178             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11179                 return false;
11180             }
11181             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11182                 return false;
11183             }
11184             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11185                 return false;
11186             }
11187             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11188                     .equals( "Xenopus tropicalis" ) ) {
11189                 System.out.println( results.get( 0 ).getLineage() );
11190                 return false;
11191             }
11192             //
11193             results = null;
11194             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11195             if ( results.size() != 1 ) {
11196                 return false;
11197             }
11198             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11199                 return false;
11200             }
11201             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11202                 return false;
11203             }
11204             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11205                 return false;
11206             }
11207             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11208                 return false;
11209             }
11210             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11211                 return false;
11212             }
11213             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11214                     .equals( "Xenopus tropicalis" ) ) {
11215                 System.out.println( results.get( 0 ).getLineage() );
11216                 return false;
11217             }
11218         }
11219         catch ( final IOException e ) {
11220             System.out.println();
11221             System.out.println( "the following might be due to absence internet connection:" );
11222             e.printStackTrace( System.out );
11223             return true;
11224         }
11225         catch ( final Exception e ) {
11226             return false;
11227         }
11228         return true;
11229     }
11230
11231     private static boolean testWabiTxSearch() {
11232         try {
11233             String result = "";
11234             result = TxSearch.searchSimple( "nematostella" );
11235             result = TxSearch.getTxId( "nematostella" );
11236             if ( !result.equals( "45350" ) ) {
11237                 return false;
11238             }
11239             result = TxSearch.getTxName( "45350" );
11240             if ( !result.equals( "Nematostella" ) ) {
11241                 return false;
11242             }
11243             result = TxSearch.getTxId( "nematostella vectensis" );
11244             if ( !result.equals( "45351" ) ) {
11245                 return false;
11246             }
11247             result = TxSearch.getTxName( "45351" );
11248             if ( !result.equals( "Nematostella vectensis" ) ) {
11249                 return false;
11250             }
11251             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11252             if ( !result.equals( "536089" ) ) {
11253                 return false;
11254             }
11255             result = TxSearch.getTxName( "536089" );
11256             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11257                 return false;
11258             }
11259             final List<String> queries = new ArrayList<String>();
11260             queries.add( "Campylobacter coli" );
11261             queries.add( "Escherichia coli" );
11262             queries.add( "Arabidopsis" );
11263             queries.add( "Trichoplax" );
11264             queries.add( "Samanea saman" );
11265             queries.add( "Kluyveromyces marxianus" );
11266             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11267             queries.add( "Bornavirus parrot/PDD/2008" );
11268             final List<RANKS> ranks = new ArrayList<RANKS>();
11269             ranks.add( RANKS.SUPERKINGDOM );
11270             ranks.add( RANKS.KINGDOM );
11271             ranks.add( RANKS.FAMILY );
11272             ranks.add( RANKS.GENUS );
11273             ranks.add( RANKS.TRIBE );
11274             result = TxSearch.searchLineage( queries, ranks );
11275             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11276             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11277         }
11278         catch ( final Exception e ) {
11279             System.out.println();
11280             System.out.println( "the following might be due to absence internet connection:" );
11281             e.printStackTrace( System.out );
11282             return false;
11283         }
11284         return true;
11285     }
11286 }