73c1c1f631d7f6dd0941e9b5c8254570f20da819
[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) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
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 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.TreePanelUtil;
45 import org.forester.archaeopteryx.webservices.WebserviceUtil;
46 import org.forester.development.DevelopmentTools;
47 import org.forester.evoinference.TestPhylogenyReconstruction;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
50 import org.forester.go.TestGo;
51 import org.forester.io.parsers.FastaParser;
52 import org.forester.io.parsers.GeneralMsaParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
55 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
56 import org.forester.io.parsers.nexus.NexusCharactersParser;
57 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
58 import org.forester.io.parsers.nhx.NHXParser;
59 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
60 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
61 import org.forester.io.parsers.tol.TolParser;
62 import org.forester.io.parsers.util.ParserUtils;
63 import org.forester.io.writers.PhylogenyWriter;
64 import org.forester.io.writers.SequenceWriter;
65 import org.forester.msa.BasicMsa;
66 import org.forester.msa.DeleteableMsa;
67 import org.forester.msa.Mafft;
68 import org.forester.msa.Msa;
69 import org.forester.msa.Msa.MSA_FORMAT;
70 import org.forester.msa.MsaInferrer;
71 import org.forester.msa.MsaMethods;
72 import org.forester.pccx.TestPccx;
73 import org.forester.phylogeny.Phylogeny;
74 import org.forester.phylogeny.PhylogenyBranch;
75 import org.forester.phylogeny.PhylogenyMethods;
76 import org.forester.phylogeny.PhylogenyNode;
77 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
78 import org.forester.phylogeny.data.Accession;
79 import org.forester.phylogeny.data.Accession.Source;
80 import org.forester.phylogeny.data.BinaryCharacters;
81 import org.forester.phylogeny.data.BranchWidth;
82 import org.forester.phylogeny.data.Confidence;
83 import org.forester.phylogeny.data.Distribution;
84 import org.forester.phylogeny.data.DomainArchitecture;
85 import org.forester.phylogeny.data.Event;
86 import org.forester.phylogeny.data.Identifier;
87 import org.forester.phylogeny.data.PhylogenyData;
88 import org.forester.phylogeny.data.PhylogenyDataUtil;
89 import org.forester.phylogeny.data.Polygon;
90 import org.forester.phylogeny.data.PropertiesMap;
91 import org.forester.phylogeny.data.Property;
92 import org.forester.phylogeny.data.Property.AppliesTo;
93 import org.forester.phylogeny.data.ProteinDomain;
94 import org.forester.phylogeny.data.Taxonomy;
95 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
96 import org.forester.phylogeny.factories.PhylogenyFactory;
97 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
98 import org.forester.protein.BasicDomain;
99 import org.forester.protein.BasicProtein;
100 import org.forester.protein.Domain;
101 import org.forester.protein.Protein;
102 import org.forester.protein.ProteinId;
103 import org.forester.rio.TestRIO;
104 import org.forester.sdi.SDI;
105 import org.forester.sdi.SDIR;
106 import org.forester.sdi.TestGSDI;
107 import org.forester.sequence.BasicSequence;
108 import org.forester.sequence.Sequence;
109 import org.forester.species.BasicSpecies;
110 import org.forester.species.Species;
111 import org.forester.surfacing.TestSurfacing;
112 import org.forester.tools.ConfidenceAssessor;
113 import org.forester.tools.SupportCount;
114 import org.forester.tools.TreeSplitMatrix;
115 import org.forester.util.AsciiHistogram;
116 import org.forester.util.BasicDescriptiveStatistics;
117 import org.forester.util.BasicTable;
118 import org.forester.util.BasicTableParser;
119 import org.forester.util.DescriptiveStatistics;
120 import org.forester.util.ForesterConstants;
121 import org.forester.util.ForesterUtil;
122 import org.forester.util.GeneralTable;
123 import org.forester.util.SequenceAccessionTools;
124 import org.forester.ws.seqdb.SequenceDatabaseEntry;
125 import org.forester.ws.seqdb.SequenceDbWsTools;
126 import org.forester.ws.seqdb.UniProtTaxonomy;
127 import org.forester.ws.wabi.TxSearch;
128 import org.forester.ws.wabi.TxSearch.RANKS;
129 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
130 import org.forester.ws.wabi.TxSearch.TAX_RANK;
131
132 @SuppressWarnings( "unused")
133 public final class Test {
134
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
139                                                                    + ForesterUtil.getFileSeparator() + "test_data"
140                                                                    + ForesterUtil.getFileSeparator();
141     private final static boolean PERFORM_DB_TESTS          = false;
142     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
143     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
147                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_XSD;
149     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
150     private final static double  ZERO_DIFF                 = 1.0E-9;
151
152     public static boolean isEqual( final double a, final double b ) {
153         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
154     }
155
156     public static void main( final String[] args ) {
157         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
158         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
159                 + "]" );
160         Locale.setDefault( Locale.US );
161         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
162         int failed = 0;
163         int succeeded = 0;
164         System.out.print( "[Test if directory with files for testing exists/is readable: " );
165         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         System.out.print( "[Test if resources directory exists/is readable: " );
174         if ( testDir( PATH_TO_RESOURCES ) ) {
175             System.out.println( "OK.]" );
176         }
177         else {
178             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
179             System.out.println( "Testing aborted." );
180             System.exit( -1 );
181         }
182         final long start_time = new Date().getTime();
183         System.out.print( "Basic node methods: " );
184         if ( Test.testBasicNodeMethods() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.out.print( "Protein id: " );
193         if ( !testProteinId() ) {
194             System.out.println( "failed." );
195             failed++;
196         }
197         else {
198             succeeded++;
199         }
200         System.out.println( "OK." );
201         System.out.print( "Species: " );
202         if ( !testSpecies() ) {
203             System.out.println( "failed." );
204             failed++;
205         }
206         else {
207             succeeded++;
208         }
209         System.out.println( "OK." );
210         System.out.print( "Basic domain: " );
211         if ( !testBasicDomain() ) {
212             System.out.println( "failed." );
213             failed++;
214         }
215         else {
216             succeeded++;
217         }
218         System.out.println( "OK." );
219         System.out.print( "Basic protein: " );
220         if ( !testBasicProtein() ) {
221             System.out.println( "failed." );
222             failed++;
223         }
224         else {
225             succeeded++;
226         }
227         System.out.println( "OK." );
228         System.out.print( "Sequence writer: " );
229         if ( testSequenceWriter() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "Sequence id parsing: " );
238         if ( testSequenceIdParsing() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "UniProtKB id extraction: " );
247         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "Sequence DB tools 1: " );
256         if ( testSequenceDbWsTools1() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Hmmscan output parser: " );
265         if ( testHmmscanOutputParser() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "Overlap removal: " );
274         if ( !org.forester.test.Test.testOverlapRemoval() ) {
275             System.out.println( "failed." );
276             failed++;
277         }
278         else {
279             succeeded++;
280         }
281         System.out.println( "OK." );
282         System.out.print( "Engulfing overlap removal: " );
283         if ( !Test.testEngulfingOverlapRemoval() ) {
284             System.out.println( "failed." );
285             failed++;
286         }
287         else {
288             succeeded++;
289         }
290         System.out.println( "OK." );
291         System.out.print( "Taxonomy code extraction: " );
292         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "SN extraction: " );
301         if ( Test.testExtractSNFromNodeName() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Taxonomy extraction (general): " );
310         if ( Test.testTaxonomyExtraction() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Uri for Aptx web sequence accession: " );
319         if ( Test.testCreateUriForSeqWeb() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "Basic node construction and parsing of NHX (node level): " );
328         if ( Test.testNHXNodeParsing() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "NHX parsing iterating: " );
337         if ( Test.testNHParsingIter() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "NH parsing: " );
346         if ( Test.testNHParsing() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Conversion to NHX (node level): " );
355         if ( Test.testNHXconversion() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "NHX parsing: " );
364         if ( Test.testNHXParsing() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "NHX parsing with quotes: " );
373         if ( Test.testNHXParsingQuotes() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "NHX parsing (MrBayes): " );
382         if ( Test.testNHXParsingMB() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Nexus characters parsing: " );
391         if ( Test.testNexusCharactersParsing() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Nexus tree parsing iterating: " );
400         if ( Test.testNexusTreeParsingIterating() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Nexus tree parsing: " );
409         if ( Test.testNexusTreeParsing() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Nexus tree parsing (translating): " );
418         if ( Test.testNexusTreeParsingTranslating() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Nexus matrix parsing: " );
427         if ( Test.testNexusMatrixParsing() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Basic phyloXML parsing: " );
436         if ( Test.testBasicPhyloXMLparsing() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Basic phyloXML parsing (validating against schema): " );
445         if ( testBasicPhyloXMLparsingValidating() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
454         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "phyloXML Distribution Element: " );
463         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Tol XML parsing: " );
472         if ( Test.testBasicTolXMLparsing() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Copying of node data: " );
481         if ( Test.testCopyOfNodeData() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Tree copy: " );
490         if ( Test.testTreeCopy() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Basic tree methods: " );
499         if ( Test.testBasicTreeMethods() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Tree methods: " );
508         if ( Test.testTreeMethods() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Postorder Iterator: " );
517         if ( Test.testPostOrderIterator() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Preorder Iterator: " );
526         if ( Test.testPreOrderIterator() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Levelorder Iterator: " );
535         if ( Test.testLevelOrderIterator() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "Re-id methods: " );
544         if ( Test.testReIdMethods() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "Methods on last external nodes: " );
553         if ( Test.testLastExternalNodeMethods() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "Methods on external nodes: " );
562         if ( Test.testExternalNodeRelatedMethods() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Deletion of external nodes: " );
571         if ( Test.testDeletionOfExternalNodes() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Subtree deletion: " );
580         if ( Test.testSubtreeDeletion() ) {
581             System.out.println( "OK." );
582             succeeded++;
583         }
584         else {
585             System.out.println( "failed." );
586             failed++;
587         }
588         System.out.print( "Phylogeny branch: " );
589         if ( Test.testPhylogenyBranch() ) {
590             System.out.println( "OK." );
591             succeeded++;
592         }
593         else {
594             System.out.println( "failed." );
595             failed++;
596         }
597         System.out.print( "Rerooting: " );
598         if ( Test.testRerooting() ) {
599             System.out.println( "OK." );
600             succeeded++;
601         }
602         else {
603             System.out.println( "failed." );
604             failed++;
605         }
606         System.out.print( "Mipoint rooting: " );
607         if ( Test.testMidpointrooting() ) {
608             System.out.println( "OK." );
609             succeeded++;
610         }
611         else {
612             System.out.println( "failed." );
613             failed++;
614         }
615         System.out.print( "Node removal: " );
616         if ( Test.testNodeRemoval() ) {
617             System.out.println( "OK." );
618             succeeded++;
619         }
620         else {
621             System.out.println( "failed." );
622             failed++;
623         }
624         System.out.print( "Support count: " );
625         if ( Test.testSupportCount() ) {
626             System.out.println( "OK." );
627             succeeded++;
628         }
629         else {
630             System.out.println( "failed." );
631             failed++;
632         }
633         System.out.print( "Support transfer: " );
634         if ( Test.testSupportTransfer() ) {
635             System.out.println( "OK." );
636             succeeded++;
637         }
638         else {
639             System.out.println( "failed." );
640             failed++;
641         }
642         System.out.print( "Finding of LCA: " );
643         if ( Test.testGetLCA() ) {
644             System.out.println( "OK." );
645             succeeded++;
646         }
647         else {
648             System.out.println( "failed." );
649             failed++;
650         }
651         System.out.print( "Finding of LCA 2: " );
652         if ( Test.testGetLCA2() ) {
653             System.out.println( "OK." );
654             succeeded++;
655         }
656         else {
657             System.out.println( "failed." );
658             failed++;
659         }
660         System.out.print( "Calculation of distance between nodes: " );
661         if ( Test.testGetDistance() ) {
662             System.out.println( "OK." );
663             succeeded++;
664         }
665         else {
666             System.out.println( "failed." );
667             failed++;
668         }
669         System.out.print( "Descriptive statistics: " );
670         if ( Test.testDescriptiveStatistics() ) {
671             System.out.println( "OK." );
672             succeeded++;
673         }
674         else {
675             System.out.println( "failed." );
676             failed++;
677         }
678         System.out.print( "Data objects and methods: " );
679         if ( Test.testDataObjects() ) {
680             System.out.println( "OK." );
681             succeeded++;
682         }
683         else {
684             System.out.println( "failed." );
685             failed++;
686         }
687         System.out.print( "Properties map: " );
688         if ( Test.testPropertiesMap() ) {
689             System.out.println( "OK." );
690             succeeded++;
691         }
692         else {
693             System.out.println( "failed." );
694             failed++;
695         }
696         System.out.print( "SDIse: " );
697         if ( Test.testSDIse() ) {
698             System.out.println( "OK." );
699             succeeded++;
700         }
701         else {
702             System.out.println( "failed." );
703             failed++;
704         }
705         System.out.print( "SDIunrooted: " );
706         if ( Test.testSDIunrooted() ) {
707             System.out.println( "OK." );
708             succeeded++;
709         }
710         else {
711             System.out.println( "failed." );
712             failed++;
713         }
714         System.out.print( "GSDI: " );
715         if ( TestGSDI.test() ) {
716             System.out.println( "OK." );
717             succeeded++;
718         }
719         else {
720             System.out.println( "failed." );
721             failed++;
722         }
723         System.out.print( "RIO: " );
724         if ( TestRIO.test() ) {
725             System.out.println( "OK." );
726             succeeded++;
727         }
728         else {
729             System.out.println( "failed." );
730             failed++;
731         }
732         System.out.print( "Phylogeny reconstruction:" );
733         System.out.println();
734         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Analysis of domain architectures: " );
743         System.out.println();
744         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GO: " );
753         System.out.println();
754         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "Modeling tools: " );
763         if ( TestPccx.test() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Split Matrix strict: " );
772         if ( Test.testSplitStrict() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Split Matrix: " );
781         if ( Test.testSplit() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Confidence Assessor: " );
790         if ( Test.testConfidenceAssessor() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "Basic table: " );
799         if ( Test.testBasicTable() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "General table: " );
808         if ( Test.testGeneralTable() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "Amino acid sequence: " );
817         if ( Test.testAminoAcidSequence() ) {
818             System.out.println( "OK." );
819             succeeded++;
820         }
821         else {
822             System.out.println( "failed." );
823             failed++;
824         }
825         System.out.print( "General MSA parser: " );
826         if ( Test.testGeneralMsaParser() ) {
827             System.out.println( "OK." );
828             succeeded++;
829         }
830         else {
831             System.out.println( "failed." );
832             failed++;
833         }
834         System.out.print( "Fasta parser for msa: " );
835         if ( Test.testFastaParser() ) {
836             System.out.println( "OK." );
837             succeeded++;
838         }
839         else {
840             System.out.println( "failed." );
841             failed++;
842         }
843         System.out.print( "Creation of balanced phylogeny: " );
844         if ( Test.testCreateBalancedPhylogeny() ) {
845             System.out.println( "OK." );
846             succeeded++;
847         }
848         else {
849             System.out.println( "failed." );
850             failed++;
851         }
852         System.out.print( "Genbank accessor parsing: " );
853         if ( Test.testGenbankAccessorParsing() ) {
854             System.out.println( "OK." );
855             succeeded++;
856         }
857         else {
858             System.out.println( "failed." );
859             failed++;
860         }
861         String path = "";
862         final String os = ForesterUtil.OS_NAME.toLowerCase();
863         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
864             path = "/usr/local/bin/mafft";
865         }
866         else if ( os.indexOf( "win" ) >= 0 ) {
867             path = "C:\\Program Files\\mafft-win\\mafft.bat";
868         }
869         else {
870             path = "mafft";
871             if ( !MsaInferrer.isInstalled( path ) ) {
872                 path = "/usr/bin/mafft";
873             }
874             if ( !MsaInferrer.isInstalled( path ) ) {
875                 path = "/usr/local/bin/mafft";
876             }
877         }
878         if ( MsaInferrer.isInstalled( path ) ) {
879             System.out.print( "MAFFT (external program): " );
880             if ( Test.testMafft( path ) ) {
881                 System.out.println( "OK." );
882                 succeeded++;
883             }
884             else {
885                 System.out.println( "failed [will not count towards failed tests]" );
886             }
887         }
888         System.out.print( "Next nodes with collapsed: " );
889         if ( Test.testNextNodeWithCollapsing() ) {
890             System.out.println( "OK." );
891             succeeded++;
892         }
893         else {
894             System.out.println( "failed." );
895             failed++;
896         }
897         System.out.print( "Simple MSA quality: " );
898         if ( Test.testMsaQualityMethod() ) {
899             System.out.println( "OK." );
900             succeeded++;
901         }
902         else {
903             System.out.println( "failed." );
904             failed++;
905         }
906         System.out.print( "Deleteable MSA: " );
907         if ( Test.testDeleteableMsa() ) {
908             System.out.println( "OK." );
909             succeeded++;
910         }
911         else {
912             System.out.println( "failed." );
913             failed++;
914         }
915         System.exit( 0 );
916         if ( PERFORM_DB_TESTS ) {
917             System.out.print( "Uniprot Entry Retrieval: " );
918             if ( Test.testUniprotEntryRetrieval() ) {
919                 System.out.println( "OK." );
920                 succeeded++;
921             }
922             else {
923                 System.out.println( "failed." );
924                 failed++;
925             }
926             System.out.print( "Ebi Entry Retrieval: " );
927             if ( Test.testEbiEntryRetrieval() ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed." );
933                 failed++;
934             }
935             System.out.print( "Sequence DB tools 2: " );
936             if ( testSequenceDbWsTools2() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943                 System.exit( -1 );
944             }
945             System.out.print( "Uniprot Taxonomy Search: " );
946             if ( Test.testUniprotTaxonomySearch() ) {
947                 System.out.println( "OK." );
948                 succeeded++;
949             }
950             else {
951                 System.out.println( "failed." );
952                 failed++;
953             }
954         }
955         if ( PERFORM_WEB_TREE_ACCESS ) {
956             System.out.print( "NHX parsing from URL: " );
957             if ( Test.testNHXparsingFromURL() ) {
958                 System.out.println( "OK." );
959                 succeeded++;
960             }
961             else {
962                 System.out.println( "failed." );
963                 failed++;
964             }
965             System.out.print( "phyloXML parsing from URL: " );
966             if ( Test.testPhyloXMLparsingFromURL() ) {
967                 System.out.println( "OK." );
968                 succeeded++;
969             }
970             else {
971                 System.out.println( "failed." );
972                 failed++;
973             }
974             System.out.print( "TreeBase acccess: " );
975             if ( Test.testTreeBaseReading() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             //
984             System.out.print( "ToL access: " );
985             if ( Test.testToLReading() ) {
986                 System.out.println( "OK." );
987                 succeeded++;
988             }
989             else {
990                 System.out.println( "failed." );
991                 failed++;
992             }
993             //
994             System.out.print( "TreeFam access: " );
995             if ( Test.testTreeFamReading() ) {
996                 System.out.println( "OK." );
997                 succeeded++;
998             }
999             else {
1000                 System.out.println( "failed." );
1001                 failed++;
1002             }
1003             //
1004             //
1005             System.out.print( "Pfam tree access: " );
1006             if ( Test.testPfamTreeReading() ) {
1007                 System.out.println( "OK." );
1008                 succeeded++;
1009             }
1010             else {
1011                 System.out.println( "failed." );
1012                 failed++;
1013             }
1014         }
1015         System.out.println();
1016         final Runtime rt = java.lang.Runtime.getRuntime();
1017         final long free_memory = rt.freeMemory() / 1000000;
1018         final long total_memory = rt.totalMemory() / 1000000;
1019         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1020                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1021         System.out.println();
1022         System.out.println( "Successful tests: " + succeeded );
1023         System.out.println( "Failed     tests: " + failed );
1024         System.out.println();
1025         if ( failed < 1 ) {
1026             System.out.println( "OK." );
1027         }
1028         else {
1029             System.out.println( "Not OK." );
1030         }
1031     }
1032
1033     public static boolean testEngulfingOverlapRemoval() {
1034         try {
1035             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1036             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1037             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1038             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1039             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1040             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1041             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1042             final List<Boolean> covered = new ArrayList<Boolean>();
1043             covered.add( true ); // 0
1044             covered.add( false ); // 1
1045             covered.add( true ); // 2
1046             covered.add( false ); // 3
1047             covered.add( true ); // 4
1048             covered.add( true ); // 5
1049             covered.add( false ); // 6
1050             covered.add( true ); // 7
1051             covered.add( true ); // 8
1052             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1053                 return false;
1054             }
1055             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1056                 return false;
1057             }
1058             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1059                 return false;
1060             }
1061             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1062                 return false;
1063             }
1064             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1065                 return false;
1066             }
1067             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1068                 return false;
1069             }
1070             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1071                 return false;
1072             }
1073             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1074             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1075             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1076             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1077             abc.addProteinDomain( a );
1078             abc.addProteinDomain( b );
1079             abc.addProteinDomain( c );
1080             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1081             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1082             if ( abc.getNumberOfProteinDomains() != 3 ) {
1083                 return false;
1084             }
1085             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1086                 return false;
1087             }
1088             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1089                 return false;
1090             }
1091             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1092                 return false;
1093             }
1094             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1095                 return false;
1096             }
1097             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1098             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1099             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1100             final Protein def = new BasicProtein( "def", "nemve", 0 );
1101             def.addProteinDomain( d );
1102             def.addProteinDomain( e );
1103             def.addProteinDomain( f );
1104             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1105             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1106             if ( def.getNumberOfProteinDomains() != 3 ) {
1107                 return false;
1108             }
1109             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1113                 return false;
1114             }
1115             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1116                 return false;
1117             }
1118             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1119                 return false;
1120             }
1121             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1122                 return false;
1123             }
1124         }
1125         catch ( final Exception e ) {
1126             e.printStackTrace( System.out );
1127             return false;
1128         }
1129         return true;
1130     }
1131
1132     public static final boolean testNHXparsingFromURL() {
1133         try {
1134             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1135             final URL u = new URL( s );
1136             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1137             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1138             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1139                 return false;
1140             }
1141             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1142                 System.out.println( phys[ 0 ].toNewHampshire() );
1143                 return false;
1144             }
1145             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1146                 System.out.println( phys[ 1 ].toNewHampshire() );
1147                 return false;
1148             }
1149             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1150             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1151                 return false;
1152             }
1153             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1154                 System.out.println( phys2[ 0 ].toNewHampshire() );
1155                 return false;
1156             }
1157             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1158             final NHXParser p = new NHXParser();
1159             final URL u2 = new URL( s );
1160             p.setSource( u2 );
1161             if ( !p.hasNext() ) {
1162                 return false;
1163             }
1164             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1165                 return false;
1166             }
1167             if ( !p.hasNext() ) {
1168                 return false;
1169             }
1170             p.reset();
1171             if ( !p.hasNext() ) {
1172                 return false;
1173             }
1174             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1175                 return false;
1176             }
1177             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1178                 return false;
1179             }
1180             p.reset();
1181             if ( !p.hasNext() ) {
1182                 return false;
1183             }
1184             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1185                 return false;
1186             }
1187             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1188                 return false;
1189             }
1190         }
1191         catch ( final Exception e ) {
1192             e.printStackTrace();
1193         }
1194         return true;
1195     }
1196
1197     public static boolean testOverlapRemoval() {
1198         try {
1199             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1200             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1201             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1202             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1203             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1204             final List<Boolean> covered = new ArrayList<Boolean>();
1205             covered.add( true ); // 0
1206             covered.add( false ); // 1
1207             covered.add( true ); // 2
1208             covered.add( false ); // 3
1209             covered.add( true ); // 4
1210             covered.add( true ); // 5
1211             covered.add( false ); // 6
1212             covered.add( true ); // 7
1213             covered.add( true ); // 8
1214             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1215                 return false;
1216             }
1217             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1218                 return false;
1219             }
1220             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1221                 return false;
1222             }
1223             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1224                 return false;
1225             }
1226             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1227                 return false;
1228             }
1229             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1230             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1231             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1232             ab.addProteinDomain( a );
1233             ab.addProteinDomain( b );
1234             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1235             if ( ab.getNumberOfProteinDomains() != 2 ) {
1236                 return false;
1237             }
1238             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1239                 return false;
1240             }
1241             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1242                 return false;
1243             }
1244             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1245             if ( ab.getNumberOfProteinDomains() != 2 ) {
1246                 return false;
1247             }
1248             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1249                 return false;
1250             }
1251             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1252             final Domain d = new BasicDomain( "d",
1253                                               ( short ) 10000,
1254                                               ( short ) 10500,
1255                                               ( short ) 1,
1256                                               ( short ) 1,
1257                                               0.0000001,
1258                                               1 );
1259             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1260             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1261             cde.addProteinDomain( c );
1262             cde.addProteinDomain( d );
1263             cde.addProteinDomain( e );
1264             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1265             if ( cde.getNumberOfProteinDomains() != 3 ) {
1266                 return false;
1267             }
1268             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1269                 return false;
1270             }
1271             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1272             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1273             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1274             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1275             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1276             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1277             fghi.addProteinDomain( f );
1278             fghi.addProteinDomain( g );
1279             fghi.addProteinDomain( h );
1280             fghi.addProteinDomain( i );
1281             fghi.addProteinDomain( i );
1282             fghi.addProteinDomain( i );
1283             fghi.addProteinDomain( i2 );
1284             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1285             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1286                 return false;
1287             }
1288             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1289                 return false;
1290             }
1291             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1292                 return false;
1293             }
1294             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1295             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1296                 return false;
1297             }
1298             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1299                 return false;
1300             }
1301             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1302             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1303             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1304             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1305             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1306             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1307             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1308             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1309             jklm.addProteinDomain( j );
1310             jklm.addProteinDomain( k );
1311             jklm.addProteinDomain( l );
1312             jklm.addProteinDomain( m );
1313             jklm.addProteinDomain( m0 );
1314             jklm.addProteinDomain( m1 );
1315             jklm.addProteinDomain( m2 );
1316             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1317             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1318                 return false;
1319             }
1320             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1321                 return false;
1322             }
1323             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1324                 return false;
1325             }
1326             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1327             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1328                 return false;
1329             }
1330             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1331                 return false;
1332             }
1333             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1334             final Protein od = new BasicProtein( "od", "varanus", 0 );
1335             od.addProteinDomain( only );
1336             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1337             if ( od.getNumberOfProteinDomains() != 1 ) {
1338                 return false;
1339             }
1340             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1341                 return false;
1342             }
1343         }
1344         catch ( final Exception e ) {
1345             e.printStackTrace( System.out );
1346             return false;
1347         }
1348         return true;
1349     }
1350
1351     public static final boolean testPfamTreeReading() {
1352         try {
1353             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1354             final NHXParser parser = new NHXParser();
1355             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1356             parser.setReplaceUnderscores( false );
1357             parser.setGuessRootedness( true );
1358             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1359             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1360             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1361                 return false;
1362             }
1363             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1364                 return false;
1365             }
1366         }
1367         catch ( final Exception e ) {
1368             e.printStackTrace();
1369         }
1370         return true;
1371     }
1372
1373     public static final boolean testPhyloXMLparsingFromURL() {
1374         try {
1375             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1376             final URL u = new URL( s );
1377             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1378             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1379             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1380                 return false;
1381             }
1382         }
1383         catch ( final Exception e ) {
1384             e.printStackTrace();
1385         }
1386         return true;
1387     }
1388
1389     public static final boolean testToLReading() {
1390         try {
1391             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1392             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1393             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1394             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1395                 return false;
1396             }
1397             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1398                 return false;
1399             }
1400             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1401                 return false;
1402             }
1403             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1404                 return false;
1405             }
1406         }
1407         catch ( final Exception e ) {
1408             e.printStackTrace();
1409         }
1410         return true;
1411     }
1412
1413     public static final boolean testTreeBaseReading() {
1414         try {
1415             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1416             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1417             parser.setReplaceUnderscores( true );
1418             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1419             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1420             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1421                 return false;
1422             }
1423             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1424             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1425             parser2.setReplaceUnderscores( true );
1426             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1427             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1428             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1429                 return false;
1430             }
1431         }
1432         catch ( final Exception e ) {
1433             e.printStackTrace();
1434         }
1435         return true;
1436     }
1437
1438     public static final boolean testTreeFamReading() {
1439         try {
1440             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1441             final NHXParser parser = new NHXParser();
1442             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1443             parser.setReplaceUnderscores( false );
1444             parser.setGuessRootedness( true );
1445             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1446             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1447             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1448                 return false;
1449             }
1450             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1451                 return false;
1452             }
1453         }
1454         catch ( final Exception e ) {
1455             e.printStackTrace();
1456         }
1457         return true;
1458     }
1459
1460     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1461         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1462         return p;
1463     }
1464
1465     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1466         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1467     }
1468
1469     private static boolean testAminoAcidSequence() {
1470         try {
1471             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1472             if ( aa1.getLength() != 13 ) {
1473                 return false;
1474             }
1475             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1476                 return false;
1477             }
1478             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1479                 return false;
1480             }
1481             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1482                 return false;
1483             }
1484             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1485             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1486                 return false;
1487             }
1488             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1489             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1490                 return false;
1491             }
1492             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1493             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1494                 return false;
1495             }
1496         }
1497         catch ( final Exception e ) {
1498             e.printStackTrace();
1499             return false;
1500         }
1501         return true;
1502     }
1503
1504     private static boolean testBasicDomain() {
1505         try {
1506             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1507             if ( !pd.getDomainId().equals( "id" ) ) {
1508                 return false;
1509             }
1510             if ( pd.getNumber() != 1 ) {
1511                 return false;
1512             }
1513             if ( pd.getTotalCount() != 4 ) {
1514                 return false;
1515             }
1516             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1517                 return false;
1518             }
1519             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1520             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1521             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1522             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1523             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1524             if ( !a1.equals( a1 ) ) {
1525                 return false;
1526             }
1527             if ( !a1.equals( a1_copy ) ) {
1528                 return false;
1529             }
1530             if ( !a1.equals( a1_equal ) ) {
1531                 return false;
1532             }
1533             if ( !a1.equals( a2 ) ) {
1534                 return false;
1535             }
1536             if ( a1.equals( a3 ) ) {
1537                 return false;
1538             }
1539             if ( a1.compareTo( a1 ) != 0 ) {
1540                 return false;
1541             }
1542             if ( a1.compareTo( a1_copy ) != 0 ) {
1543                 return false;
1544             }
1545             if ( a1.compareTo( a1_equal ) != 0 ) {
1546                 return false;
1547             }
1548             if ( a1.compareTo( a2 ) != 0 ) {
1549                 return false;
1550             }
1551             if ( a1.compareTo( a3 ) == 0 ) {
1552                 return false;
1553             }
1554         }
1555         catch ( final Exception e ) {
1556             e.printStackTrace( System.out );
1557             return false;
1558         }
1559         return true;
1560     }
1561
1562     private static boolean testBasicNodeMethods() {
1563         try {
1564             if ( PhylogenyNode.getNodeCount() != 0 ) {
1565                 return false;
1566             }
1567             final PhylogenyNode n1 = new PhylogenyNode();
1568             final PhylogenyNode n2 = PhylogenyNode
1569                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1570             final PhylogenyNode n3 = PhylogenyNode
1571                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1572             final PhylogenyNode n4 = PhylogenyNode
1573                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1574             if ( n1.isHasAssignedEvent() ) {
1575                 return false;
1576             }
1577             if ( PhylogenyNode.getNodeCount() != 4 ) {
1578                 return false;
1579             }
1580             if ( n3.getIndicator() != 0 ) {
1581                 return false;
1582             }
1583             if ( n3.getNumberOfExternalNodes() != 1 ) {
1584                 return false;
1585             }
1586             if ( !n3.isExternal() ) {
1587                 return false;
1588             }
1589             if ( !n3.isRoot() ) {
1590                 return false;
1591             }
1592             if ( !n4.getName().equals( "n4" ) ) {
1593                 return false;
1594             }
1595         }
1596         catch ( final Exception e ) {
1597             e.printStackTrace( System.out );
1598             return false;
1599         }
1600         return true;
1601     }
1602
1603     private static boolean testBasicPhyloXMLparsing() {
1604         try {
1605             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1606             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1607             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1608                                                               xml_parser );
1609             if ( xml_parser.getErrorCount() > 0 ) {
1610                 System.out.println( xml_parser.getErrorMessages().toString() );
1611                 return false;
1612             }
1613             if ( phylogenies_0.length != 4 ) {
1614                 return false;
1615             }
1616             final Phylogeny t1 = phylogenies_0[ 0 ];
1617             final Phylogeny t2 = phylogenies_0[ 1 ];
1618             final Phylogeny t3 = phylogenies_0[ 2 ];
1619             final Phylogeny t4 = phylogenies_0[ 3 ];
1620             if ( t1.getNumberOfExternalNodes() != 1 ) {
1621                 return false;
1622             }
1623             if ( !t1.isRooted() ) {
1624                 return false;
1625             }
1626             if ( t1.isRerootable() ) {
1627                 return false;
1628             }
1629             if ( !t1.getType().equals( "gene_tree" ) ) {
1630                 return false;
1631             }
1632             if ( t2.getNumberOfExternalNodes() != 2 ) {
1633                 return false;
1634             }
1635             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1636                 return false;
1637             }
1638             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1639                 return false;
1640             }
1641             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1642                 return false;
1643             }
1644             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1645                 return false;
1646             }
1647             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1648                 return false;
1649             }
1650             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1651                 return false;
1652             }
1653             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1654                     .startsWith( "actgtgggggt" ) ) {
1655                 return false;
1656             }
1657             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1658                     .startsWith( "ctgtgatgcat" ) ) {
1659                 return false;
1660             }
1661             if ( t3.getNumberOfExternalNodes() != 4 ) {
1662                 return false;
1663             }
1664             if ( !t1.getName().equals( "t1" ) ) {
1665                 return false;
1666             }
1667             if ( !t2.getName().equals( "t2" ) ) {
1668                 return false;
1669             }
1670             if ( !t3.getName().equals( "t3" ) ) {
1671                 return false;
1672             }
1673             if ( !t4.getName().equals( "t4" ) ) {
1674                 return false;
1675             }
1676             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1677                 return false;
1678             }
1679             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1680                 return false;
1681             }
1682             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1683                 return false;
1684             }
1685             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1686                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1687                 return false;
1688             }
1689             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1690                 return false;
1691             }
1692             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1693                 return false;
1694             }
1695             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1696                 return false;
1697             }
1698             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1699                     .equals( "apoptosis" ) ) {
1700                 return false;
1701             }
1702             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1703                     .equals( "GO:0006915" ) ) {
1704                 return false;
1705             }
1706             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1707                     .equals( "UniProtKB" ) ) {
1708                 return false;
1709             }
1710             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1711                     .equals( "experimental" ) ) {
1712                 return false;
1713             }
1714             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1715                     .equals( "function" ) ) {
1716                 return false;
1717             }
1718             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1719                     .getValue() != 1 ) {
1720                 return false;
1721             }
1722             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1723                     .getType().equals( "ml" ) ) {
1724                 return false;
1725             }
1726             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1727                     .equals( "apoptosis" ) ) {
1728                 return false;
1729             }
1730             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1731                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1732                 return false;
1733             }
1734             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1735                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1736                 return false;
1737             }
1738             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1739                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1740                 return false;
1741             }
1742             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1743                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1744                 return false;
1745             }
1746             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1747                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1748                 return false;
1749             }
1750             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1751                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1752                 return false;
1753             }
1754             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1755                     .equals( "GO:0005829" ) ) {
1756                 return false;
1757             }
1758             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1759                     .equals( "intracellular organelle" ) ) {
1760                 return false;
1761             }
1762             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1763                 return false;
1764             }
1765             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1766                     .equals( "UniProt link" ) ) ) {
1767                 return false;
1768             }
1769             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1770                 return false;
1771             }
1772             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1773             if ( x.size() != 4 ) {
1774                 return false;
1775             }
1776             int c = 0;
1777             for( final Accession acc : x ) {
1778                 if ( c == 0 ) {
1779                     if ( !acc.getSource().equals( "KEGG" ) ) {
1780                         return false;
1781                     }
1782                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1783                         return false;
1784                     }
1785                 }
1786                 c++;
1787             }
1788         }
1789         catch ( final Exception e ) {
1790             e.printStackTrace( System.out );
1791             return false;
1792         }
1793         return true;
1794     }
1795
1796     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1797         try {
1798             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1799             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1800             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1801                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1802             }
1803             else {
1804                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1805             }
1806             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1807                                                               xml_parser );
1808             if ( xml_parser.getErrorCount() > 0 ) {
1809                 System.out.println( xml_parser.getErrorMessages().toString() );
1810                 return false;
1811             }
1812             if ( phylogenies_0.length != 4 ) {
1813                 return false;
1814             }
1815             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1816             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1817             if ( phylogenies_t1.length != 1 ) {
1818                 return false;
1819             }
1820             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1821             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1822                 return false;
1823             }
1824             if ( !t1_rt.isRooted() ) {
1825                 return false;
1826             }
1827             if ( t1_rt.isRerootable() ) {
1828                 return false;
1829             }
1830             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1831                 return false;
1832             }
1833             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1834             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1835             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1836             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1837                 return false;
1838             }
1839             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1840                 return false;
1841             }
1842             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1843                 return false;
1844             }
1845             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1846                 return false;
1847             }
1848             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1849                     .startsWith( "actgtgggggt" ) ) {
1850                 return false;
1851             }
1852             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1853                     .startsWith( "ctgtgatgcat" ) ) {
1854                 return false;
1855             }
1856             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1857             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1858             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1859             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1860             if ( phylogenies_1.length != 1 ) {
1861                 return false;
1862             }
1863             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1864             if ( !t3_rt.getName().equals( "t3" ) ) {
1865                 return false;
1866             }
1867             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1868                 return false;
1869             }
1870             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1871                 return false;
1872             }
1873             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1874                 return false;
1875             }
1876             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1877                 return false;
1878             }
1879             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1880                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1881                 return false;
1882             }
1883             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1884                 return false;
1885             }
1886             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1887                 return false;
1888             }
1889             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1890                     .equals( "UniProtKB" ) ) {
1891                 return false;
1892             }
1893             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1894                     .equals( "apoptosis" ) ) {
1895                 return false;
1896             }
1897             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1898                     .equals( "GO:0006915" ) ) {
1899                 return false;
1900             }
1901             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1902                     .equals( "UniProtKB" ) ) {
1903                 return false;
1904             }
1905             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1906                     .equals( "experimental" ) ) {
1907                 return false;
1908             }
1909             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1910                     .equals( "function" ) ) {
1911                 return false;
1912             }
1913             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1914                     .getValue() != 1 ) {
1915                 return false;
1916             }
1917             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1918                     .getType().equals( "ml" ) ) {
1919                 return false;
1920             }
1921             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1922                     .equals( "apoptosis" ) ) {
1923                 return false;
1924             }
1925             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1926                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1927                 return false;
1928             }
1929             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1930                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1931                 return false;
1932             }
1933             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1934                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1935                 return false;
1936             }
1937             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1938                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1939                 return false;
1940             }
1941             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1942                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1943                 return false;
1944             }
1945             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1946                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1947                 return false;
1948             }
1949             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1950                     .equals( "GO:0005829" ) ) {
1951                 return false;
1952             }
1953             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1954                     .equals( "intracellular organelle" ) ) {
1955                 return false;
1956             }
1957             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1958                 return false;
1959             }
1960             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1961                     .equals( "UniProt link" ) ) ) {
1962                 return false;
1963             }
1964             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1965                 return false;
1966             }
1967             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1968                 return false;
1969             }
1970             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1971                     .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." ) ) ) {
1972                 return false;
1973             }
1974             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1975                 return false;
1976             }
1977             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1978                 return false;
1979             }
1980             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1981                 return false;
1982             }
1983             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1984                 return false;
1985             }
1986             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1987                     .equals( "ncbi" ) ) {
1988                 return false;
1989             }
1990             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1991                 return false;
1992             }
1993             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1994                     .getName().equals( "B" ) ) {
1995                 return false;
1996             }
1997             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1998                     .getFrom() != 21 ) {
1999                 return false;
2000             }
2001             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2002                 return false;
2003             }
2004             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2005                     .getLength() != 24 ) {
2006                 return false;
2007             }
2008             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2009                     .getConfidence() != 2144 ) {
2010                 return false;
2011             }
2012             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2013                     .equals( "pfam" ) ) {
2014                 return false;
2015             }
2016             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2017                 return false;
2018             }
2019             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2020                 return false;
2021             }
2022             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2023                 return false;
2024             }
2025             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2026                 return false;
2027             }
2028             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2029             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2030                 return false;
2031             }
2032             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2033                 return false;
2034             }
2035             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2036                 return false;
2037             }
2038             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2039                 return false;
2040             }
2041             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2042                 return false;
2043             }
2044             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2045                 return false;
2046             }
2047             if ( taxbb.getSynonyms().size() != 2 ) {
2048                 return false;
2049             }
2050             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2051                 return false;
2052             }
2053             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2054                 return false;
2055             }
2056             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2057                 return false;
2058             }
2059             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2060                 return false;
2061             }
2062             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2063                 return false;
2064             }
2065             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2066                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2067                 return false;
2068             }
2069             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2070                 return false;
2071             }
2072             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2073                 return false;
2074             }
2075             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2076                 return false;
2077             }
2078             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2079                 return false;
2080             }
2081             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2082                 return false;
2083             }
2084             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2085                 return false;
2086             }
2087             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2088                 return false;
2089             }
2090             //
2091             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2092                 return false;
2093             }
2094             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2095                     .equalsIgnoreCase( "435" ) ) {
2096                 return false;
2097             }
2098             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2099                 return false;
2100             }
2101             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2102                     .equalsIgnoreCase( "443.7" ) ) {
2103                 return false;
2104             }
2105             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2106                 return false;
2107             }
2108             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2109                 return false;
2110             }
2111             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2112                     .equalsIgnoreCase( "433" ) ) {
2113                 return false;
2114             }
2115             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2116                     .getCrossReferences();
2117             if ( x.size() != 4 ) {
2118                 return false;
2119             }
2120             int c = 0;
2121             for( final Accession acc : x ) {
2122                 if ( c == 0 ) {
2123                     if ( !acc.getSource().equals( "KEGG" ) ) {
2124                         return false;
2125                     }
2126                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2127                         return false;
2128                     }
2129                 }
2130                 c++;
2131             }
2132         }
2133         catch ( final Exception e ) {
2134             e.printStackTrace( System.out );
2135             return false;
2136         }
2137         return true;
2138     }
2139
2140     private static boolean testBasicPhyloXMLparsingValidating() {
2141         try {
2142             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2143             PhyloXmlParser xml_parser = null;
2144             try {
2145                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2146             }
2147             catch ( final Exception e ) {
2148                 // Do nothing -- means were not running from jar.
2149             }
2150             if ( xml_parser == null ) {
2151                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2152                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2153                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2154                 }
2155                 else {
2156                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2157                 }
2158             }
2159             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2160                                                               xml_parser );
2161             if ( xml_parser.getErrorCount() > 0 ) {
2162                 System.out.println( xml_parser.getErrorMessages().toString() );
2163                 return false;
2164             }
2165             if ( phylogenies_0.length != 4 ) {
2166                 return false;
2167             }
2168             final Phylogeny t1 = phylogenies_0[ 0 ];
2169             final Phylogeny t2 = phylogenies_0[ 1 ];
2170             final Phylogeny t3 = phylogenies_0[ 2 ];
2171             final Phylogeny t4 = phylogenies_0[ 3 ];
2172             if ( !t1.getName().equals( "t1" ) ) {
2173                 return false;
2174             }
2175             if ( !t2.getName().equals( "t2" ) ) {
2176                 return false;
2177             }
2178             if ( !t3.getName().equals( "t3" ) ) {
2179                 return false;
2180             }
2181             if ( !t4.getName().equals( "t4" ) ) {
2182                 return false;
2183             }
2184             if ( t1.getNumberOfExternalNodes() != 1 ) {
2185                 return false;
2186             }
2187             if ( t2.getNumberOfExternalNodes() != 2 ) {
2188                 return false;
2189             }
2190             if ( t3.getNumberOfExternalNodes() != 4 ) {
2191                 return false;
2192             }
2193             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2194             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2195             if ( xml_parser.getErrorCount() > 0 ) {
2196                 System.out.println( "errors:" );
2197                 System.out.println( xml_parser.getErrorMessages().toString() );
2198                 return false;
2199             }
2200             if ( phylogenies_1.length != 4 ) {
2201                 return false;
2202             }
2203             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2204                                                               xml_parser );
2205             if ( xml_parser.getErrorCount() > 0 ) {
2206                 System.out.println( "errors:" );
2207                 System.out.println( xml_parser.getErrorMessages().toString() );
2208                 return false;
2209             }
2210             if ( phylogenies_2.length != 1 ) {
2211                 return false;
2212             }
2213             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2214                 return false;
2215             }
2216             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2217                                                               xml_parser );
2218             if ( xml_parser.getErrorCount() > 0 ) {
2219                 System.out.println( xml_parser.getErrorMessages().toString() );
2220                 return false;
2221             }
2222             if ( phylogenies_3.length != 2 ) {
2223                 return false;
2224             }
2225             final Phylogeny a = phylogenies_3[ 0 ];
2226             if ( !a.getName().equals( "tree 4" ) ) {
2227                 return false;
2228             }
2229             if ( a.getNumberOfExternalNodes() != 3 ) {
2230                 return false;
2231             }
2232             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2233                 return false;
2234             }
2235             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2236                 return false;
2237             }
2238             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2239                                                               xml_parser );
2240             if ( xml_parser.getErrorCount() > 0 ) {
2241                 System.out.println( xml_parser.getErrorMessages().toString() );
2242                 return false;
2243             }
2244             if ( phylogenies_4.length != 1 ) {
2245                 return false;
2246             }
2247             final Phylogeny s = phylogenies_4[ 0 ];
2248             if ( s.getNumberOfExternalNodes() != 6 ) {
2249                 return false;
2250             }
2251             s.getNode( "first" );
2252             s.getNode( "<>" );
2253             s.getNode( "\"<a'b&c'd\">\"" );
2254             s.getNode( "'''\"" );
2255             s.getNode( "\"\"\"" );
2256             s.getNode( "dick & doof" );
2257         }
2258         catch ( final Exception e ) {
2259             e.printStackTrace( System.out );
2260             return false;
2261         }
2262         return true;
2263     }
2264
2265     private static boolean testBasicProtein() {
2266         try {
2267             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2268             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2269             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2270             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2271             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2272             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2273             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2274             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2275             p0.addProteinDomain( y );
2276             p0.addProteinDomain( e );
2277             p0.addProteinDomain( b );
2278             p0.addProteinDomain( c );
2279             p0.addProteinDomain( d );
2280             p0.addProteinDomain( a );
2281             p0.addProteinDomain( x );
2282             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2283                 return false;
2284             }
2285             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2286                 return false;
2287             }
2288             //
2289             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2290             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2291             aa0.addProteinDomain( a1 );
2292             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2293                 return false;
2294             }
2295             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2296                 return false;
2297             }
2298             //
2299             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2300             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2301             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2302             aa1.addProteinDomain( a11 );
2303             aa1.addProteinDomain( a12 );
2304             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2305                 return false;
2306             }
2307             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2308                 return false;
2309             }
2310             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2311             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2312                 return false;
2313             }
2314             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2315                 return false;
2316             }
2317             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2318                 return false;
2319             }
2320             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2321             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2322                 return false;
2323             }
2324             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2325                 return false;
2326             }
2327             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2328                 return false;
2329             }
2330             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2331                 return false;
2332             }
2333             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2334             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2335                 return false;
2336             }
2337             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2338                 return false;
2339             }
2340             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2341                 return false;
2342             }
2343             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2344                 return false;
2345             }
2346             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2347             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2348                 return false;
2349             }
2350             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2351                 return false;
2352             }
2353             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2354                 return false;
2355             }
2356             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2357                 return false;
2358             }
2359             //
2360             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2361             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2379             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2381             p00.addProteinDomain( y0 );
2382             p00.addProteinDomain( e0 );
2383             p00.addProteinDomain( b0 );
2384             p00.addProteinDomain( c0 );
2385             p00.addProteinDomain( d0 );
2386             p00.addProteinDomain( a0 );
2387             p00.addProteinDomain( x0 );
2388             p00.addProteinDomain( y1 );
2389             p00.addProteinDomain( y2 );
2390             p00.addProteinDomain( y3 );
2391             p00.addProteinDomain( e1 );
2392             p00.addProteinDomain( e2 );
2393             p00.addProteinDomain( e3 );
2394             p00.addProteinDomain( e4 );
2395             p00.addProteinDomain( e5 );
2396             p00.addProteinDomain( z0 );
2397             p00.addProteinDomain( z1 );
2398             p00.addProteinDomain( z2 );
2399             p00.addProteinDomain( zz0 );
2400             p00.addProteinDomain( zz1 );
2401             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2402                 return false;
2403             }
2404             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2405                 return false;
2406             }
2407             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2408                 return false;
2409             }
2410             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2411                 return false;
2412             }
2413             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" ) ) {
2414                 return false;
2415             }
2416             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2417             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2418             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2419             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2420             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2421             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2422             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2423             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2424             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2425             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2426             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2427             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2428             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2429             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2430             p.addProteinDomain( B15 );
2431             p.addProteinDomain( C50 );
2432             p.addProteinDomain( A60 );
2433             p.addProteinDomain( A30 );
2434             p.addProteinDomain( C70 );
2435             p.addProteinDomain( B35 );
2436             p.addProteinDomain( B40 );
2437             p.addProteinDomain( A0 );
2438             p.addProteinDomain( A10 );
2439             p.addProteinDomain( A20 );
2440             p.addProteinDomain( B25 );
2441             p.addProteinDomain( D80 );
2442             List<String> domains_ids = new ArrayList<String>();
2443             domains_ids.add( "A" );
2444             domains_ids.add( "B" );
2445             domains_ids.add( "C" );
2446             if ( !p.contains( domains_ids, false ) ) {
2447                 return false;
2448             }
2449             if ( !p.contains( domains_ids, true ) ) {
2450                 return false;
2451             }
2452             domains_ids.add( "X" );
2453             if ( p.contains( domains_ids, false ) ) {
2454                 return false;
2455             }
2456             if ( p.contains( domains_ids, true ) ) {
2457                 return false;
2458             }
2459             domains_ids = new ArrayList<String>();
2460             domains_ids.add( "A" );
2461             domains_ids.add( "C" );
2462             domains_ids.add( "D" );
2463             if ( !p.contains( domains_ids, false ) ) {
2464                 return false;
2465             }
2466             if ( !p.contains( domains_ids, true ) ) {
2467                 return false;
2468             }
2469             domains_ids = new ArrayList<String>();
2470             domains_ids.add( "A" );
2471             domains_ids.add( "D" );
2472             domains_ids.add( "C" );
2473             if ( !p.contains( domains_ids, false ) ) {
2474                 return false;
2475             }
2476             if ( p.contains( domains_ids, true ) ) {
2477                 return false;
2478             }
2479             domains_ids = new ArrayList<String>();
2480             domains_ids.add( "A" );
2481             domains_ids.add( "A" );
2482             domains_ids.add( "B" );
2483             if ( !p.contains( domains_ids, false ) ) {
2484                 return false;
2485             }
2486             if ( !p.contains( domains_ids, true ) ) {
2487                 return false;
2488             }
2489             domains_ids = new ArrayList<String>();
2490             domains_ids.add( "A" );
2491             domains_ids.add( "A" );
2492             domains_ids.add( "A" );
2493             domains_ids.add( "B" );
2494             domains_ids.add( "B" );
2495             if ( !p.contains( domains_ids, false ) ) {
2496                 return false;
2497             }
2498             if ( !p.contains( domains_ids, true ) ) {
2499                 return false;
2500             }
2501             domains_ids = new ArrayList<String>();
2502             domains_ids.add( "A" );
2503             domains_ids.add( "A" );
2504             domains_ids.add( "B" );
2505             domains_ids.add( "A" );
2506             domains_ids.add( "B" );
2507             domains_ids.add( "B" );
2508             domains_ids.add( "A" );
2509             domains_ids.add( "B" );
2510             domains_ids.add( "C" );
2511             domains_ids.add( "A" );
2512             domains_ids.add( "C" );
2513             domains_ids.add( "D" );
2514             if ( !p.contains( domains_ids, false ) ) {
2515                 return false;
2516             }
2517             if ( p.contains( domains_ids, true ) ) {
2518                 return false;
2519             }
2520         }
2521         catch ( final Exception e ) {
2522             e.printStackTrace( System.out );
2523             return false;
2524         }
2525         return true;
2526     }
2527
2528     private static boolean testBasicTable() {
2529         try {
2530             final BasicTable<String> t0 = new BasicTable<String>();
2531             if ( t0.getNumberOfColumns() != 0 ) {
2532                 return false;
2533             }
2534             if ( t0.getNumberOfRows() != 0 ) {
2535                 return false;
2536             }
2537             t0.setValue( 3, 2, "23" );
2538             t0.setValue( 10, 1, "error" );
2539             t0.setValue( 10, 1, "110" );
2540             t0.setValue( 9, 1, "19" );
2541             t0.setValue( 1, 10, "101" );
2542             t0.setValue( 10, 10, "1010" );
2543             t0.setValue( 100, 10, "10100" );
2544             t0.setValue( 0, 0, "00" );
2545             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2546                 return false;
2547             }
2548             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2549                 return false;
2550             }
2551             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2552                 return false;
2553             }
2554             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2555                 return false;
2556             }
2557             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2558                 return false;
2559             }
2560             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2561                 return false;
2562             }
2563             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2564                 return false;
2565             }
2566             if ( t0.getNumberOfColumns() != 101 ) {
2567                 return false;
2568             }
2569             if ( t0.getNumberOfRows() != 11 ) {
2570                 return false;
2571             }
2572             if ( t0.getValueAsString( 49, 4 ) != null ) {
2573                 return false;
2574             }
2575             final String l = ForesterUtil.getLineSeparator();
2576             final StringBuffer source = new StringBuffer();
2577             source.append( "" + l );
2578             source.append( "# 1 1 1 1 1 1 1 1" + l );
2579             source.append( " 00 01 02 03" + l );
2580             source.append( "   10 11 12 13  " + l );
2581             source.append( "20 21 22 23 " + l );
2582             source.append( "    30  31    32 33" + l );
2583             source.append( "40 41 42 43" + l );
2584             source.append( "  # 1 1 1 1 1 " + l );
2585             source.append( "50 51 52 53 54" + l );
2586             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2587             if ( t1.getNumberOfColumns() != 5 ) {
2588                 return false;
2589             }
2590             if ( t1.getNumberOfRows() != 6 ) {
2591                 return false;
2592             }
2593             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2594                 return false;
2595             }
2596             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2597                 return false;
2598             }
2599             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2600                 return false;
2601             }
2602             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2603                 return false;
2604             }
2605             final StringBuffer source1 = new StringBuffer();
2606             source1.append( "" + l );
2607             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2608             source1.append( " 00; 01 ;02;03" + l );
2609             source1.append( "   10; 11; 12; 13  " + l );
2610             source1.append( "20; 21; 22; 23 " + l );
2611             source1.append( "    30;  31;    32; 33" + l );
2612             source1.append( "40;41;42;43" + l );
2613             source1.append( "  # 1 1 1 1 1 " + l );
2614             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2615             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2616             if ( t2.getNumberOfColumns() != 5 ) {
2617                 return false;
2618             }
2619             if ( t2.getNumberOfRows() != 6 ) {
2620                 return false;
2621             }
2622             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2623                 return false;
2624             }
2625             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2626                 return false;
2627             }
2628             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2629                 return false;
2630             }
2631             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2632                 return false;
2633             }
2634             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2635                 return false;
2636             }
2637             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2638                 return false;
2639             }
2640             final StringBuffer source2 = new StringBuffer();
2641             source2.append( "" + l );
2642             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2643             source2.append( " 00; 01 ;02;03" + l );
2644             source2.append( "   10; 11; 12; 13  " + l );
2645             source2.append( "20; 21; 22; 23 " + l );
2646             source2.append( "                     " + l );
2647             source2.append( "    30;  31;    32; 33" + l );
2648             source2.append( "40;41;42;43" + l );
2649             source2.append( "  comment: 1 1 1 1 1 " + l );
2650             source2.append( ";;;50  ;   52; 53;;54   " + l );
2651             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2652                                                                         ';',
2653                                                                         false,
2654                                                                         false,
2655                                                                         "comment:",
2656                                                                         false );
2657             if ( tl.size() != 2 ) {
2658                 return false;
2659             }
2660             final BasicTable<String> t3 = tl.get( 0 );
2661             final BasicTable<String> t4 = tl.get( 1 );
2662             if ( t3.getNumberOfColumns() != 4 ) {
2663                 return false;
2664             }
2665             if ( t3.getNumberOfRows() != 3 ) {
2666                 return false;
2667             }
2668             if ( t4.getNumberOfColumns() != 4 ) {
2669                 return false;
2670             }
2671             if ( t4.getNumberOfRows() != 3 ) {
2672                 return false;
2673             }
2674             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2675                 return false;
2676             }
2677             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2678                 return false;
2679             }
2680         }
2681         catch ( final Exception e ) {
2682             e.printStackTrace( System.out );
2683             return false;
2684         }
2685         return true;
2686     }
2687
2688     private static boolean testBasicTolXMLparsing() {
2689         try {
2690             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2691             final TolParser parser = new TolParser();
2692             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2693             if ( parser.getErrorCount() > 0 ) {
2694                 System.out.println( parser.getErrorMessages().toString() );
2695                 return false;
2696             }
2697             if ( phylogenies_0.length != 1 ) {
2698                 return false;
2699             }
2700             final Phylogeny t1 = phylogenies_0[ 0 ];
2701             if ( t1.getNumberOfExternalNodes() != 5 ) {
2702                 return false;
2703             }
2704             if ( !t1.isRooted() ) {
2705                 return false;
2706             }
2707             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2708                 return false;
2709             }
2710             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2711                 return false;
2712             }
2713             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2714                 return false;
2715             }
2716             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2717                 return false;
2718             }
2719             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2720             if ( parser.getErrorCount() > 0 ) {
2721                 System.out.println( parser.getErrorMessages().toString() );
2722                 return false;
2723             }
2724             if ( phylogenies_1.length != 1 ) {
2725                 return false;
2726             }
2727             final Phylogeny t2 = phylogenies_1[ 0 ];
2728             if ( t2.getNumberOfExternalNodes() != 664 ) {
2729                 return false;
2730             }
2731             if ( !t2.isRooted() ) {
2732                 return false;
2733             }
2734             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2735                 return false;
2736             }
2737             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2738                 return false;
2739             }
2740             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2741                 return false;
2742             }
2743             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2744                 return false;
2745             }
2746             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2747                 return false;
2748             }
2749             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2750                     .equals( "Aquifex" ) ) {
2751                 return false;
2752             }
2753             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2754             if ( parser.getErrorCount() > 0 ) {
2755                 System.out.println( parser.getErrorMessages().toString() );
2756                 return false;
2757             }
2758             if ( phylogenies_2.length != 1 ) {
2759                 return false;
2760             }
2761             final Phylogeny t3 = phylogenies_2[ 0 ];
2762             if ( t3.getNumberOfExternalNodes() != 184 ) {
2763                 return false;
2764             }
2765             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2766                 return false;
2767             }
2768             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2769                 return false;
2770             }
2771             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2772                 return false;
2773             }
2774             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2775             if ( parser.getErrorCount() > 0 ) {
2776                 System.out.println( parser.getErrorMessages().toString() );
2777                 return false;
2778             }
2779             if ( phylogenies_3.length != 1 ) {
2780                 return false;
2781             }
2782             final Phylogeny t4 = phylogenies_3[ 0 ];
2783             if ( t4.getNumberOfExternalNodes() != 1 ) {
2784                 return false;
2785             }
2786             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2787                 return false;
2788             }
2789             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2790                 return false;
2791             }
2792             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2793                 return false;
2794             }
2795             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2796             if ( parser.getErrorCount() > 0 ) {
2797                 System.out.println( parser.getErrorMessages().toString() );
2798                 return false;
2799             }
2800             if ( phylogenies_4.length != 1 ) {
2801                 return false;
2802             }
2803             final Phylogeny t5 = phylogenies_4[ 0 ];
2804             if ( t5.getNumberOfExternalNodes() != 13 ) {
2805                 return false;
2806             }
2807             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2808                 return false;
2809             }
2810             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2811                 return false;
2812             }
2813             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2814                 return false;
2815             }
2816         }
2817         catch ( final Exception e ) {
2818             e.printStackTrace( System.out );
2819             return false;
2820         }
2821         return true;
2822     }
2823
2824     private static boolean testBasicTreeMethods() {
2825         try {
2826             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2827             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2828             if ( t2.getNumberOfExternalNodes() != 4 ) {
2829                 return false;
2830             }
2831             if ( t2.getHeight() != 8.5 ) {
2832                 return false;
2833             }
2834             if ( !t2.isCompletelyBinary() ) {
2835                 return false;
2836             }
2837             if ( t2.isEmpty() ) {
2838                 return false;
2839             }
2840             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2841             if ( t3.getNumberOfExternalNodes() != 5 ) {
2842                 return false;
2843             }
2844             if ( t3.getHeight() != 11 ) {
2845                 return false;
2846             }
2847             if ( t3.isCompletelyBinary() ) {
2848                 return false;
2849             }
2850             final PhylogenyNode n = t3.getNode( "ABC" );
2851             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 ];
2852             if ( t4.getNumberOfExternalNodes() != 9 ) {
2853                 return false;
2854             }
2855             if ( t4.getHeight() != 11 ) {
2856                 return false;
2857             }
2858             if ( t4.isCompletelyBinary() ) {
2859                 return false;
2860             }
2861             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)" );
2862             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2863             if ( t5.getNumberOfExternalNodes() != 8 ) {
2864                 return false;
2865             }
2866             if ( t5.getHeight() != 15 ) {
2867                 return false;
2868             }
2869             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)" );
2870             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2871             if ( t6.getHeight() != 15 ) {
2872                 return false;
2873             }
2874             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)" );
2875             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2876             if ( t7.getHeight() != 15 ) {
2877                 return false;
2878             }
2879             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)" );
2880             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2881             if ( t8.getNumberOfExternalNodes() != 10 ) {
2882                 return false;
2883             }
2884             if ( t8.getHeight() != 15 ) {
2885                 return false;
2886             }
2887             final char[] a9 = new char[] { 'a' };
2888             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2889             if ( t9.getHeight() != 0 ) {
2890                 return false;
2891             }
2892             final char[] a10 = new char[] { 'a', ':', '6' };
2893             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2894             if ( t10.getHeight() != 6 ) {
2895                 return false;
2896             }
2897         }
2898         catch ( final Exception e ) {
2899             e.printStackTrace( System.out );
2900             return false;
2901         }
2902         return true;
2903     }
2904
2905     private static boolean testConfidenceAssessor() {
2906         try {
2907             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2908             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2909             final Phylogeny[] ev0 = factory
2910                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2911                              new NHXParser() );
2912             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2913             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2914                 return false;
2915             }
2916             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2917                 return false;
2918             }
2919             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2920             final Phylogeny[] ev1 = factory
2921                     .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)));",
2922                              new NHXParser() );
2923             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2924             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2925                 return false;
2926             }
2927             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2928                 return false;
2929             }
2930             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2931             final Phylogeny[] ev_b = factory
2932                     .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",
2933                              new NHXParser() );
2934             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2935             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2936                 return false;
2937             }
2938             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2939                 return false;
2940             }
2941             //
2942             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2943             final Phylogeny[] ev1x = factory
2944                     .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)));",
2945                              new NHXParser() );
2946             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2947             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2948                 return false;
2949             }
2950             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2951                 return false;
2952             }
2953             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2954             final Phylogeny[] ev_bx = factory
2955                     .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",
2956                              new NHXParser() );
2957             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2958             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2959                 return false;
2960             }
2961             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2962                 return false;
2963             }
2964             //
2965             final Phylogeny[] t2 = factory
2966                     .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);",
2967                              new NHXParser() );
2968             final Phylogeny[] ev2 = factory
2969                     .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);",
2970                              new NHXParser() );
2971             for( final Phylogeny target : t2 ) {
2972                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2973             }
2974             //
2975             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2976                                                  new NHXParser() )[ 0 ];
2977             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2978             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2979             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2980                 return false;
2981             }
2982             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2983                 return false;
2984             }
2985             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2986                 return false;
2987             }
2988         }
2989         catch ( final Exception e ) {
2990             e.printStackTrace();
2991             return false;
2992         }
2993         return true;
2994     }
2995
2996     private static boolean testCopyOfNodeData() {
2997         try {
2998             final PhylogenyNode n1 = PhylogenyNode
2999                     .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]" );
3000             final PhylogenyNode n2 = n1.copyNodeData();
3001             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3002                 return false;
3003             }
3004         }
3005         catch ( final Exception e ) {
3006             e.printStackTrace();
3007             return false;
3008         }
3009         return true;
3010     }
3011
3012     private static boolean testCreateBalancedPhylogeny() {
3013         try {
3014             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3015             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3016                 return false;
3017             }
3018             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3019                 return false;
3020             }
3021             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3022             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3023                 return false;
3024             }
3025             if ( p1.getNumberOfExternalNodes() != 100 ) {
3026                 return false;
3027             }
3028         }
3029         catch ( final Exception e ) {
3030             e.printStackTrace();
3031             return false;
3032         }
3033         return true;
3034     }
3035
3036     private static boolean testCreateUriForSeqWeb() {
3037         try {
3038             final PhylogenyNode n = new PhylogenyNode();
3039             n.setName( "tr|B3RJ64" );
3040             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3041                 return false;
3042             }
3043             n.setName( "B0LM41_HUMAN" );
3044             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3045                 return false;
3046             }
3047             n.setName( "NP_001025424" );
3048             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3049                 return false;
3050             }
3051             n.setName( "_NM_001030253-" );
3052             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3053                 return false;
3054             }
3055             n.setName( "XM_002122186" );
3056             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3057                 return false;
3058             }
3059             n.setName( "dgh_AAA34956_gdg" );
3060             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3061                 return false;
3062             }
3063             n.setName( "AAA34956" );
3064             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3065                 return false;
3066             }
3067             n.setName( "GI:394892" );
3068             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3069                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3070                 return false;
3071             }
3072             n.setName( "gi_394892" );
3073             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3074                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3075                 return false;
3076             }
3077             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3078             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3079                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3080                 return false;
3081             }
3082             n.setName( "P12345" );
3083             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3084                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3085                 return false;
3086             }
3087             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3088             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3089                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3090                 return false;
3091             }
3092         }
3093         catch ( final Exception e ) {
3094             e.printStackTrace( System.out );
3095             return false;
3096         }
3097         return true;
3098     }
3099
3100     private static boolean testDataObjects() {
3101         try {
3102             final Confidence s0 = new Confidence();
3103             final Confidence s1 = new Confidence();
3104             if ( !s0.isEqual( s1 ) ) {
3105                 return false;
3106             }
3107             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3108             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3109             if ( s2.isEqual( s1 ) ) {
3110                 return false;
3111             }
3112             if ( !s2.isEqual( s3 ) ) {
3113                 return false;
3114             }
3115             final Confidence s4 = ( Confidence ) s3.copy();
3116             if ( !s4.isEqual( s3 ) ) {
3117                 return false;
3118             }
3119             s3.asSimpleText();
3120             s3.asText();
3121             // Taxonomy
3122             // ----------
3123             final Taxonomy t1 = new Taxonomy();
3124             final Taxonomy t2 = new Taxonomy();
3125             final Taxonomy t3 = new Taxonomy();
3126             final Taxonomy t4 = new Taxonomy();
3127             final Taxonomy t5 = new Taxonomy();
3128             t1.setIdentifier( new Identifier( "ecoli" ) );
3129             t1.setTaxonomyCode( "ECOLI" );
3130             t1.setScientificName( "E. coli" );
3131             t1.setCommonName( "coli" );
3132             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3133             if ( !t1.isEqual( t0 ) ) {
3134                 return false;
3135             }
3136             t2.setIdentifier( new Identifier( "ecoli" ) );
3137             t2.setTaxonomyCode( "OTHER" );
3138             t2.setScientificName( "what" );
3139             t2.setCommonName( "something" );
3140             if ( !t1.isEqual( t2 ) ) {
3141                 return false;
3142             }
3143             t2.setIdentifier( new Identifier( "nemve" ) );
3144             if ( t1.isEqual( t2 ) ) {
3145                 return false;
3146             }
3147             t1.setIdentifier( null );
3148             t3.setTaxonomyCode( "ECOLI" );
3149             t3.setScientificName( "what" );
3150             t3.setCommonName( "something" );
3151             if ( !t1.isEqual( t3 ) ) {
3152                 return false;
3153             }
3154             t1.setIdentifier( null );
3155             t1.setTaxonomyCode( "" );
3156             t4.setScientificName( "E. ColI" );
3157             t4.setCommonName( "something" );
3158             if ( !t1.isEqual( t4 ) ) {
3159                 return false;
3160             }
3161             t4.setScientificName( "B. subtilis" );
3162             t4.setCommonName( "something" );
3163             if ( t1.isEqual( t4 ) ) {
3164                 return false;
3165             }
3166             t1.setIdentifier( null );
3167             t1.setTaxonomyCode( "" );
3168             t1.setScientificName( "" );
3169             t5.setCommonName( "COLI" );
3170             if ( !t1.isEqual( t5 ) ) {
3171                 return false;
3172             }
3173             t5.setCommonName( "vibrio" );
3174             if ( t1.isEqual( t5 ) ) {
3175                 return false;
3176             }
3177             // Identifier
3178             // ----------
3179             final Identifier id0 = new Identifier( "123", "pfam" );
3180             final Identifier id1 = ( Identifier ) id0.copy();
3181             if ( !id1.isEqual( id1 ) ) {
3182                 return false;
3183             }
3184             if ( !id1.isEqual( id0 ) ) {
3185                 return false;
3186             }
3187             if ( !id0.isEqual( id1 ) ) {
3188                 return false;
3189             }
3190             id1.asSimpleText();
3191             id1.asText();
3192             // ProteinDomain
3193             // ---------------
3194             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3195             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3196             if ( !pd1.isEqual( pd1 ) ) {
3197                 return false;
3198             }
3199             if ( !pd1.isEqual( pd0 ) ) {
3200                 return false;
3201             }
3202             pd1.asSimpleText();
3203             pd1.asText();
3204             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3205             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3206             if ( !pd3.isEqual( pd3 ) ) {
3207                 return false;
3208             }
3209             if ( !pd2.isEqual( pd3 ) ) {
3210                 return false;
3211             }
3212             if ( !pd0.isEqual( pd3 ) ) {
3213                 return false;
3214             }
3215             pd3.asSimpleText();
3216             pd3.asText();
3217             // DomainArchitecture
3218             // ------------------
3219             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3220             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3221             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3222             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3223             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3224             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3225             domains0.add( d2 );
3226             domains0.add( d0 );
3227             domains0.add( d3 );
3228             domains0.add( d1 );
3229             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3230             if ( ds0.getNumberOfDomains() != 4 ) {
3231                 return false;
3232             }
3233             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3234             if ( !ds0.isEqual( ds0 ) ) {
3235                 return false;
3236             }
3237             if ( !ds0.isEqual( ds1 ) ) {
3238                 return false;
3239             }
3240             if ( ds1.getNumberOfDomains() != 4 ) {
3241                 return false;
3242             }
3243             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3244             domains1.add( d1 );
3245             domains1.add( d2 );
3246             domains1.add( d4 );
3247             domains1.add( d0 );
3248             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3249             if ( ds0.isEqual( ds2 ) ) {
3250                 return false;
3251             }
3252             ds1.asSimpleText();
3253             ds1.asText();
3254             ds1.toNHX();
3255             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3256             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3257                 System.out.println( ds3.toNHX() );
3258                 return false;
3259             }
3260             if ( ds3.getNumberOfDomains() != 3 ) {
3261                 return false;
3262             }
3263             // Event
3264             // -----
3265             final Event e1 = new Event( Event.EventType.fusion );
3266             if ( e1.isDuplication() ) {
3267                 return false;
3268             }
3269             if ( !e1.isFusion() ) {
3270                 return false;
3271             }
3272             if ( !e1.asText().toString().equals( "fusion" ) ) {
3273                 return false;
3274             }
3275             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3276                 return false;
3277             }
3278             final Event e11 = new Event( Event.EventType.fusion );
3279             if ( !e11.isEqual( e1 ) ) {
3280                 return false;
3281             }
3282             if ( !e11.toNHX().toString().equals( "" ) ) {
3283                 return false;
3284             }
3285             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3286             if ( e2.isDuplication() ) {
3287                 return false;
3288             }
3289             if ( !e2.isSpeciationOrDuplication() ) {
3290                 return false;
3291             }
3292             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3293                 return false;
3294             }
3295             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3296                 return false;
3297             }
3298             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3299                 return false;
3300             }
3301             if ( e11.isEqual( e2 ) ) {
3302                 return false;
3303             }
3304             final Event e2c = ( Event ) e2.copy();
3305             if ( !e2c.isEqual( e2 ) ) {
3306                 return false;
3307             }
3308             Event e3 = new Event( 1, 2, 3 );
3309             if ( e3.isDuplication() ) {
3310                 return false;
3311             }
3312             if ( e3.isSpeciation() ) {
3313                 return false;
3314             }
3315             if ( e3.isGeneLoss() ) {
3316                 return false;
3317             }
3318             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3319                 return false;
3320             }
3321             final Event e3c = ( Event ) e3.copy();
3322             final Event e3cc = ( Event ) e3c.copy();
3323             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3324                 return false;
3325             }
3326             e3 = null;
3327             if ( !e3c.isEqual( e3cc ) ) {
3328                 return false;
3329             }
3330             Event e4 = new Event( 1, 2, 3 );
3331             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3332                 return false;
3333             }
3334             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3335                 return false;
3336             }
3337             final Event e4c = ( Event ) e4.copy();
3338             e4 = null;
3339             final Event e4cc = ( Event ) e4c.copy();
3340             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3341                 return false;
3342             }
3343             if ( !e4c.isEqual( e4cc ) ) {
3344                 return false;
3345             }
3346             final Event e5 = new Event();
3347             if ( !e5.isUnassigned() ) {
3348                 return false;
3349             }
3350             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3351                 return false;
3352             }
3353             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3354                 return false;
3355             }
3356             final Event e6 = new Event( 1, 0, 0 );
3357             if ( !e6.asText().toString().equals( "duplication" ) ) {
3358                 return false;
3359             }
3360             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3361                 return false;
3362             }
3363             final Event e7 = new Event( 0, 1, 0 );
3364             if ( !e7.asText().toString().equals( "speciation" ) ) {
3365                 return false;
3366             }
3367             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3368                 return false;
3369             }
3370             final Event e8 = new Event( 0, 0, 1 );
3371             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3372                 return false;
3373             }
3374             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3375                 return false;
3376             }
3377         }
3378         catch ( final Exception e ) {
3379             e.printStackTrace( System.out );
3380             return false;
3381         }
3382         return true;
3383     }
3384
3385     private static boolean testDeletionOfExternalNodes() {
3386         try {
3387             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3388             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3389             final PhylogenyWriter w = new PhylogenyWriter();
3390             if ( t0.isEmpty() ) {
3391                 return false;
3392             }
3393             if ( t0.getNumberOfExternalNodes() != 1 ) {
3394                 return false;
3395             }
3396             t0.deleteSubtree( t0.getNode( "A" ), false );
3397             if ( t0.getNumberOfExternalNodes() != 0 ) {
3398                 return false;
3399             }
3400             if ( !t0.isEmpty() ) {
3401                 return false;
3402             }
3403             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3404             if ( t1.getNumberOfExternalNodes() != 2 ) {
3405                 return false;
3406             }
3407             t1.deleteSubtree( t1.getNode( "A" ), false );
3408             if ( t1.getNumberOfExternalNodes() != 1 ) {
3409                 return false;
3410             }
3411             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3412                 return false;
3413             }
3414             t1.deleteSubtree( t1.getNode( "B" ), false );
3415             if ( t1.getNumberOfExternalNodes() != 1 ) {
3416                 return false;
3417             }
3418             t1.deleteSubtree( t1.getNode( "r" ), false );
3419             if ( !t1.isEmpty() ) {
3420                 return false;
3421             }
3422             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3423             if ( t2.getNumberOfExternalNodes() != 3 ) {
3424                 return false;
3425             }
3426             t2.deleteSubtree( t2.getNode( "B" ), false );
3427             if ( t2.getNumberOfExternalNodes() != 2 ) {
3428                 return false;
3429             }
3430             t2.toNewHampshireX();
3431             PhylogenyNode n = t2.getNode( "A" );
3432             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3433                 return false;
3434             }
3435             t2.deleteSubtree( t2.getNode( "A" ), false );
3436             if ( t2.getNumberOfExternalNodes() != 2 ) {
3437                 return false;
3438             }
3439             t2.deleteSubtree( t2.getNode( "C" ), true );
3440             if ( t2.getNumberOfExternalNodes() != 1 ) {
3441                 return false;
3442             }
3443             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3444             if ( t3.getNumberOfExternalNodes() != 4 ) {
3445                 return false;
3446             }
3447             t3.deleteSubtree( t3.getNode( "B" ), true );
3448             if ( t3.getNumberOfExternalNodes() != 3 ) {
3449                 return false;
3450             }
3451             n = t3.getNode( "A" );
3452             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3453                 return false;
3454             }
3455             n = n.getNextExternalNode();
3456             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3457                 return false;
3458             }
3459             t3.deleteSubtree( t3.getNode( "A" ), true );
3460             if ( t3.getNumberOfExternalNodes() != 2 ) {
3461                 return false;
3462             }
3463             n = t3.getNode( "C" );
3464             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3465                 return false;
3466             }
3467             t3.deleteSubtree( t3.getNode( "C" ), true );
3468             if ( t3.getNumberOfExternalNodes() != 1 ) {
3469                 return false;
3470             }
3471             t3.deleteSubtree( t3.getNode( "D" ), true );
3472             if ( t3.getNumberOfExternalNodes() != 0 ) {
3473                 return false;
3474             }
3475             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3476             if ( t4.getNumberOfExternalNodes() != 6 ) {
3477                 return false;
3478             }
3479             t4.deleteSubtree( t4.getNode( "B2" ), true );
3480             if ( t4.getNumberOfExternalNodes() != 5 ) {
3481                 return false;
3482             }
3483             String s = w.toNewHampshire( t4, true ).toString();
3484             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3485                 return false;
3486             }
3487             t4.deleteSubtree( t4.getNode( "B11" ), true );
3488             if ( t4.getNumberOfExternalNodes() != 4 ) {
3489                 return false;
3490             }
3491             t4.deleteSubtree( t4.getNode( "C" ), true );
3492             if ( t4.getNumberOfExternalNodes() != 3 ) {
3493                 return false;
3494             }
3495             n = t4.getNode( "A" );
3496             n = n.getNextExternalNode();
3497             if ( !n.getName().equals( "B12" ) ) {
3498                 return false;
3499             }
3500             n = n.getNextExternalNode();
3501             if ( !n.getName().equals( "D" ) ) {
3502                 return false;
3503             }
3504             s = w.toNewHampshire( t4, true ).toString();
3505             if ( !s.equals( "((A,B12),D);" ) ) {
3506                 return false;
3507             }
3508             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3509             t5.deleteSubtree( t5.getNode( "A" ), true );
3510             if ( t5.getNumberOfExternalNodes() != 5 ) {
3511                 return false;
3512             }
3513             s = w.toNewHampshire( t5, true ).toString();
3514             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3515                 return false;
3516             }
3517             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3518             t6.deleteSubtree( t6.getNode( "B11" ), true );
3519             if ( t6.getNumberOfExternalNodes() != 5 ) {
3520                 return false;
3521             }
3522             s = w.toNewHampshire( t6, false ).toString();
3523             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3524                 return false;
3525             }
3526             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3527             t7.deleteSubtree( t7.getNode( "B12" ), true );
3528             if ( t7.getNumberOfExternalNodes() != 5 ) {
3529                 return false;
3530             }
3531             s = w.toNewHampshire( t7, true ).toString();
3532             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3533                 return false;
3534             }
3535             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3536             t8.deleteSubtree( t8.getNode( "B2" ), true );
3537             if ( t8.getNumberOfExternalNodes() != 5 ) {
3538                 return false;
3539             }
3540             s = w.toNewHampshire( t8, false ).toString();
3541             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3542                 return false;
3543             }
3544             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3545             t9.deleteSubtree( t9.getNode( "C" ), true );
3546             if ( t9.getNumberOfExternalNodes() != 5 ) {
3547                 return false;
3548             }
3549             s = w.toNewHampshire( t9, true ).toString();
3550             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3551                 return false;
3552             }
3553             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3554             t10.deleteSubtree( t10.getNode( "D" ), true );
3555             if ( t10.getNumberOfExternalNodes() != 5 ) {
3556                 return false;
3557             }
3558             s = w.toNewHampshire( t10, true ).toString();
3559             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3560                 return false;
3561             }
3562             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3563             t11.deleteSubtree( t11.getNode( "A" ), true );
3564             if ( t11.getNumberOfExternalNodes() != 2 ) {
3565                 return false;
3566             }
3567             s = w.toNewHampshire( t11, true ).toString();
3568             if ( !s.equals( "(B,C);" ) ) {
3569                 return false;
3570             }
3571             t11.deleteSubtree( t11.getNode( "C" ), true );
3572             if ( t11.getNumberOfExternalNodes() != 1 ) {
3573                 return false;
3574             }
3575             s = w.toNewHampshire( t11, false ).toString();
3576             if ( !s.equals( "B;" ) ) {
3577                 return false;
3578             }
3579             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3580             t12.deleteSubtree( t12.getNode( "B2" ), true );
3581             if ( t12.getNumberOfExternalNodes() != 8 ) {
3582                 return false;
3583             }
3584             s = w.toNewHampshire( t12, true ).toString();
3585             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3586                 return false;
3587             }
3588             t12.deleteSubtree( t12.getNode( "B3" ), true );
3589             if ( t12.getNumberOfExternalNodes() != 7 ) {
3590                 return false;
3591             }
3592             s = w.toNewHampshire( t12, true ).toString();
3593             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3594                 return false;
3595             }
3596             t12.deleteSubtree( t12.getNode( "C3" ), true );
3597             if ( t12.getNumberOfExternalNodes() != 6 ) {
3598                 return false;
3599             }
3600             s = w.toNewHampshire( t12, true ).toString();
3601             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3602                 return false;
3603             }
3604             t12.deleteSubtree( t12.getNode( "A1" ), true );
3605             if ( t12.getNumberOfExternalNodes() != 5 ) {
3606                 return false;
3607             }
3608             s = w.toNewHampshire( t12, true ).toString();
3609             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3610                 return false;
3611             }
3612             t12.deleteSubtree( t12.getNode( "B1" ), true );
3613             if ( t12.getNumberOfExternalNodes() != 4 ) {
3614                 return false;
3615             }
3616             s = w.toNewHampshire( t12, true ).toString();
3617             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3618                 return false;
3619             }
3620             t12.deleteSubtree( t12.getNode( "A3" ), true );
3621             if ( t12.getNumberOfExternalNodes() != 3 ) {
3622                 return false;
3623             }
3624             s = w.toNewHampshire( t12, true ).toString();
3625             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3626                 return false;
3627             }
3628             t12.deleteSubtree( t12.getNode( "A2" ), true );
3629             if ( t12.getNumberOfExternalNodes() != 2 ) {
3630                 return false;
3631             }
3632             s = w.toNewHampshire( t12, true ).toString();
3633             if ( !s.equals( "(C1,C2);" ) ) {
3634                 return false;
3635             }
3636             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3637             t13.deleteSubtree( t13.getNode( "D" ), true );
3638             if ( t13.getNumberOfExternalNodes() != 4 ) {
3639                 return false;
3640             }
3641             s = w.toNewHampshire( t13, true ).toString();
3642             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3643                 return false;
3644             }
3645             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3646             t14.deleteSubtree( t14.getNode( "E" ), true );
3647             if ( t14.getNumberOfExternalNodes() != 5 ) {
3648                 return false;
3649             }
3650             s = w.toNewHampshire( t14, true ).toString();
3651             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3652                 return false;
3653             }
3654             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3655             t15.deleteSubtree( t15.getNode( "B2" ), true );
3656             if ( t15.getNumberOfExternalNodes() != 11 ) {
3657                 return false;
3658             }
3659             t15.deleteSubtree( t15.getNode( "B1" ), true );
3660             if ( t15.getNumberOfExternalNodes() != 10 ) {
3661                 return false;
3662             }
3663             t15.deleteSubtree( t15.getNode( "B3" ), true );
3664             if ( t15.getNumberOfExternalNodes() != 9 ) {
3665                 return false;
3666             }
3667             t15.deleteSubtree( t15.getNode( "B4" ), true );
3668             if ( t15.getNumberOfExternalNodes() != 8 ) {
3669                 return false;
3670             }
3671             t15.deleteSubtree( t15.getNode( "A1" ), true );
3672             if ( t15.getNumberOfExternalNodes() != 7 ) {
3673                 return false;
3674             }
3675             t15.deleteSubtree( t15.getNode( "C4" ), true );
3676             if ( t15.getNumberOfExternalNodes() != 6 ) {
3677                 return false;
3678             }
3679         }
3680         catch ( final Exception e ) {
3681             e.printStackTrace( System.out );
3682             return false;
3683         }
3684         return true;
3685     }
3686
3687     private static boolean testDescriptiveStatistics() {
3688         try {
3689             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3690             dss1.addValue( 82 );
3691             dss1.addValue( 78 );
3692             dss1.addValue( 70 );
3693             dss1.addValue( 58 );
3694             dss1.addValue( 42 );
3695             if ( dss1.getN() != 5 ) {
3696                 return false;
3697             }
3698             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3699                 return false;
3700             }
3701             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3702                 return false;
3703             }
3704             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3705                 return false;
3706             }
3707             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3708                 return false;
3709             }
3710             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3711                 return false;
3712             }
3713             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3714                 return false;
3715             }
3716             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3717                 return false;
3718             }
3719             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3720                 return false;
3721             }
3722             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3723                 return false;
3724             }
3725             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3726                 return false;
3727             }
3728             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3729                 return false;
3730             }
3731             dss1.addValue( 123 );
3732             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3733                 return false;
3734             }
3735             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3736                 return false;
3737             }
3738             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3739                 return false;
3740             }
3741             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3742             dss2.addValue( -1.85 );
3743             dss2.addValue( 57.5 );
3744             dss2.addValue( 92.78 );
3745             dss2.addValue( 57.78 );
3746             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3747                 return false;
3748             }
3749             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3750                 return false;
3751             }
3752             final double[] a = dss2.getDataAsDoubleArray();
3753             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3754                 return false;
3755             }
3756             dss2.addValue( -100 );
3757             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3758                 return false;
3759             }
3760             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3761                 return false;
3762             }
3763             final double[] ds = new double[ 14 ];
3764             ds[ 0 ] = 34;
3765             ds[ 1 ] = 23;
3766             ds[ 2 ] = 1;
3767             ds[ 3 ] = 32;
3768             ds[ 4 ] = 11;
3769             ds[ 5 ] = 2;
3770             ds[ 6 ] = 12;
3771             ds[ 7 ] = 33;
3772             ds[ 8 ] = 13;
3773             ds[ 9 ] = 22;
3774             ds[ 10 ] = 21;
3775             ds[ 11 ] = 35;
3776             ds[ 12 ] = 24;
3777             ds[ 13 ] = 31;
3778             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3779             if ( bins.length != 4 ) {
3780                 return false;
3781             }
3782             if ( bins[ 0 ] != 2 ) {
3783                 return false;
3784             }
3785             if ( bins[ 1 ] != 3 ) {
3786                 return false;
3787             }
3788             if ( bins[ 2 ] != 4 ) {
3789                 return false;
3790             }
3791             if ( bins[ 3 ] != 5 ) {
3792                 return false;
3793             }
3794             final double[] ds1 = new double[ 9 ];
3795             ds1[ 0 ] = 10.0;
3796             ds1[ 1 ] = 19.0;
3797             ds1[ 2 ] = 9.999;
3798             ds1[ 3 ] = 0.0;
3799             ds1[ 4 ] = 39.9;
3800             ds1[ 5 ] = 39.999;
3801             ds1[ 6 ] = 30.0;
3802             ds1[ 7 ] = 19.999;
3803             ds1[ 8 ] = 30.1;
3804             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3805             if ( bins1.length != 4 ) {
3806                 return false;
3807             }
3808             if ( bins1[ 0 ] != 2 ) {
3809                 return false;
3810             }
3811             if ( bins1[ 1 ] != 3 ) {
3812                 return false;
3813             }
3814             if ( bins1[ 2 ] != 0 ) {
3815                 return false;
3816             }
3817             if ( bins1[ 3 ] != 4 ) {
3818                 return false;
3819             }
3820             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3821             if ( bins1_1.length != 3 ) {
3822                 return false;
3823             }
3824             if ( bins1_1[ 0 ] != 3 ) {
3825                 return false;
3826             }
3827             if ( bins1_1[ 1 ] != 2 ) {
3828                 return false;
3829             }
3830             if ( bins1_1[ 2 ] != 4 ) {
3831                 return false;
3832             }
3833             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3834             if ( bins1_2.length != 3 ) {
3835                 return false;
3836             }
3837             if ( bins1_2[ 0 ] != 2 ) {
3838                 return false;
3839             }
3840             if ( bins1_2[ 1 ] != 2 ) {
3841                 return false;
3842             }
3843             if ( bins1_2[ 2 ] != 2 ) {
3844                 return false;
3845             }
3846             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3847             dss3.addValue( 1 );
3848             dss3.addValue( 1 );
3849             dss3.addValue( 1 );
3850             dss3.addValue( 2 );
3851             dss3.addValue( 3 );
3852             dss3.addValue( 4 );
3853             dss3.addValue( 5 );
3854             dss3.addValue( 5 );
3855             dss3.addValue( 5 );
3856             dss3.addValue( 6 );
3857             dss3.addValue( 7 );
3858             dss3.addValue( 8 );
3859             dss3.addValue( 9 );
3860             dss3.addValue( 10 );
3861             dss3.addValue( 10 );
3862             dss3.addValue( 10 );
3863             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3864             histo.toStringBuffer( 10, '=', 40, 5 );
3865             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3866         }
3867         catch ( final Exception e ) {
3868             e.printStackTrace( System.out );
3869             return false;
3870         }
3871         return true;
3872     }
3873
3874     private static boolean testDir( final String file ) {
3875         try {
3876             final File f = new File( file );
3877             if ( !f.exists() ) {
3878                 return false;
3879             }
3880             if ( !f.isDirectory() ) {
3881                 return false;
3882             }
3883             if ( !f.canRead() ) {
3884                 return false;
3885             }
3886         }
3887         catch ( final Exception e ) {
3888             return false;
3889         }
3890         return true;
3891     }
3892
3893     private static boolean testEbiEntryRetrieval() {
3894         try {
3895             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3896             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3897                 System.out.println( entry.getAccession() );
3898                 return false;
3899             }
3900             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3901                 System.out.println( entry.getTaxonomyScientificName() );
3902                 return false;
3903             }
3904             if ( !entry.getSequenceName()
3905                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3906                 System.out.println( entry.getSequenceName() );
3907                 return false;
3908             }
3909             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3910             //     System.out.println( entry.getSequenceSymbol() );
3911             //     return false;
3912             // }
3913             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3914                 System.out.println( entry.getGeneName() );
3915                 return false;
3916             }
3917             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3918                 System.out.println( entry.getTaxonomyIdentifier() );
3919                 return false;
3920             }
3921             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3922                 System.out.println( entry.getAnnotations().first().getRefValue() );
3923                 return false;
3924             }
3925             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3926                 System.out.println( entry.getAnnotations().first().getRefSource() );
3927                 return false;
3928             }
3929             if ( entry.getCrossReferences().size() != 5 ) {
3930                 return false;
3931             }
3932             //
3933             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3934             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3935                 return false;
3936             }
3937             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3938                 System.out.println( entry1.getTaxonomyScientificName() );
3939                 return false;
3940             }
3941             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3942                 System.out.println( entry1.getSequenceName() );
3943                 return false;
3944             }
3945             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3946                 System.out.println( entry1.getTaxonomyIdentifier() );
3947                 return false;
3948             }
3949             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3950                 System.out.println( entry1.getGeneName() );
3951                 return false;
3952             }
3953             if ( entry1.getCrossReferences().size() != 6 ) {
3954                 return false;
3955             }
3956             //
3957             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3958             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3959                 return false;
3960             }
3961             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3962                 System.out.println( entry2.getTaxonomyScientificName() );
3963                 return false;
3964             }
3965             if ( !entry2.getSequenceName()
3966                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3967                 System.out.println( entry2.getSequenceName() );
3968                 return false;
3969             }
3970             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3971                 System.out.println( entry2.getTaxonomyIdentifier() );
3972                 return false;
3973             }
3974             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3975                 System.out.println( entry2.getGeneName() );
3976                 return false;
3977             }
3978             if ( entry2.getCrossReferences().size() != 3 ) {
3979                 return false;
3980             }
3981             //
3982             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3983             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3984                 return false;
3985             }
3986             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3987                 System.out.println( entry3.getTaxonomyScientificName() );
3988                 return false;
3989             }
3990             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3991                 System.out.println( entry3.getSequenceName() );
3992                 return false;
3993             }
3994             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3995                 System.out.println( entry3.getTaxonomyIdentifier() );
3996                 return false;
3997             }
3998             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3999                 System.out.println( entry3.getSequenceSymbol() );
4000                 return false;
4001             }
4002             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4003                 return false;
4004             }
4005             if ( entry3.getCrossReferences().size() != 8 ) {
4006                 return false;
4007             }
4008             //
4009             //
4010             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4011             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4012                 return false;
4013             }
4014             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4015                 System.out.println( entry4.getTaxonomyScientificName() );
4016                 return false;
4017             }
4018             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4019                 System.out.println( entry4.getSequenceName() );
4020                 return false;
4021             }
4022             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4023                 System.out.println( entry4.getTaxonomyIdentifier() );
4024                 return false;
4025             }
4026             if ( !entry4.getGeneName().equals( "ras" ) ) {
4027                 System.out.println( entry4.getGeneName() );
4028                 return false;
4029             }
4030             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4031             //     System.out.println( entry4.getChromosome() );
4032             //     return false;
4033             // }
4034             // if ( !entry4.getMap().equals( "ras" ) ) {
4035             //     System.out.println( entry4.getMap() );
4036             //     return false;
4037             // }
4038             //TODO FIXME gi...
4039             //
4040             //TODO fails:
4041             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4042             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4043             //                return false;
4044             //            }
4045             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4046             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4047                 return false;
4048             }
4049             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4050                 System.out.println( entry5.getTaxonomyScientificName() );
4051                 return false;
4052             }
4053             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4054                 System.out.println( entry5.getSequenceName() );
4055                 return false;
4056             }
4057             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4058                 System.out.println( entry5.getTaxonomyIdentifier() );
4059                 return false;
4060             }
4061         }
4062         catch ( final IOException e ) {
4063             System.out.println();
4064             System.out.println( "the following might be due to absence internet connection:" );
4065             e.printStackTrace( System.out );
4066             return true;
4067         }
4068         catch ( final Exception e ) {
4069             e.printStackTrace();
4070             return false;
4071         }
4072         return true;
4073     }
4074
4075     private static boolean testExternalNodeRelatedMethods() {
4076         try {
4077             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4078             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4079             PhylogenyNode n = t1.getNode( "A" );
4080             n = n.getNextExternalNode();
4081             if ( !n.getName().equals( "B" ) ) {
4082                 return false;
4083             }
4084             n = n.getNextExternalNode();
4085             if ( !n.getName().equals( "C" ) ) {
4086                 return false;
4087             }
4088             n = n.getNextExternalNode();
4089             if ( !n.getName().equals( "D" ) ) {
4090                 return false;
4091             }
4092             n = t1.getNode( "B" );
4093             while ( !n.isLastExternalNode() ) {
4094                 n = n.getNextExternalNode();
4095             }
4096             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4097             n = t2.getNode( "A" );
4098             n = n.getNextExternalNode();
4099             if ( !n.getName().equals( "B" ) ) {
4100                 return false;
4101             }
4102             n = n.getNextExternalNode();
4103             if ( !n.getName().equals( "C" ) ) {
4104                 return false;
4105             }
4106             n = n.getNextExternalNode();
4107             if ( !n.getName().equals( "D" ) ) {
4108                 return false;
4109             }
4110             n = t2.getNode( "B" );
4111             while ( !n.isLastExternalNode() ) {
4112                 n = n.getNextExternalNode();
4113             }
4114             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4115             n = t3.getNode( "A" );
4116             n = n.getNextExternalNode();
4117             if ( !n.getName().equals( "B" ) ) {
4118                 return false;
4119             }
4120             n = n.getNextExternalNode();
4121             if ( !n.getName().equals( "C" ) ) {
4122                 return false;
4123             }
4124             n = n.getNextExternalNode();
4125             if ( !n.getName().equals( "D" ) ) {
4126                 return false;
4127             }
4128             n = n.getNextExternalNode();
4129             if ( !n.getName().equals( "E" ) ) {
4130                 return false;
4131             }
4132             n = n.getNextExternalNode();
4133             if ( !n.getName().equals( "F" ) ) {
4134                 return false;
4135             }
4136             n = n.getNextExternalNode();
4137             if ( !n.getName().equals( "G" ) ) {
4138                 return false;
4139             }
4140             n = n.getNextExternalNode();
4141             if ( !n.getName().equals( "H" ) ) {
4142                 return false;
4143             }
4144             n = t3.getNode( "B" );
4145             while ( !n.isLastExternalNode() ) {
4146                 n = n.getNextExternalNode();
4147             }
4148             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4149             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4150                 final PhylogenyNode node = iter.next();
4151             }
4152             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4153             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4154                 final PhylogenyNode node = iter.next();
4155             }
4156             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4157             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4158             if ( !iter.next().getName().equals( "A" ) ) {
4159                 return false;
4160             }
4161             if ( !iter.next().getName().equals( "B" ) ) {
4162                 return false;
4163             }
4164             if ( !iter.next().getName().equals( "C" ) ) {
4165                 return false;
4166             }
4167             if ( !iter.next().getName().equals( "D" ) ) {
4168                 return false;
4169             }
4170             if ( !iter.next().getName().equals( "E" ) ) {
4171                 return false;
4172             }
4173             if ( !iter.next().getName().equals( "F" ) ) {
4174                 return false;
4175             }
4176             if ( iter.hasNext() ) {
4177                 return false;
4178             }
4179         }
4180         catch ( final Exception e ) {
4181             e.printStackTrace( System.out );
4182             return false;
4183         }
4184         return true;
4185     }
4186
4187     private static boolean testExtractSNFromNodeName() {
4188         try {
4189             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4190                 return false;
4191             }
4192             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4193                 return false;
4194             }
4195             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4196                 return false;
4197             }
4198             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4199                     .equals( "Mus musculus musculus" ) ) {
4200                 return false;
4201             }
4202             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4203                     .equals( "Mus musculus musculus" ) ) {
4204                 return false;
4205             }
4206             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4207                     .equals( "Mus musculus musculus" ) ) {
4208                 return false;
4209             }
4210             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4211                     .equals( "Mus musculus musculus" ) ) {
4212                 return false;
4213             }
4214             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4215                 return false;
4216             }
4217             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4218                     .equals( "Mus musculus musculus" ) ) {
4219                 return false;
4220             }
4221             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4222                     .equals( "Mus musculus musculus" ) ) {
4223                 return false;
4224             }
4225             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4226                 return false;
4227             }
4228             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4229                 return false;
4230             }
4231             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4232                 return false;
4233             }
4234             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4235                 return false;
4236             }
4237             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4238                     .equals( "Mus musculus musculus" ) ) {
4239                 return false;
4240             }
4241             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4242                 return false;
4243             }
4244             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4245                 return false;
4246             }
4247             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4248                 return false;
4249             }
4250             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4251                 return false;
4252             }
4253             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4254                 return false;
4255             }
4256             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4257                 return false;
4258             }
4259             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4260                 return false;
4261             }
4262             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4263                 return false;
4264             }
4265             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4266                     .equals( "Mus musculus" ) ) {
4267                 return false;
4268             }
4269             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4270                     .equals( "Mus musculus" ) ) {
4271                 return false;
4272             }
4273             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4274                 return false;
4275             }
4276             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4277                     .equals( "Mus musculus musculus" ) ) {
4278                 return false;
4279             }
4280             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4281                     .equals( "Mus musculus musculus" ) ) {
4282                 return false;
4283             }
4284             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4285                     .equals( "Mus musculus musculus" ) ) {
4286                 return false;
4287             }
4288             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4289                 return false;
4290             }
4291             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4292                     .equals( "Pilostyles mexicana" ) ) {
4293                 return false;
4294             }
4295             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4296                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4297                 return false;
4298             }
4299             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4300                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4301                 return false;
4302             }
4303             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4304                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4305                 return false;
4306             }
4307             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4308                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4309                 return false;
4310             }
4311             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4312                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4313                 return false;
4314             }
4315             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4316                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4317                 return false;
4318             }
4319             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4320                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4321                 return false;
4322             }
4323             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4324                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4325                 return false;
4326             }
4327             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4328                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4332                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4333                 return false;
4334             }
4335             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4336                     .equals( "Escherichia coli (strain K12)" ) ) {
4337                 return false;
4338             }
4339             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4340                     .equals( "Escherichia coli (strain K12)" ) ) {
4341                 return false;
4342             }
4343             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4344                     .equals( "Escherichia coli (str. K12)" ) ) {
4345                 return false;
4346             }
4347             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4348                     .equals( "Escherichia coli (str. K12)" ) ) {
4349                 return false;
4350             }
4351             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4352                     .equals( "Escherichia coli (str. K12)" ) ) {
4353                 return false;
4354             }
4355             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4356                     .equals( "Escherichia coli (var. K12)" ) ) {
4357                 return false;
4358             }
4359             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4360                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4361                 return false;
4362             }
4363             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4364                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4365                 return false;
4366             }
4367             if ( !ParserUtils
4368                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4369                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4373                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4374                 return false;
4375             }
4376             if ( !ParserUtils
4377                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4378                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4379                 return false;
4380             }
4381             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4382                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4383                 return false;
4384             }
4385             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4386                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4390                 return false;
4391             }
4392             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4399                     .equals( "Macrocera sp." ) ) {
4400                 return false;
4401             }
4402             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4403                 return false;
4404             }
4405             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4406                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4410                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4414                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4418                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4419                 return false;
4420             }
4421         }
4422         catch ( final Exception e ) {
4423             e.printStackTrace( System.out );
4424             return false;
4425         }
4426         return true;
4427     }
4428
4429     private static boolean testExtractTaxonomyCodeFromNodeName() {
4430         try {
4431             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4432                 return false;
4433             }
4434             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4435                     .equals( "SOYBN" ) ) {
4436                 return false;
4437             }
4438             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4439                     .equals( "ARATH" ) ) {
4440                 return false;
4441             }
4442             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4443                     .equals( "ARATH" ) ) {
4444                 return false;
4445             }
4446             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4447                 return false;
4448             }
4449             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4450                 return false;
4451             }
4452             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4453                 return false;
4454             }
4455             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4456                     .equals( "SOYBN" ) ) {
4457                 return false;
4458             }
4459             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4460                     .equals( "SOYBN" ) ) {
4461                 return false;
4462             }
4463             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4464                     .equals( "SOYBN" ) ) {
4465                 return false;
4466             }
4467             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4468                     .equals( "SOYBN" ) ) {
4469                 return false;
4470             }
4471             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4472                     .equals( "SOYBN" ) ) {
4473                 return false;
4474             }
4475             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4476                     .equals( "SOYBN" ) ) {
4477                 return false;
4478             }
4479             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4480                     .equals( "SOYBN" ) ) {
4481                 return false;
4482             }
4483             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4484                     .equals( "SOYBN" ) ) {
4485                 return false;
4486             }
4487             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4488                 return false;
4489             }
4490             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4491                     .equals( "SOYBN" ) ) {
4492                 return false;
4493             }
4494             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4495                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4496                 return false;
4497             }
4498             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4499                     .equals( "9YX45" ) ) {
4500                 return false;
4501             }
4502             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4503                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4504                     .equals( "MOUSE" ) ) {
4505                 return false;
4506             }
4507             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4508                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4509                     .equals( "MOUSE" ) ) {
4510                 return false;
4511             }
4512             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4513                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4514                     .equals( "MOUSE" ) ) {
4515                 return false;
4516             }
4517             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4518                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4519                 return false;
4520             }
4521             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4522                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4523                 return false;
4524             }
4525             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4526                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4527                 return false;
4528             }
4529             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4530                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4531                 return false;
4532             }
4533             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4534                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4535                 return false;
4536             }
4537             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4538                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4539                 return false;
4540             }
4541             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4542                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4543                 return false;
4544             }
4545             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4546                     .equals( "RAT" ) ) {
4547                 return false;
4548             }
4549             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4550                     .equals( "PIG" ) ) {
4551                 return false;
4552             }
4553             if ( !ParserUtils
4554                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4555                     .equals( "MOUSE" ) ) {
4556                 return false;
4557             }
4558             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4559                     .equals( "MOUSE" ) ) {
4560                 return false;
4561             }
4562             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4563                 return false;
4564             }
4565         }
4566         catch ( final Exception e ) {
4567             e.printStackTrace( System.out );
4568             return false;
4569         }
4570         return true;
4571     }
4572
4573     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4574         try {
4575             PhylogenyNode n = new PhylogenyNode();
4576             n.setName( "tr|B3RJ64" );
4577             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4578                 return false;
4579             }
4580             n.setName( "tr.B3RJ64" );
4581             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4582                 return false;
4583             }
4584             n.setName( "tr=B3RJ64" );
4585             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4586                 return false;
4587             }
4588             n.setName( "tr-B3RJ64" );
4589             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4590                 return false;
4591             }
4592             n.setName( "tr/B3RJ64" );
4593             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4594                 return false;
4595             }
4596             n.setName( "tr\\B3RJ64" );
4597             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4598                 return false;
4599             }
4600             n.setName( "tr_B3RJ64" );
4601             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4602                 return false;
4603             }
4604             n.setName( " tr|B3RJ64 " );
4605             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4606                 return false;
4607             }
4608             n.setName( "-tr|B3RJ64-" );
4609             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4610                 return false;
4611             }
4612             n.setName( "-tr=B3RJ64-" );
4613             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4614                 return false;
4615             }
4616             n.setName( "_tr=B3RJ64_" );
4617             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4618                 return false;
4619             }
4620             n.setName( " tr_tr|B3RJ64_sp|123 " );
4621             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4622                 return false;
4623             }
4624             n.setName( "B3RJ64" );
4625             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4626                 return false;
4627             }
4628             n.setName( "sp|B3RJ64" );
4629             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4630                 return false;
4631             }
4632             n.setName( "sp|B3RJ64C" );
4633             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4634                 return false;
4635             }
4636             n.setName( "sp B3RJ64" );
4637             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4638                 return false;
4639             }
4640             n.setName( "sp|B3RJ6X" );
4641             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4642                 return false;
4643             }
4644             n.setName( "sp|B3RJ6" );
4645             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4646                 return false;
4647             }
4648             n.setName( "K1PYK7_CRAGI" );
4649             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4650                 return false;
4651             }
4652             n.setName( "K1PYK7_PEA" );
4653             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4654                 return false;
4655             }
4656             n.setName( "K1PYK7_RAT" );
4657             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4658                 return false;
4659             }
4660             n.setName( "K1PYK7_PIG" );
4661             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4662                 return false;
4663             }
4664             n.setName( "~K1PYK7_PIG~" );
4665             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4666                 return false;
4667             }
4668             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4669             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4670                 return false;
4671             }
4672             n.setName( "K1PYKX_CRAGI" );
4673             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4674                 return false;
4675             }
4676             n.setName( "XXXXX_CRAGI" );
4677             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4678                 return false;
4679             }
4680             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4681             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4682                 return false;
4683             }
4684             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4685             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4686                 return false;
4687             }
4688             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4689             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4690                 return false;
4691             }
4692             n = new PhylogenyNode();
4693             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4694             seq.setSymbol( "K1PYK7_CRAGI" );
4695             n.getNodeData().addSequence( seq );
4696             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4697                 return false;
4698             }
4699             seq.setSymbol( "tr|B3RJ64" );
4700             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4701                 return false;
4702             }
4703             n = new PhylogenyNode();
4704             seq = new org.forester.phylogeny.data.Sequence();
4705             seq.setName( "K1PYK7_CRAGI" );
4706             n.getNodeData().addSequence( seq );
4707             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4708                 return false;
4709             }
4710             seq.setName( "tr|B3RJ64" );
4711             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4712                 return false;
4713             }
4714             n = new PhylogenyNode();
4715             seq = new org.forester.phylogeny.data.Sequence();
4716             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4717             n.getNodeData().addSequence( seq );
4718             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4719                 return false;
4720             }
4721             n = new PhylogenyNode();
4722             seq = new org.forester.phylogeny.data.Sequence();
4723             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4724             n.getNodeData().addSequence( seq );
4725             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4726                 return false;
4727             }
4728             //
4729             n = new PhylogenyNode();
4730             n.setName( "ACP19736" );
4731             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4732                 return false;
4733             }
4734             n = new PhylogenyNode();
4735             n.setName( "|ACP19736|" );
4736             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4737                 return false;
4738             }
4739         }
4740         catch ( final Exception e ) {
4741             e.printStackTrace( System.out );
4742             return false;
4743         }
4744         return true;
4745     }
4746
4747     private static boolean testFastaParser() {
4748         try {
4749             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4750                 return false;
4751             }
4752             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4753                 return false;
4754             }
4755             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4756             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4757                 return false;
4758             }
4759             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4760                 return false;
4761             }
4762             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4763                 return false;
4764             }
4765             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4766                 return false;
4767             }
4768             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4769                 return false;
4770             }
4771             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4772                 return false;
4773             }
4774         }
4775         catch ( final Exception e ) {
4776             e.printStackTrace();
4777             return false;
4778         }
4779         return true;
4780     }
4781
4782     private static boolean testGenbankAccessorParsing() {
4783         //The format for GenBank Accession numbers are:
4784         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4785         //Protein:    3 letters + 5 numerals
4786         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4787         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4788             return false;
4789         }
4790         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4791             return false;
4792         }
4793         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4794             return false;
4795         }
4796         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4797             return false;
4798         }
4799         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4800             return false;
4801         }
4802         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4803             return false;
4804         }
4805         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4806             return false;
4807         }
4808         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4809             return false;
4810         }
4811         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4812             return false;
4813         }
4814         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4815             return false;
4816         }
4817         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4818             return false;
4819         }
4820         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4821             return false;
4822         }
4823         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4824             return false;
4825         }
4826         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4827             return false;
4828         }
4829         return true;
4830     }
4831
4832     private static boolean testGeneralMsaParser() {
4833         try {
4834             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4835             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4836             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4837             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4838             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4839             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4840             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4841             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4842             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4843                 return false;
4844             }
4845             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4846                 return false;
4847             }
4848             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4849                 return false;
4850             }
4851             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4852                 return false;
4853             }
4854             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4855                 return false;
4856             }
4857             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4858                 return false;
4859             }
4860             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4861                 return false;
4862             }
4863             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4864                 return false;
4865             }
4866             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4867                 return false;
4868             }
4869             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4870                 return false;
4871             }
4872             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4873                 return false;
4874             }
4875             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4876                 return false;
4877             }
4878             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4879             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4880                 return false;
4881             }
4882             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4883                 return false;
4884             }
4885             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4886                 return false;
4887             }
4888             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4889             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4890                 return false;
4891             }
4892             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4893                 return false;
4894             }
4895             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4896                 return false;
4897             }
4898             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4899             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4900                 return false;
4901             }
4902             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4903                 return false;
4904             }
4905             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4906                 return false;
4907             }
4908         }
4909         catch ( final Exception e ) {
4910             e.printStackTrace();
4911             return false;
4912         }
4913         return true;
4914     }
4915
4916     private static boolean testGeneralTable() {
4917         try {
4918             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4919             t0.setValue( 3, 2, "23" );
4920             t0.setValue( 10, 1, "error" );
4921             t0.setValue( 10, 1, "110" );
4922             t0.setValue( 9, 1, "19" );
4923             t0.setValue( 1, 10, "101" );
4924             t0.setValue( 10, 10, "1010" );
4925             t0.setValue( 100, 10, "10100" );
4926             t0.setValue( 0, 0, "00" );
4927             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4928                 return false;
4929             }
4930             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4931                 return false;
4932             }
4933             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4934                 return false;
4935             }
4936             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4937                 return false;
4938             }
4939             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4940                 return false;
4941             }
4942             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4943                 return false;
4944             }
4945             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4946                 return false;
4947             }
4948             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4949                 return false;
4950             }
4951             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4952                 return false;
4953             }
4954             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4955             t1.setValue( "3", "2", "23" );
4956             t1.setValue( "10", "1", "error" );
4957             t1.setValue( "10", "1", "110" );
4958             t1.setValue( "9", "1", "19" );
4959             t1.setValue( "1", "10", "101" );
4960             t1.setValue( "10", "10", "1010" );
4961             t1.setValue( "100", "10", "10100" );
4962             t1.setValue( "0", "0", "00" );
4963             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4964             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4965                 return false;
4966             }
4967             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4968                 return false;
4969             }
4970             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4971                 return false;
4972             }
4973             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4974                 return false;
4975             }
4976             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4977                 return false;
4978             }
4979             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4980                 return false;
4981             }
4982             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4983                 return false;
4984             }
4985             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4986                 return false;
4987             }
4988             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4989                 return false;
4990             }
4991             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4992                 return false;
4993             }
4994         }
4995         catch ( final Exception e ) {
4996             e.printStackTrace( System.out );
4997             return false;
4998         }
4999         return true;
5000     }
5001
5002     private static boolean testGetDistance() {
5003         try {
5004             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5005             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",
5006                                                  new NHXParser() )[ 0 ];
5007             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5008                 return false;
5009             }
5010             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5011                 return false;
5012             }
5013             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5014                 return false;
5015             }
5016             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5017                 return false;
5018             }
5019             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5020                 return false;
5021             }
5022             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5023                 return false;
5024             }
5025             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5026                 return false;
5027             }
5028             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5029                 return false;
5030             }
5031             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5032                 return false;
5033             }
5034             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5035                 return false;
5036             }
5037             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5038                 return false;
5039             }
5040             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5041                 return false;
5042             }
5043             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5044                 return false;
5045             }
5046             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5047                 return false;
5048             }
5049             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5050                 return false;
5051             }
5052             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5053                 return false;
5054             }
5055             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5056                 return false;
5057             }
5058             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5059                 return false;
5060             }
5061             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5062                 return false;
5063             }
5064             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5065                 return false;
5066             }
5067             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5068                 return false;
5069             }
5070             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5071                 return false;
5072             }
5073             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5074                 return false;
5075             }
5076             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5077                 return false;
5078             }
5079             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5080                 return false;
5081             }
5082             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5083                 return false;
5084             }
5085             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5086                 return false;
5087             }
5088             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5089                 return false;
5090             }
5091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5095                 return false;
5096             }
5097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5098                 return false;
5099             }
5100             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",
5101                                                  new NHXParser() )[ 0 ];
5102             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5103                 return false;
5104             }
5105             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5106                 return false;
5107             }
5108             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5109                 return false;
5110             }
5111             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5112                 return false;
5113             }
5114             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5115                 return false;
5116             }
5117             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5118                 return false;
5119             }
5120             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5121                 return false;
5122             }
5123             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5124                 return false;
5125             }
5126             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5127                 return false;
5128             }
5129             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5130                 return false;
5131             }
5132             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5133                 return false;
5134             }
5135         }
5136         catch ( final Exception e ) {
5137             e.printStackTrace( System.out );
5138             return false;
5139         }
5140         return true;
5141     }
5142
5143     private static boolean testGetLCA() {
5144         try {
5145             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5146             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5147                                                  new NHXParser() )[ 0 ];
5148             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5149             if ( !A.getName().equals( "A" ) ) {
5150                 return false;
5151             }
5152             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5153             if ( !gh.getName().equals( "gh" ) ) {
5154                 return false;
5155             }
5156             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5157             if ( !ab.getName().equals( "ab" ) ) {
5158                 return false;
5159             }
5160             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5161             if ( !ab2.getName().equals( "ab" ) ) {
5162                 return false;
5163             }
5164             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5165             if ( !gh2.getName().equals( "gh" ) ) {
5166                 return false;
5167             }
5168             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5169             if ( !gh3.getName().equals( "gh" ) ) {
5170                 return false;
5171             }
5172             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5173             if ( !abc.getName().equals( "abc" ) ) {
5174                 return false;
5175             }
5176             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5177             if ( !abc2.getName().equals( "abc" ) ) {
5178                 return false;
5179             }
5180             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5181             if ( !abcd.getName().equals( "abcd" ) ) {
5182                 return false;
5183             }
5184             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5185             if ( !abcd2.getName().equals( "abcd" ) ) {
5186                 return false;
5187             }
5188             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5189             if ( !abcdef.getName().equals( "abcdef" ) ) {
5190                 return false;
5191             }
5192             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5193             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5194                 return false;
5195             }
5196             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5197             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5198                 return false;
5199             }
5200             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5201             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5202                 return false;
5203             }
5204             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5205             if ( !abcde.getName().equals( "abcde" ) ) {
5206                 return false;
5207             }
5208             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5209             if ( !abcde2.getName().equals( "abcde" ) ) {
5210                 return false;
5211             }
5212             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5213             if ( !r.getName().equals( "abcdefgh" ) ) {
5214                 return false;
5215             }
5216             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5217             if ( !r2.getName().equals( "abcdefgh" ) ) {
5218                 return false;
5219             }
5220             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5221             if ( !r3.getName().equals( "abcdefgh" ) ) {
5222                 return false;
5223             }
5224             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5225             if ( !abcde3.getName().equals( "abcde" ) ) {
5226                 return false;
5227             }
5228             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5229             if ( !abcde4.getName().equals( "abcde" ) ) {
5230                 return false;
5231             }
5232             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5233             if ( !ab3.getName().equals( "ab" ) ) {
5234                 return false;
5235             }
5236             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5237             if ( !ab4.getName().equals( "ab" ) ) {
5238                 return false;
5239             }
5240             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5241             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5242             if ( !cd.getName().equals( "cd" ) ) {
5243                 return false;
5244             }
5245             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5246             if ( !cd2.getName().equals( "cd" ) ) {
5247                 return false;
5248             }
5249             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5250             if ( !cde.getName().equals( "cde" ) ) {
5251                 return false;
5252             }
5253             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5254             if ( !cde2.getName().equals( "cde" ) ) {
5255                 return false;
5256             }
5257             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5258             if ( !cdef.getName().equals( "cdef" ) ) {
5259                 return false;
5260             }
5261             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5262             if ( !cdef2.getName().equals( "cdef" ) ) {
5263                 return false;
5264             }
5265             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5266             if ( !cdef3.getName().equals( "cdef" ) ) {
5267                 return false;
5268             }
5269             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5270             if ( !rt.getName().equals( "r" ) ) {
5271                 return false;
5272             }
5273             final Phylogeny p3 = factory
5274                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5275                              new NHXParser() )[ 0 ];
5276             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5277             if ( !bc_3.getName().equals( "bc" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5281             if ( !ac_3.getName().equals( "abc" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5285             if ( !ad_3.getName().equals( "abcde" ) ) {
5286                 return false;
5287             }
5288             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5289             if ( !af_3.getName().equals( "abcdef" ) ) {
5290                 return false;
5291             }
5292             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5293             if ( !ag_3.getName().equals( "" ) ) {
5294                 return false;
5295             }
5296             if ( !ag_3.isRoot() ) {
5297                 return false;
5298             }
5299             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5300             if ( !al_3.getName().equals( "" ) ) {
5301                 return false;
5302             }
5303             if ( !al_3.isRoot() ) {
5304                 return false;
5305             }
5306             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5307             if ( !kl_3.getName().equals( "" ) ) {
5308                 return false;
5309             }
5310             if ( !kl_3.isRoot() ) {
5311                 return false;
5312             }
5313             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5314             if ( !fl_3.getName().equals( "" ) ) {
5315                 return false;
5316             }
5317             if ( !fl_3.isRoot() ) {
5318                 return false;
5319             }
5320             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5321             if ( !gk_3.getName().equals( "ghijk" ) ) {
5322                 return false;
5323             }
5324             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5325             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5326             if ( !r_4.getName().equals( "r" ) ) {
5327                 return false;
5328             }
5329             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5330             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5331             if ( !r_5.getName().equals( "root" ) ) {
5332                 return false;
5333             }
5334             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5335             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5336             if ( !r_6.getName().equals( "rot" ) ) {
5337                 return false;
5338             }
5339             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5340             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5341             if ( !r_7.getName().equals( "rott" ) ) {
5342                 return false;
5343             }
5344         }
5345         catch ( final Exception e ) {
5346             e.printStackTrace( System.out );
5347             return false;
5348         }
5349         return true;
5350     }
5351
5352     private static boolean testGetLCA2() {
5353         try {
5354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5355             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5356             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5357             PhylogenyMethods.preOrderReId( p_a );
5358             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5359                                                                                               p_a.getNode( "a" ) );
5360             if ( !p_a_1.getName().equals( "a" ) ) {
5361                 return false;
5362             }
5363             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5364             PhylogenyMethods.preOrderReId( p_b );
5365             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5366                                                                                               p_b.getNode( "a" ) );
5367             if ( !p_b_1.getName().equals( "b" ) ) {
5368                 return false;
5369             }
5370             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5371                                                                                               p_b.getNode( "b" ) );
5372             if ( !p_b_2.getName().equals( "b" ) ) {
5373                 return false;
5374             }
5375             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5376             PhylogenyMethods.preOrderReId( p_c );
5377             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5378                                                                                               p_c.getNode( "a" ) );
5379             if ( !p_c_1.getName().equals( "b" ) ) {
5380                 return false;
5381             }
5382             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5383                                                                                               p_c.getNode( "c" ) );
5384             if ( !p_c_2.getName().equals( "c" ) ) {
5385                 System.out.println( p_c_2.getName() );
5386                 System.exit( -1 );
5387                 return false;
5388             }
5389             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5390                                                                                               p_c.getNode( "b" ) );
5391             if ( !p_c_3.getName().equals( "b" ) ) {
5392                 return false;
5393             }
5394             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5395                                                                                               p_c.getNode( "a" ) );
5396             if ( !p_c_4.getName().equals( "c" ) ) {
5397                 return false;
5398             }
5399             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5400                                                  new NHXParser() )[ 0 ];
5401             PhylogenyMethods.preOrderReId( p1 );
5402             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5403                                                                                           p1.getNode( "A" ) );
5404             if ( !A.getName().equals( "A" ) ) {
5405                 return false;
5406             }
5407             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5408                                                                                            p1.getNode( "gh" ) );
5409             if ( !gh.getName().equals( "gh" ) ) {
5410                 return false;
5411             }
5412             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5413                                                                                            p1.getNode( "B" ) );
5414             if ( !ab.getName().equals( "ab" ) ) {
5415                 return false;
5416             }
5417             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5418                                                                                             p1.getNode( "A" ) );
5419             if ( !ab2.getName().equals( "ab" ) ) {
5420                 return false;
5421             }
5422             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5423                                                                                             p1.getNode( "G" ) );
5424             if ( !gh2.getName().equals( "gh" ) ) {
5425                 return false;
5426             }
5427             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5428                                                                                             p1.getNode( "H" ) );
5429             if ( !gh3.getName().equals( "gh" ) ) {
5430                 return false;
5431             }
5432             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5433                                                                                             p1.getNode( "A" ) );
5434             if ( !abc.getName().equals( "abc" ) ) {
5435                 return false;
5436             }
5437             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5438                                                                                              p1.getNode( "C" ) );
5439             if ( !abc2.getName().equals( "abc" ) ) {
5440                 return false;
5441             }
5442             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5443                                                                                              p1.getNode( "D" ) );
5444             if ( !abcd.getName().equals( "abcd" ) ) {
5445                 return false;
5446             }
5447             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5448                                                                                               p1.getNode( "A" ) );
5449             if ( !abcd2.getName().equals( "abcd" ) ) {
5450                 return false;
5451             }
5452             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5453                                                                                                p1.getNode( "F" ) );
5454             if ( !abcdef.getName().equals( "abcdef" ) ) {
5455                 return false;
5456             }
5457             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5458                                                                                                 p1.getNode( "A" ) );
5459             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5460                 return false;
5461             }
5462             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5463                                                                                                 p1.getNode( "F" ) );
5464             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5465                 return false;
5466             }
5467             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5468                                                                                                 p1.getNode( "ab" ) );
5469             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5470                 return false;
5471             }
5472             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5473                                                                                               p1.getNode( "E" ) );
5474             if ( !abcde.getName().equals( "abcde" ) ) {
5475                 return false;
5476             }
5477             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5478                                                                                                p1.getNode( "A" ) );
5479             if ( !abcde2.getName().equals( "abcde" ) ) {
5480                 return false;
5481             }
5482             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5483                                                                                           p1.getNode( "abcdefgh" ) );
5484             if ( !r.getName().equals( "abcdefgh" ) ) {
5485                 return false;
5486             }
5487             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5488                                                                                            p1.getNode( "H" ) );
5489             if ( !r2.getName().equals( "abcdefgh" ) ) {
5490                 return false;
5491             }
5492             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5493                                                                                            p1.getNode( "A" ) );
5494             if ( !r3.getName().equals( "abcdefgh" ) ) {
5495                 return false;
5496             }
5497             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5498                                                                                                p1.getNode( "abcde" ) );
5499             if ( !abcde3.getName().equals( "abcde" ) ) {
5500                 return false;
5501             }
5502             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5503                                                                                                p1.getNode( "E" ) );
5504             if ( !abcde4.getName().equals( "abcde" ) ) {
5505                 return false;
5506             }
5507             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5508                                                                                             p1.getNode( "B" ) );
5509             if ( !ab3.getName().equals( "ab" ) ) {
5510                 return false;
5511             }
5512             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5513                                                                                             p1.getNode( "ab" ) );
5514             if ( !ab4.getName().equals( "ab" ) ) {
5515                 return false;
5516             }
5517             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5518             PhylogenyMethods.preOrderReId( p2 );
5519             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5520                                                                                            p2.getNode( "d" ) );
5521             if ( !cd.getName().equals( "cd" ) ) {
5522                 return false;
5523             }
5524             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5525                                                                                             p2.getNode( "c" ) );
5526             if ( !cd2.getName().equals( "cd" ) ) {
5527                 return false;
5528             }
5529             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5530                                                                                             p2.getNode( "e" ) );
5531             if ( !cde.getName().equals( "cde" ) ) {
5532                 return false;
5533             }
5534             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5535                                                                                              p2.getNode( "c" ) );
5536             if ( !cde2.getName().equals( "cde" ) ) {
5537                 return false;
5538             }
5539             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5540                                                                                              p2.getNode( "f" ) );
5541             if ( !cdef.getName().equals( "cdef" ) ) {
5542                 return false;
5543             }
5544             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5545                                                                                               p2.getNode( "f" ) );
5546             if ( !cdef2.getName().equals( "cdef" ) ) {
5547                 return false;
5548             }
5549             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5550                                                                                               p2.getNode( "d" ) );
5551             if ( !cdef3.getName().equals( "cdef" ) ) {
5552                 return false;
5553             }
5554             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5555                                                                                            p2.getNode( "a" ) );
5556             if ( !rt.getName().equals( "r" ) ) {
5557                 return false;
5558             }
5559             final Phylogeny p3 = factory
5560                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5561                              new NHXParser() )[ 0 ];
5562             PhylogenyMethods.preOrderReId( p3 );
5563             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5564                                                                                              p3.getNode( "c" ) );
5565             if ( !bc_3.getName().equals( "bc" ) ) {
5566                 return false;
5567             }
5568             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5569                                                                                              p3.getNode( "c" ) );
5570             if ( !ac_3.getName().equals( "abc" ) ) {
5571                 return false;
5572             }
5573             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5574                                                                                              p3.getNode( "d" ) );
5575             if ( !ad_3.getName().equals( "abcde" ) ) {
5576                 return false;
5577             }
5578             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5579                                                                                              p3.getNode( "f" ) );
5580             if ( !af_3.getName().equals( "abcdef" ) ) {
5581                 return false;
5582             }
5583             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5584                                                                                              p3.getNode( "g" ) );
5585             if ( !ag_3.getName().equals( "" ) ) {
5586                 return false;
5587             }
5588             if ( !ag_3.isRoot() ) {
5589                 return false;
5590             }
5591             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5592                                                                                              p3.getNode( "l" ) );
5593             if ( !al_3.getName().equals( "" ) ) {
5594                 return false;
5595             }
5596             if ( !al_3.isRoot() ) {
5597                 return false;
5598             }
5599             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5600                                                                                              p3.getNode( "l" ) );
5601             if ( !kl_3.getName().equals( "" ) ) {
5602                 return false;
5603             }
5604             if ( !kl_3.isRoot() ) {
5605                 return false;
5606             }
5607             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5608                                                                                              p3.getNode( "l" ) );
5609             if ( !fl_3.getName().equals( "" ) ) {
5610                 return false;
5611             }
5612             if ( !fl_3.isRoot() ) {
5613                 return false;
5614             }
5615             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5616                                                                                              p3.getNode( "k" ) );
5617             if ( !gk_3.getName().equals( "ghijk" ) ) {
5618                 return false;
5619             }
5620             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5621             PhylogenyMethods.preOrderReId( p4 );
5622             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5623                                                                                             p4.getNode( "c" ) );
5624             if ( !r_4.getName().equals( "r" ) ) {
5625                 return false;
5626             }
5627             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5628             PhylogenyMethods.preOrderReId( p5 );
5629             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5630                                                                                             p5.getNode( "c" ) );
5631             if ( !r_5.getName().equals( "root" ) ) {
5632                 return false;
5633             }
5634             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5635             PhylogenyMethods.preOrderReId( p6 );
5636             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5637                                                                                             p6.getNode( "a" ) );
5638             if ( !r_6.getName().equals( "rot" ) ) {
5639                 return false;
5640             }
5641             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5642             PhylogenyMethods.preOrderReId( p7 );
5643             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5644                                                                                             p7.getNode( "e" ) );
5645             if ( !r_7.getName().equals( "rott" ) ) {
5646                 return false;
5647             }
5648             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5649                                                                                              p7.getNode( "a" ) );
5650             if ( !r_71.getName().equals( "rott" ) ) {
5651                 return false;
5652             }
5653             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5654                                                                                              p7.getNode( "rott" ) );
5655             if ( !r_72.getName().equals( "rott" ) ) {
5656                 return false;
5657             }
5658             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5659                                                                                              p7.getNode( "a" ) );
5660             if ( !r_73.getName().equals( "rott" ) ) {
5661                 return false;
5662             }
5663             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5664                                                                                              p7.getNode( "rott" ) );
5665             if ( !r_74.getName().equals( "rott" ) ) {
5666                 return false;
5667             }
5668             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5669                                                                                              p7.getNode( "e" ) );
5670             if ( !r_75.getName().equals( "e" ) ) {
5671                 return false;
5672             }
5673         }
5674         catch ( final Exception e ) {
5675             e.printStackTrace( System.out );
5676             return false;
5677         }
5678         return true;
5679     }
5680
5681     private static boolean testHmmscanOutputParser() {
5682         final String test_dir = Test.PATH_TO_TEST_DATA;
5683         try {
5684             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5685                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5686             parser1.parse();
5687             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5688                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5689             final List<Protein> proteins = parser2.parse();
5690             if ( parser2.getProteinsEncountered() != 4 ) {
5691                 return false;
5692             }
5693             if ( proteins.size() != 4 ) {
5694                 return false;
5695             }
5696             if ( parser2.getDomainsEncountered() != 69 ) {
5697                 return false;
5698             }
5699             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5700                 return false;
5701             }
5702             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5703                 return false;
5704             }
5705             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5706                 return false;
5707             }
5708             final Protein p1 = proteins.get( 0 );
5709             if ( p1.getNumberOfProteinDomains() != 15 ) {
5710                 return false;
5711             }
5712             if ( p1.getLength() != 850 ) {
5713                 return false;
5714             }
5715             final Protein p2 = proteins.get( 1 );
5716             if ( p2.getNumberOfProteinDomains() != 51 ) {
5717                 return false;
5718             }
5719             if ( p2.getLength() != 1291 ) {
5720                 return false;
5721             }
5722             final Protein p3 = proteins.get( 2 );
5723             if ( p3.getNumberOfProteinDomains() != 2 ) {
5724                 return false;
5725             }
5726             final Protein p4 = proteins.get( 3 );
5727             if ( p4.getNumberOfProteinDomains() != 1 ) {
5728                 return false;
5729             }
5730             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5731                 return false;
5732             }
5733             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5734                 return false;
5735             }
5736             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5737                 return false;
5738             }
5739             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5740                 return false;
5741             }
5742             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5743                 return false;
5744             }
5745             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5746                 return false;
5747             }
5748             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5749                 return false;
5750             }
5751         }
5752         catch ( final Exception e ) {
5753             e.printStackTrace( System.out );
5754             return false;
5755         }
5756         return true;
5757     }
5758
5759     private static boolean testLastExternalNodeMethods() {
5760         try {
5761             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5762             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5763             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5764             final PhylogenyNode n1 = t0.getNode( "A" );
5765             if ( n1.isLastExternalNode() ) {
5766                 return false;
5767             }
5768             final PhylogenyNode n2 = t0.getNode( "B" );
5769             if ( n2.isLastExternalNode() ) {
5770                 return false;
5771             }
5772             final PhylogenyNode n3 = t0.getNode( "C" );
5773             if ( n3.isLastExternalNode() ) {
5774                 return false;
5775             }
5776             final PhylogenyNode n4 = t0.getNode( "D" );
5777             if ( !n4.isLastExternalNode() ) {
5778                 return false;
5779             }
5780         }
5781         catch ( final Exception e ) {
5782             e.printStackTrace( System.out );
5783             return false;
5784         }
5785         return true;
5786     }
5787
5788     private static boolean testLevelOrderIterator() {
5789         try {
5790             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5791             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5792             PhylogenyNodeIterator it0;
5793             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5794                 it0.next();
5795             }
5796             for( it0.reset(); it0.hasNext(); ) {
5797                 it0.next();
5798             }
5799             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5800             if ( !it.next().getName().equals( "r" ) ) {
5801                 return false;
5802             }
5803             if ( !it.next().getName().equals( "ab" ) ) {
5804                 return false;
5805             }
5806             if ( !it.next().getName().equals( "cd" ) ) {
5807                 return false;
5808             }
5809             if ( !it.next().getName().equals( "A" ) ) {
5810                 return false;
5811             }
5812             if ( !it.next().getName().equals( "B" ) ) {
5813                 return false;
5814             }
5815             if ( !it.next().getName().equals( "C" ) ) {
5816                 return false;
5817             }
5818             if ( !it.next().getName().equals( "D" ) ) {
5819                 return false;
5820             }
5821             if ( it.hasNext() ) {
5822                 return false;
5823             }
5824             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",
5825                                                  new NHXParser() )[ 0 ];
5826             PhylogenyNodeIterator it2;
5827             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5828                 it2.next();
5829             }
5830             for( it2.reset(); it2.hasNext(); ) {
5831                 it2.next();
5832             }
5833             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5834             if ( !it3.next().getName().equals( "r" ) ) {
5835                 return false;
5836             }
5837             if ( !it3.next().getName().equals( "abc" ) ) {
5838                 return false;
5839             }
5840             if ( !it3.next().getName().equals( "defg" ) ) {
5841                 return false;
5842             }
5843             if ( !it3.next().getName().equals( "A" ) ) {
5844                 return false;
5845             }
5846             if ( !it3.next().getName().equals( "B" ) ) {
5847                 return false;
5848             }
5849             if ( !it3.next().getName().equals( "C" ) ) {
5850                 return false;
5851             }
5852             if ( !it3.next().getName().equals( "D" ) ) {
5853                 return false;
5854             }
5855             if ( !it3.next().getName().equals( "E" ) ) {
5856                 return false;
5857             }
5858             if ( !it3.next().getName().equals( "F" ) ) {
5859                 return false;
5860             }
5861             if ( !it3.next().getName().equals( "G" ) ) {
5862                 return false;
5863             }
5864             if ( !it3.next().getName().equals( "1" ) ) {
5865                 return false;
5866             }
5867             if ( !it3.next().getName().equals( "2" ) ) {
5868                 return false;
5869             }
5870             if ( !it3.next().getName().equals( "3" ) ) {
5871                 return false;
5872             }
5873             if ( !it3.next().getName().equals( "4" ) ) {
5874                 return false;
5875             }
5876             if ( !it3.next().getName().equals( "5" ) ) {
5877                 return false;
5878             }
5879             if ( !it3.next().getName().equals( "6" ) ) {
5880                 return false;
5881             }
5882             if ( !it3.next().getName().equals( "f1" ) ) {
5883                 return false;
5884             }
5885             if ( !it3.next().getName().equals( "f2" ) ) {
5886                 return false;
5887             }
5888             if ( !it3.next().getName().equals( "f3" ) ) {
5889                 return false;
5890             }
5891             if ( !it3.next().getName().equals( "a" ) ) {
5892                 return false;
5893             }
5894             if ( !it3.next().getName().equals( "b" ) ) {
5895                 return false;
5896             }
5897             if ( !it3.next().getName().equals( "f21" ) ) {
5898                 return false;
5899             }
5900             if ( !it3.next().getName().equals( "X" ) ) {
5901                 return false;
5902             }
5903             if ( !it3.next().getName().equals( "Y" ) ) {
5904                 return false;
5905             }
5906             if ( !it3.next().getName().equals( "Z" ) ) {
5907                 return false;
5908             }
5909             if ( it3.hasNext() ) {
5910                 return false;
5911             }
5912             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5913             PhylogenyNodeIterator it4;
5914             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5915                 it4.next();
5916             }
5917             for( it4.reset(); it4.hasNext(); ) {
5918                 it4.next();
5919             }
5920             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5921             if ( !it5.next().getName().equals( "r" ) ) {
5922                 return false;
5923             }
5924             if ( !it5.next().getName().equals( "A" ) ) {
5925                 return false;
5926             }
5927             if ( !it5.next().getName().equals( "B" ) ) {
5928                 return false;
5929             }
5930             if ( !it5.next().getName().equals( "C" ) ) {
5931                 return false;
5932             }
5933             if ( !it5.next().getName().equals( "D" ) ) {
5934                 return false;
5935             }
5936             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5937             PhylogenyNodeIterator it6;
5938             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5939                 it6.next();
5940             }
5941             for( it6.reset(); it6.hasNext(); ) {
5942                 it6.next();
5943             }
5944             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5945             if ( !it7.next().getName().equals( "A" ) ) {
5946                 return false;
5947             }
5948             if ( it.hasNext() ) {
5949                 return false;
5950             }
5951         }
5952         catch ( final Exception e ) {
5953             e.printStackTrace( System.out );
5954             return false;
5955         }
5956         return true;
5957     }
5958
5959     private static boolean testMafft( final String path ) {
5960         try {
5961             final List<String> opts = new ArrayList<String>();
5962             opts.add( "--maxiterate" );
5963             opts.add( "1000" );
5964             opts.add( "--localpair" );
5965             opts.add( "--quiet" );
5966             Msa msa = null;
5967             final MsaInferrer mafft = Mafft.createInstance( path );
5968             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5969             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5970                 return false;
5971             }
5972             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5973                 return false;
5974             }
5975         }
5976         catch ( final Exception e ) {
5977             e.printStackTrace( System.out );
5978             return false;
5979         }
5980         return true;
5981     }
5982
5983     private static boolean testMidpointrooting() {
5984         try {
5985             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5986             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5987             PhylogenyMethods.midpointRoot( t0 );
5988             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5989                 return false;
5990             }
5991             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5992                 return false;
5993             }
5994             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5995                            1 ) ) {
5996                 return false;
5997             }
5998             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",
5999                                                  new NHXParser() )[ 0 ];
6000             if ( !t1.isRooted() ) {
6001                 return false;
6002             }
6003             PhylogenyMethods.midpointRoot( t1 );
6004             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6005                 return false;
6006             }
6007             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6008                 return false;
6009             }
6010             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6011                 return false;
6012             }
6013             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6014                 return false;
6015             }
6016             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6017                 return false;
6018             }
6019             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6020                 return false;
6021             }
6022             t1.reRoot( t1.getNode( "A" ) );
6023             PhylogenyMethods.midpointRoot( t1 );
6024             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6025                 return false;
6026             }
6027             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6028                 return false;
6029             }
6030             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6031                 return false;
6032             }
6033             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6034                 return false;
6035             }
6036             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6037                 System.exit( -1 );
6038                 return false;
6039             }
6040             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6041                 return false;
6042             }
6043         }
6044         catch ( final Exception e ) {
6045             e.printStackTrace( System.out );
6046             return false;
6047         }
6048         return true;
6049     }
6050
6051     private static boolean testMsaQualityMethod() {
6052         try {
6053             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6054             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6055             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6056             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6057             final List<Sequence> l = new ArrayList<Sequence>();
6058             l.add( s0 );
6059             l.add( s1 );
6060             l.add( s2 );
6061             l.add( s3 );
6062             final Msa msa = BasicMsa.createInstance( l );
6063             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6064                 return false;
6065             }
6066             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6067                 return false;
6068             }
6069             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6070                 return false;
6071             }
6072             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6073                 return false;
6074             }
6075             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6076                 return false;
6077             }
6078             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6079                 return false;
6080             }
6081             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6082                 return false;
6083             }
6084         }
6085         catch ( final Exception e ) {
6086             e.printStackTrace( System.out );
6087             return false;
6088         }
6089         return true;
6090     }
6091
6092     private static boolean testDeleteableMsa() {
6093         try {
6094             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6095             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6096             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6097             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6098             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6099             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6100             final List<Sequence> l0 = new ArrayList<Sequence>();
6101             l0.add( s0 );
6102             l0.add( s1 );
6103             l0.add( s2 );
6104             l0.add( s3 );
6105             l0.add( s4 );
6106             l0.add( s5 );
6107             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6108             dmsa0.deleteRow( "b" );
6109             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6110                 return false;
6111             }
6112             System.out.println();
6113             System.out.println( dmsa0.toString() );
6114             dmsa0.deleteRow( "e" );
6115             System.out.println();
6116             System.out.println( dmsa0.toString() );
6117             dmsa0.deleteRow( "a" );
6118             System.out.println();
6119             System.out.println( dmsa0.toString() );
6120             dmsa0.deleteRow( "f" );
6121             System.out.println();
6122             System.out.println( dmsa0.toString() );
6123             if ( dmsa0.getLength() != 4 ) {
6124                 return false;
6125             }
6126             if ( dmsa0.getNumberOfSequences() != 2 ) {
6127                 return false;
6128             }
6129             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6130                 return false;
6131             }
6132             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6133                 return false;
6134             }
6135             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6136                 return false;
6137             }
6138             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6139                 return false;
6140             }
6141             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6142                 return false;
6143             }
6144             dmsa0.deleteRow( "c" );
6145             dmsa0.deleteRow( "d" );
6146             if ( dmsa0.getNumberOfSequences() != 0 ) {
6147                 return false;
6148             }
6149             //
6150             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6151             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6152             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6153             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6154             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6155             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6156             final List<Sequence> l1 = new ArrayList<Sequence>();
6157             l1.add( s_0 );
6158             l1.add( s_1 );
6159             l1.add( s_2 );
6160             l1.add( s_3 );
6161             l1.add( s_4 );
6162             l1.add( s_5 );
6163             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6164             System.out.println( dmsa1.toString() );
6165             dmsa1.deleteGapOnlyColumns();
6166             System.out.println( dmsa1.toString() );
6167             dmsa1.deleteRow( "a" );
6168             dmsa1.deleteRow( "f" );
6169             dmsa1.deleteRow( "d" );
6170             System.out.println( dmsa1.toString() );
6171             dmsa1.deleteGapOnlyColumns();
6172             System.out.println( dmsa1.toString() );
6173             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6174                 return false;
6175             }
6176             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6177                 return false;
6178             }
6179             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6180                 return false;
6181             }
6182             dmsa1.deleteRow( "c" );
6183             dmsa1.deleteGapOnlyColumns();
6184             final Writer w0 = new StringWriter();
6185             dmsa1.write( w0, MSA_FORMAT.FASTA );
6186             System.out.println( w0.toString() );
6187             final Writer w1 = new StringWriter();
6188             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6189             System.out.println( w1.toString() );
6190             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6191                 return false;
6192             }
6193             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6194                 return false;
6195             }
6196             //
6197             final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6198             final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6199             final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6200             final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6201             final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6202             final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6203             final List<Sequence> l2 = new ArrayList<Sequence>();
6204             l2.add( s__0 );
6205             l2.add( s__1 );
6206             l2.add( s__2 );
6207             l2.add( s__3 );
6208             l2.add( s__4 );
6209             l2.add( s__5 );
6210             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6211             System.out.println( dmsa2.toString() );
6212             dmsa2.deleteGapColumns( 0.5 );
6213             System.out.println( dmsa2.toString() );
6214         }
6215         catch ( final Exception e ) {
6216             e.printStackTrace( System.out );
6217             return false;
6218         }
6219         return true;
6220     }
6221
6222     private static boolean testNextNodeWithCollapsing() {
6223         try {
6224             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6225             PhylogenyNode n;
6226             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6227             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6228             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6229             t0.getNode( "cd" ).setCollapse( true );
6230             t0.getNode( "cde" ).setCollapse( true );
6231             n = t0.getFirstExternalNode();
6232             while ( n != null ) {
6233                 ext.add( n );
6234                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6235             }
6236             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6237                 return false;
6238             }
6239             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6240                 return false;
6241             }
6242             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6243                 return false;
6244             }
6245             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6246                 return false;
6247             }
6248             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6249                 return false;
6250             }
6251             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6252                 return false;
6253             }
6254             ext.clear();
6255             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6256             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6257             t1.getNode( "ab" ).setCollapse( true );
6258             t1.getNode( "cd" ).setCollapse( true );
6259             t1.getNode( "cde" ).setCollapse( true );
6260             n = t1.getNode( "ab" );
6261             ext = new ArrayList<PhylogenyNode>();
6262             while ( n != null ) {
6263                 ext.add( n );
6264                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6265             }
6266             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6267                 return false;
6268             }
6269             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6270                 return false;
6271             }
6272             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6273                 return false;
6274             }
6275             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6276                 return false;
6277             }
6278             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6279                 return false;
6280             }
6281             //
6282             //
6283             ext.clear();
6284             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6285             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6286             t2.getNode( "ab" ).setCollapse( true );
6287             t2.getNode( "cd" ).setCollapse( true );
6288             t2.getNode( "cde" ).setCollapse( true );
6289             t2.getNode( "c" ).setCollapse( true );
6290             t2.getNode( "d" ).setCollapse( true );
6291             t2.getNode( "e" ).setCollapse( true );
6292             t2.getNode( "gh" ).setCollapse( true );
6293             n = t2.getNode( "ab" );
6294             ext = new ArrayList<PhylogenyNode>();
6295             while ( n != null ) {
6296                 ext.add( n );
6297                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6298             }
6299             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6300                 return false;
6301             }
6302             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6303                 return false;
6304             }
6305             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6306                 return false;
6307             }
6308             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6309                 return false;
6310             }
6311             //
6312             //
6313             ext.clear();
6314             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6315             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6316             t3.getNode( "ab" ).setCollapse( true );
6317             t3.getNode( "cd" ).setCollapse( true );
6318             t3.getNode( "cde" ).setCollapse( true );
6319             t3.getNode( "c" ).setCollapse( true );
6320             t3.getNode( "d" ).setCollapse( true );
6321             t3.getNode( "e" ).setCollapse( true );
6322             t3.getNode( "gh" ).setCollapse( true );
6323             t3.getNode( "fgh" ).setCollapse( true );
6324             n = t3.getNode( "ab" );
6325             ext = new ArrayList<PhylogenyNode>();
6326             while ( n != null ) {
6327                 ext.add( n );
6328                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6329             }
6330             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6331                 return false;
6332             }
6333             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6334                 return false;
6335             }
6336             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6337                 return false;
6338             }
6339             //
6340             //
6341             ext.clear();
6342             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6343             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6344             t4.getNode( "ab" ).setCollapse( true );
6345             t4.getNode( "cd" ).setCollapse( true );
6346             t4.getNode( "cde" ).setCollapse( true );
6347             t4.getNode( "c" ).setCollapse( true );
6348             t4.getNode( "d" ).setCollapse( true );
6349             t4.getNode( "e" ).setCollapse( true );
6350             t4.getNode( "gh" ).setCollapse( true );
6351             t4.getNode( "fgh" ).setCollapse( true );
6352             t4.getNode( "abcdefgh" ).setCollapse( true );
6353             n = t4.getNode( "abcdefgh" );
6354             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6355                 return false;
6356             }
6357             //
6358             //
6359             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6360             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6361             ext.clear();
6362             n = t5.getFirstExternalNode();
6363             while ( n != null ) {
6364                 ext.add( n );
6365                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6366             }
6367             if ( ext.size() != 8 ) {
6368                 return false;
6369             }
6370             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6371                 return false;
6372             }
6373             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6374                 return false;
6375             }
6376             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6377                 return false;
6378             }
6379             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6380                 return false;
6381             }
6382             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6383                 return false;
6384             }
6385             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6386                 return false;
6387             }
6388             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6389                 return false;
6390             }
6391             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6392                 return false;
6393             }
6394             //
6395             //
6396             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6397             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6398             ext.clear();
6399             t6.getNode( "ab" ).setCollapse( true );
6400             n = t6.getNode( "ab" );
6401             while ( n != null ) {
6402                 ext.add( n );
6403                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6404             }
6405             if ( ext.size() != 7 ) {
6406                 return false;
6407             }
6408             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6409                 return false;
6410             }
6411             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6412                 return false;
6413             }
6414             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6415                 return false;
6416             }
6417             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6418                 return false;
6419             }
6420             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6421                 return false;
6422             }
6423             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6424                 return false;
6425             }
6426             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6427                 return false;
6428             }
6429             //
6430             //
6431             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6432             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6433             ext.clear();
6434             t7.getNode( "cd" ).setCollapse( true );
6435             n = t7.getNode( "a" );
6436             while ( n != null ) {
6437                 ext.add( n );
6438                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6439             }
6440             if ( ext.size() != 7 ) {
6441                 return false;
6442             }
6443             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6444                 return false;
6445             }
6446             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6447                 return false;
6448             }
6449             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6450                 return false;
6451             }
6452             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6453                 return false;
6454             }
6455             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6456                 return false;
6457             }
6458             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6459                 return false;
6460             }
6461             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6462                 return false;
6463             }
6464             //
6465             //
6466             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6467             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6468             ext.clear();
6469             t8.getNode( "cd" ).setCollapse( true );
6470             t8.getNode( "c" ).setCollapse( true );
6471             t8.getNode( "d" ).setCollapse( true );
6472             n = t8.getNode( "a" );
6473             while ( n != null ) {
6474                 ext.add( n );
6475                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6476             }
6477             if ( ext.size() != 7 ) {
6478                 return false;
6479             }
6480             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6481                 return false;
6482             }
6483             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6487                 System.out.println( "2 fail" );
6488                 return false;
6489             }
6490             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6491                 return false;
6492             }
6493             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6494                 return false;
6495             }
6496             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6497                 return false;
6498             }
6499             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6500                 return false;
6501             }
6502             //
6503             //
6504             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6505             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6506             ext.clear();
6507             t9.getNode( "gh" ).setCollapse( true );
6508             n = t9.getNode( "a" );
6509             while ( n != null ) {
6510                 ext.add( n );
6511                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6512             }
6513             if ( ext.size() != 7 ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6520                 return false;
6521             }
6522             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6523                 return false;
6524             }
6525             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6526                 return false;
6527             }
6528             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6529                 return false;
6530             }
6531             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6532                 return false;
6533             }
6534             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6535                 return false;
6536             }
6537             //
6538             //
6539             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6540             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6541             ext.clear();
6542             t10.getNode( "gh" ).setCollapse( true );
6543             t10.getNode( "g" ).setCollapse( true );
6544             t10.getNode( "h" ).setCollapse( true );
6545             n = t10.getNode( "a" );
6546             while ( n != null ) {
6547                 ext.add( n );
6548                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6549             }
6550             if ( ext.size() != 7 ) {
6551                 return false;
6552             }
6553             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6554                 return false;
6555             }
6556             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6557                 return false;
6558             }
6559             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6560                 return false;
6561             }
6562             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6563                 return false;
6564             }
6565             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6566                 return false;
6567             }
6568             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6569                 return false;
6570             }
6571             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6572                 return false;
6573             }
6574             //
6575             //
6576             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6577             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6578             ext.clear();
6579             t11.getNode( "gh" ).setCollapse( true );
6580             t11.getNode( "fgh" ).setCollapse( true );
6581             n = t11.getNode( "a" );
6582             while ( n != null ) {
6583                 ext.add( n );
6584                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6585             }
6586             if ( ext.size() != 6 ) {
6587                 return false;
6588             }
6589             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6590                 return false;
6591             }
6592             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6593                 return false;
6594             }
6595             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6596                 return false;
6597             }
6598             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6599                 return false;
6600             }
6601             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6602                 return false;
6603             }
6604             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6605                 return false;
6606             }
6607             //
6608             //
6609             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6610             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6611             ext.clear();
6612             t12.getNode( "gh" ).setCollapse( true );
6613             t12.getNode( "fgh" ).setCollapse( true );
6614             t12.getNode( "g" ).setCollapse( true );
6615             t12.getNode( "h" ).setCollapse( true );
6616             t12.getNode( "f" ).setCollapse( true );
6617             n = t12.getNode( "a" );
6618             while ( n != null ) {
6619                 ext.add( n );
6620                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6621             }
6622             if ( ext.size() != 6 ) {
6623                 return false;
6624             }
6625             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6626                 return false;
6627             }
6628             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6629                 return false;
6630             }
6631             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6632                 return false;
6633             }
6634             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6635                 return false;
6636             }
6637             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6638                 return false;
6639             }
6640             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6641                 return false;
6642             }
6643             //
6644             //
6645             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6646             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6647             ext.clear();
6648             t13.getNode( "ab" ).setCollapse( true );
6649             t13.getNode( "b" ).setCollapse( true );
6650             t13.getNode( "fgh" ).setCollapse( true );
6651             t13.getNode( "gh" ).setCollapse( true );
6652             n = t13.getNode( "ab" );
6653             while ( n != null ) {
6654                 ext.add( n );
6655                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6656             }
6657             if ( ext.size() != 5 ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6661                 return false;
6662             }
6663             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6664                 return false;
6665             }
6666             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6667                 return false;
6668             }
6669             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6670                 return false;
6671             }
6672             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6673                 return false;
6674             }
6675             //
6676             //
6677             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6678             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6679             ext.clear();
6680             t14.getNode( "ab" ).setCollapse( true );
6681             t14.getNode( "a" ).setCollapse( true );
6682             t14.getNode( "fgh" ).setCollapse( true );
6683             t14.getNode( "gh" ).setCollapse( true );
6684             n = t14.getNode( "ab" );
6685             while ( n != null ) {
6686                 ext.add( n );
6687                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6688             }
6689             if ( ext.size() != 5 ) {
6690                 return false;
6691             }
6692             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6693                 return false;
6694             }
6695             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6696                 return false;
6697             }
6698             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6699                 return false;
6700             }
6701             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6702                 return false;
6703             }
6704             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6705                 return false;
6706             }
6707             //
6708             //
6709             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" );
6710             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6711             ext.clear();
6712             t15.getNode( "ab" ).setCollapse( true );
6713             t15.getNode( "a" ).setCollapse( true );
6714             t15.getNode( "fgh" ).setCollapse( true );
6715             t15.getNode( "gh" ).setCollapse( true );
6716             n = t15.getNode( "ab" );
6717             while ( n != null ) {
6718                 ext.add( n );
6719                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6720             }
6721             if ( ext.size() != 6 ) {
6722                 return false;
6723             }
6724             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6728                 return false;
6729             }
6730             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6731                 return false;
6732             }
6733             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6734                 return false;
6735             }
6736             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6737                 return false;
6738             }
6739             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6740                 return false;
6741             }
6742             //
6743             //
6744             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" );
6745             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6746             ext.clear();
6747             t16.getNode( "ab" ).setCollapse( true );
6748             t16.getNode( "a" ).setCollapse( true );
6749             t16.getNode( "fgh" ).setCollapse( true );
6750             t16.getNode( "gh" ).setCollapse( true );
6751             t16.getNode( "cd" ).setCollapse( true );
6752             t16.getNode( "cde" ).setCollapse( true );
6753             t16.getNode( "d" ).setCollapse( true );
6754             t16.getNode( "x" ).setCollapse( true );
6755             n = t16.getNode( "ab" );
6756             while ( n != null ) {
6757                 ext.add( n );
6758                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6759             }
6760             if ( ext.size() != 4 ) {
6761                 return false;
6762             }
6763             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6764                 return false;
6765             }
6766             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6767                 return false;
6768             }
6769             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6770                 return false;
6771             }
6772             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6773                 return false;
6774             }
6775         }
6776         catch ( final Exception e ) {
6777             e.printStackTrace( System.out );
6778             return false;
6779         }
6780         return true;
6781     }
6782
6783     private static boolean testNexusCharactersParsing() {
6784         try {
6785             final NexusCharactersParser parser = new NexusCharactersParser();
6786             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6787             parser.parse();
6788             String[] labels = parser.getCharStateLabels();
6789             if ( labels.length != 7 ) {
6790                 return false;
6791             }
6792             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6793                 return false;
6794             }
6795             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6796                 return false;
6797             }
6798             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6799                 return false;
6800             }
6801             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6802                 return false;
6803             }
6804             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6805                 return false;
6806             }
6807             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6808                 return false;
6809             }
6810             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6811                 return false;
6812             }
6813             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6814             parser.parse();
6815             labels = parser.getCharStateLabels();
6816             if ( labels.length != 7 ) {
6817                 return false;
6818             }
6819             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6820                 return false;
6821             }
6822             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6823                 return false;
6824             }
6825             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6826                 return false;
6827             }
6828             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6829                 return false;
6830             }
6831             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6832                 return false;
6833             }
6834             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6835                 return false;
6836             }
6837             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6838                 return false;
6839             }
6840         }
6841         catch ( final Exception e ) {
6842             e.printStackTrace( System.out );
6843             return false;
6844         }
6845         return true;
6846     }
6847
6848     private static boolean testNexusMatrixParsing() {
6849         try {
6850             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6851             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6852             parser.parse();
6853             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6854             if ( m.getNumberOfCharacters() != 9 ) {
6855                 return false;
6856             }
6857             if ( m.getNumberOfIdentifiers() != 5 ) {
6858                 return false;
6859             }
6860             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6861                 return false;
6862             }
6863             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6864                 return false;
6865             }
6866             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6867                 return false;
6868             }
6869             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6870                 return false;
6871             }
6872             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6873                 return false;
6874             }
6875             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6876                 return false;
6877             }
6878             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6879                 return false;
6880             }
6881             //            if ( labels.length != 7 ) {
6882             //                return false;
6883             //            }
6884             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6885             //                return false;
6886             //            }
6887             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6888             //                return false;
6889             //            }
6890             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6891             //                return false;
6892             //            }
6893             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6894             //                return false;
6895             //            }
6896             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6897             //                return false;
6898             //            }
6899             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6900             //                return false;
6901             //            }
6902             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6903             //                return false;
6904             //            }
6905             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6906             //            parser.parse();
6907             //            labels = parser.getCharStateLabels();
6908             //            if ( labels.length != 7 ) {
6909             //                return false;
6910             //            }
6911             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6912             //                return false;
6913             //            }
6914             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6915             //                return false;
6916             //            }
6917             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6918             //                return false;
6919             //            }
6920             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6921             //                return false;
6922             //            }
6923             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6924             //                return false;
6925             //            }
6926             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6927             //                return false;
6928             //            }
6929             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6930             //                return false;
6931             //            }
6932         }
6933         catch ( final Exception e ) {
6934             e.printStackTrace( System.out );
6935             return false;
6936         }
6937         return true;
6938     }
6939
6940     private static boolean testNexusTreeParsing() {
6941         try {
6942             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6943             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6944             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6945             if ( phylogenies.length != 1 ) {
6946                 return false;
6947             }
6948             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6949                 return false;
6950             }
6951             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6952                 return false;
6953             }
6954             phylogenies = null;
6955             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6956             if ( phylogenies.length != 1 ) {
6957                 return false;
6958             }
6959             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6960                 return false;
6961             }
6962             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6963                 return false;
6964             }
6965             phylogenies = null;
6966             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6967             if ( phylogenies.length != 1 ) {
6968                 return false;
6969             }
6970             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6971                 return false;
6972             }
6973             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6974                 return false;
6975             }
6976             if ( phylogenies[ 0 ].isRooted() ) {
6977                 return false;
6978             }
6979             phylogenies = null;
6980             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6981             if ( phylogenies.length != 18 ) {
6982                 return false;
6983             }
6984             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6985                 return false;
6986             }
6987             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6988                 return false;
6989             }
6990             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6991                 return false;
6992             }
6993             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6994                 return false;
6995             }
6996             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6997                 return false;
6998             }
6999             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7000                 return false;
7001             }
7002             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7003                 return false;
7004             }
7005             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7006                 return false;
7007             }
7008             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7009                 return false;
7010             }
7011             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7012                 return false;
7013             }
7014             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7015                 return false;
7016             }
7017             if ( phylogenies[ 8 ].isRooted() ) {
7018                 return false;
7019             }
7020             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7021                 return false;
7022             }
7023             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7024                 return false;
7025             }
7026             if ( !phylogenies[ 9 ].isRooted() ) {
7027                 return false;
7028             }
7029             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7030                 return false;
7031             }
7032             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7033                 return false;
7034             }
7035             if ( !phylogenies[ 10 ].isRooted() ) {
7036                 return false;
7037             }
7038             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7039                 return false;
7040             }
7041             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7042                 return false;
7043             }
7044             if ( phylogenies[ 11 ].isRooted() ) {
7045                 return false;
7046             }
7047             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7048                 return false;
7049             }
7050             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7051                 return false;
7052             }
7053             if ( !phylogenies[ 12 ].isRooted() ) {
7054                 return false;
7055             }
7056             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7057                 return false;
7058             }
7059             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7060                 return false;
7061             }
7062             if ( !phylogenies[ 13 ].isRooted() ) {
7063                 return false;
7064             }
7065             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7066                 return false;
7067             }
7068             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7069                 return false;
7070             }
7071             if ( !phylogenies[ 14 ].isRooted() ) {
7072                 return false;
7073             }
7074             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7075                 return false;
7076             }
7077             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7078                 return false;
7079             }
7080             if ( phylogenies[ 15 ].isRooted() ) {
7081                 return false;
7082             }
7083             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7084                 return false;
7085             }
7086             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7087                 return false;
7088             }
7089             if ( !phylogenies[ 16 ].isRooted() ) {
7090                 return false;
7091             }
7092             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7093                 return false;
7094             }
7095             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7096                 return false;
7097             }
7098             if ( phylogenies[ 17 ].isRooted() ) {
7099                 return false;
7100             }
7101             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7102                 return false;
7103             }
7104             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7105             phylogenies = null;
7106             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7107             if ( phylogenies.length != 9 ) {
7108                 return false;
7109             }
7110             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7111                     .getDistanceToParent() ) ) {
7112                 return false;
7113             }
7114             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7115                     .getDistanceToParent() ) ) {
7116                 return false;
7117             }
7118             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7119                 return false;
7120             }
7121             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7122                 return false;
7123             }
7124             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7125                 return false;
7126             }
7127             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7128                 return false;
7129             }
7130             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7131                 return false;
7132             }
7133         }
7134         catch ( final Exception e ) {
7135             e.printStackTrace( System.out );
7136             return false;
7137         }
7138         return true;
7139     }
7140
7141     private static boolean testNexusTreeParsingIterating() {
7142         try {
7143             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7144             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7145             if ( !p.hasNext() ) {
7146                 return false;
7147             }
7148             Phylogeny phy = p.next();
7149             if ( phy == null ) {
7150                 return false;
7151             }
7152             if ( phy.getNumberOfExternalNodes() != 25 ) {
7153                 return false;
7154             }
7155             if ( !phy.getName().equals( "" ) ) {
7156                 return false;
7157             }
7158             if ( p.hasNext() ) {
7159                 return false;
7160             }
7161             phy = p.next();
7162             if ( phy != null ) {
7163                 return false;
7164             }
7165             //
7166             p.reset();
7167             if ( !p.hasNext() ) {
7168                 return false;
7169             }
7170             phy = p.next();
7171             if ( phy == null ) {
7172                 return false;
7173             }
7174             if ( phy.getNumberOfExternalNodes() != 25 ) {
7175                 return false;
7176             }
7177             if ( !phy.getName().equals( "" ) ) {
7178                 return false;
7179             }
7180             if ( p.hasNext() ) {
7181                 return false;
7182             }
7183             phy = p.next();
7184             if ( phy != null ) {
7185                 return false;
7186             }
7187             ////
7188             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7189             if ( !p.hasNext() ) {
7190                 return false;
7191             }
7192             phy = p.next();
7193             if ( phy == null ) {
7194                 return false;
7195             }
7196             if ( phy.getNumberOfExternalNodes() != 10 ) {
7197                 return false;
7198             }
7199             if ( !phy.getName().equals( "name" ) ) {
7200                 return false;
7201             }
7202             if ( p.hasNext() ) {
7203                 return false;
7204             }
7205             phy = p.next();
7206             if ( phy != null ) {
7207                 return false;
7208             }
7209             //
7210             p.reset();
7211             if ( !p.hasNext() ) {
7212                 return false;
7213             }
7214             phy = p.next();
7215             if ( phy == null ) {
7216                 return false;
7217             }
7218             if ( phy.getNumberOfExternalNodes() != 10 ) {
7219                 return false;
7220             }
7221             if ( !phy.getName().equals( "name" ) ) {
7222                 return false;
7223             }
7224             if ( p.hasNext() ) {
7225                 return false;
7226             }
7227             phy = p.next();
7228             if ( phy != null ) {
7229                 return false;
7230             }
7231             //
7232             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7233             if ( !p.hasNext() ) {
7234                 return false;
7235             }
7236             phy = p.next();
7237             if ( phy == null ) {
7238                 return false;
7239             }
7240             if ( phy.getNumberOfExternalNodes() != 3 ) {
7241                 return false;
7242             }
7243             if ( !phy.getName().equals( "" ) ) {
7244                 return false;
7245             }
7246             if ( phy.isRooted() ) {
7247                 return false;
7248             }
7249             if ( p.hasNext() ) {
7250                 return false;
7251             }
7252             phy = p.next();
7253             if ( phy != null ) {
7254                 return false;
7255             }
7256             //
7257             p.reset();
7258             if ( !p.hasNext() ) {
7259                 return false;
7260             }
7261             phy = p.next();
7262             if ( phy == null ) {
7263                 return false;
7264             }
7265             if ( phy.getNumberOfExternalNodes() != 3 ) {
7266                 return false;
7267             }
7268             if ( !phy.getName().equals( "" ) ) {
7269                 return false;
7270             }
7271             if ( p.hasNext() ) {
7272                 return false;
7273             }
7274             phy = p.next();
7275             if ( phy != null ) {
7276                 return false;
7277             }
7278             //
7279             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7280             if ( !p.hasNext() ) {
7281                 return false;
7282             }
7283             //0
7284             phy = p.next();
7285             if ( phy == null ) {
7286                 return false;
7287             }
7288             if ( phy.getNumberOfExternalNodes() != 10 ) {
7289                 return false;
7290             }
7291             if ( !phy.getName().equals( "tree 0" ) ) {
7292                 return false;
7293             }
7294             //1
7295             if ( !p.hasNext() ) {
7296                 return false;
7297             }
7298             phy = p.next();
7299             if ( phy == null ) {
7300                 return false;
7301             }
7302             if ( phy.getNumberOfExternalNodes() != 10 ) {
7303                 return false;
7304             }
7305             if ( !phy.getName().equals( "tree 1" ) ) {
7306                 return false;
7307             }
7308             //2
7309             if ( !p.hasNext() ) {
7310                 return false;
7311             }
7312             phy = p.next();
7313             if ( phy == null ) {
7314                 return false;
7315             }
7316             if ( phy.getNumberOfExternalNodes() != 3 ) {
7317                 System.out.println( phy.toString() );
7318                 return false;
7319             }
7320             if ( !phy.getName().equals( "" ) ) {
7321                 return false;
7322             }
7323             if ( phy.isRooted() ) {
7324                 return false;
7325             }
7326             //3
7327             if ( !p.hasNext() ) {
7328                 return false;
7329             }
7330             phy = p.next();
7331             if ( phy == null ) {
7332                 return false;
7333             }
7334             if ( phy.getNumberOfExternalNodes() != 4 ) {
7335                 return false;
7336             }
7337             if ( !phy.getName().equals( "" ) ) {
7338                 return false;
7339             }
7340             if ( !phy.isRooted() ) {
7341                 return false;
7342             }
7343             //4
7344             if ( !p.hasNext() ) {
7345                 return false;
7346             }
7347             phy = p.next();
7348             if ( phy == null ) {
7349                 return false;
7350             }
7351             if ( phy.getNumberOfExternalNodes() != 5 ) {
7352                 System.out.println( phy.getNumberOfExternalNodes() );
7353                 return false;
7354             }
7355             if ( !phy.getName().equals( "" ) ) {
7356                 return false;
7357             }
7358             if ( !phy.isRooted() ) {
7359                 return false;
7360             }
7361             //5
7362             if ( !p.hasNext() ) {
7363                 return false;
7364             }
7365             phy = p.next();
7366             if ( phy == null ) {
7367                 return false;
7368             }
7369             if ( phy.getNumberOfExternalNodes() != 3 ) {
7370                 return false;
7371             }
7372             if ( !phy.getName().equals( "" ) ) {
7373                 return false;
7374             }
7375             if ( phy.isRooted() ) {
7376                 return false;
7377             }
7378             //6
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             phy = p.next();
7383             if ( phy == null ) {
7384                 return false;
7385             }
7386             if ( phy.getNumberOfExternalNodes() != 2 ) {
7387                 return false;
7388             }
7389             if ( !phy.getName().equals( "" ) ) {
7390                 return false;
7391             }
7392             if ( !phy.isRooted() ) {
7393                 return false;
7394             }
7395             //7
7396             if ( !p.hasNext() ) {
7397                 return false;
7398             }
7399             phy = p.next();
7400             if ( phy.getNumberOfExternalNodes() != 3 ) {
7401                 return false;
7402             }
7403             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7404                 return false;
7405             }
7406             if ( !phy.isRooted() ) {
7407                 return false;
7408             }
7409             //8
7410             if ( !p.hasNext() ) {
7411                 return false;
7412             }
7413             phy = p.next();
7414             if ( phy.getNumberOfExternalNodes() != 3 ) {
7415                 return false;
7416             }
7417             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7418                 return false;
7419             }
7420             if ( !phy.getName().equals( "tree 8" ) ) {
7421                 return false;
7422             }
7423             //9
7424             if ( !p.hasNext() ) {
7425                 return false;
7426             }
7427             phy = p.next();
7428             if ( phy.getNumberOfExternalNodes() != 3 ) {
7429                 return false;
7430             }
7431             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7432                 return false;
7433             }
7434             if ( !phy.getName().equals( "tree 9" ) ) {
7435                 return false;
7436             }
7437             //10
7438             if ( !p.hasNext() ) {
7439                 return false;
7440             }
7441             phy = p.next();
7442             if ( phy.getNumberOfExternalNodes() != 3 ) {
7443                 return false;
7444             }
7445             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7446                 return false;
7447             }
7448             if ( !phy.getName().equals( "tree 10" ) ) {
7449                 return false;
7450             }
7451             if ( !phy.isRooted() ) {
7452                 return false;
7453             }
7454             //11
7455             if ( !p.hasNext() ) {
7456                 return false;
7457             }
7458             phy = p.next();
7459             if ( phy.getNumberOfExternalNodes() != 3 ) {
7460                 return false;
7461             }
7462             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7463                 return false;
7464             }
7465             if ( !phy.getName().equals( "tree 11" ) ) {
7466                 return false;
7467             }
7468             if ( phy.isRooted() ) {
7469                 return false;
7470             }
7471             //12
7472             if ( !p.hasNext() ) {
7473                 return false;
7474             }
7475             phy = p.next();
7476             if ( phy.getNumberOfExternalNodes() != 3 ) {
7477                 return false;
7478             }
7479             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7480                 return false;
7481             }
7482             if ( !phy.getName().equals( "tree 12" ) ) {
7483                 return false;
7484             }
7485             if ( !phy.isRooted() ) {
7486                 return false;
7487             }
7488             //13
7489             if ( !p.hasNext() ) {
7490                 return false;
7491             }
7492             phy = p.next();
7493             if ( phy.getNumberOfExternalNodes() != 3 ) {
7494                 return false;
7495             }
7496             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7497                 return false;
7498             }
7499             if ( !phy.getName().equals( "tree 13" ) ) {
7500                 return false;
7501             }
7502             if ( !phy.isRooted() ) {
7503                 return false;
7504             }
7505             //14
7506             if ( !p.hasNext() ) {
7507                 return false;
7508             }
7509             phy = p.next();
7510             if ( phy.getNumberOfExternalNodes() != 10 ) {
7511                 System.out.println( phy.getNumberOfExternalNodes() );
7512                 return false;
7513             }
7514             if ( !phy
7515                     .toNewHampshire()
7516                     .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;" ) ) {
7517                 System.out.println( phy.toNewHampshire() );
7518                 return false;
7519             }
7520             if ( !phy.getName().equals( "tree 14" ) ) {
7521                 return false;
7522             }
7523             if ( !phy.isRooted() ) {
7524                 return false;
7525             }
7526             //15
7527             if ( !p.hasNext() ) {
7528                 return false;
7529             }
7530             phy = p.next();
7531             if ( phy.getNumberOfExternalNodes() != 10 ) {
7532                 System.out.println( phy.getNumberOfExternalNodes() );
7533                 return false;
7534             }
7535             if ( !phy
7536                     .toNewHampshire()
7537                     .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;" ) ) {
7538                 System.out.println( phy.toNewHampshire() );
7539                 return false;
7540             }
7541             if ( !phy.getName().equals( "tree 15" ) ) {
7542                 return false;
7543             }
7544             if ( phy.isRooted() ) {
7545                 return false;
7546             }
7547             //16
7548             if ( !p.hasNext() ) {
7549                 return false;
7550             }
7551             phy = p.next();
7552             if ( phy.getNumberOfExternalNodes() != 10 ) {
7553                 System.out.println( phy.getNumberOfExternalNodes() );
7554                 return false;
7555             }
7556             if ( !phy
7557                     .toNewHampshire()
7558                     .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;" ) ) {
7559                 System.out.println( phy.toNewHampshire() );
7560                 return false;
7561             }
7562             if ( !phy.getName().equals( "tree 16" ) ) {
7563                 return false;
7564             }
7565             if ( !phy.isRooted() ) {
7566                 return false;
7567             }
7568             //17
7569             if ( !p.hasNext() ) {
7570                 return false;
7571             }
7572             phy = p.next();
7573             if ( phy.getNumberOfExternalNodes() != 10 ) {
7574                 System.out.println( phy.getNumberOfExternalNodes() );
7575                 return false;
7576             }
7577             if ( !phy
7578                     .toNewHampshire()
7579                     .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;" ) ) {
7580                 System.out.println( phy.toNewHampshire() );
7581                 return false;
7582             }
7583             if ( !phy.getName().equals( "tree 17" ) ) {
7584                 return false;
7585             }
7586             if ( phy.isRooted() ) {
7587                 return false;
7588             }
7589             //
7590             if ( p.hasNext() ) {
7591                 return false;
7592             }
7593             phy = p.next();
7594             if ( phy != null ) {
7595                 return false;
7596             }
7597             p.reset();
7598             //0
7599             if ( !p.hasNext() ) {
7600                 return false;
7601             }
7602             phy = p.next();
7603             if ( phy == null ) {
7604                 return false;
7605             }
7606             if ( phy.getNumberOfExternalNodes() != 10 ) {
7607                 return false;
7608             }
7609             if ( !phy.getName().equals( "tree 0" ) ) {
7610                 return false;
7611             }
7612             //1
7613             if ( !p.hasNext() ) {
7614                 return false;
7615             }
7616             phy = p.next();
7617             if ( phy == null ) {
7618                 return false;
7619             }
7620             if ( phy.getNumberOfExternalNodes() != 10 ) {
7621                 return false;
7622             }
7623             if ( !phy.getName().equals( "tree 1" ) ) {
7624                 return false;
7625             }
7626             //2
7627             if ( !p.hasNext() ) {
7628                 return false;
7629             }
7630             phy = p.next();
7631             if ( phy == null ) {
7632                 return false;
7633             }
7634             if ( phy.getNumberOfExternalNodes() != 3 ) {
7635                 return false;
7636             }
7637             if ( !phy.getName().equals( "" ) ) {
7638                 return false;
7639             }
7640             if ( phy.isRooted() ) {
7641                 return false;
7642             }
7643             //3
7644             if ( !p.hasNext() ) {
7645                 return false;
7646             }
7647             phy = p.next();
7648             if ( phy == null ) {
7649                 return false;
7650             }
7651             if ( phy.getNumberOfExternalNodes() != 4 ) {
7652                 return false;
7653             }
7654             if ( !phy.getName().equals( "" ) ) {
7655                 return false;
7656             }
7657             if ( !phy.isRooted() ) {
7658                 return false;
7659             }
7660             //4
7661             if ( !p.hasNext() ) {
7662                 return false;
7663             }
7664             phy = p.next();
7665             if ( phy == null ) {
7666                 return false;
7667             }
7668             if ( phy.getNumberOfExternalNodes() != 5 ) {
7669                 System.out.println( phy.getNumberOfExternalNodes() );
7670                 return false;
7671             }
7672             if ( !phy.getName().equals( "" ) ) {
7673                 return false;
7674             }
7675             if ( !phy.isRooted() ) {
7676                 return false;
7677             }
7678             //5
7679             if ( !p.hasNext() ) {
7680                 return false;
7681             }
7682             phy = p.next();
7683             if ( phy == null ) {
7684                 return false;
7685             }
7686             if ( phy.getNumberOfExternalNodes() != 3 ) {
7687                 return false;
7688             }
7689             if ( !phy.getName().equals( "" ) ) {
7690                 return false;
7691             }
7692             if ( phy.isRooted() ) {
7693                 return false;
7694             }
7695             //
7696             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7697             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7698             // 0
7699             if ( !p2.hasNext() ) {
7700                 return false;
7701             }
7702             phy = p2.next();
7703             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7704                 return false;
7705             }
7706             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7707                 return false;
7708             }
7709             // 1
7710             if ( !p2.hasNext() ) {
7711                 return false;
7712             }
7713             phy = p2.next();
7714             // 2
7715             if ( !p2.hasNext() ) {
7716                 return false;
7717             }
7718             phy = p2.next();
7719             // 3
7720             if ( !p2.hasNext() ) {
7721                 return false;
7722             }
7723             phy = p2.next();
7724             // 4
7725             if ( !p2.hasNext() ) {
7726                 return false;
7727             }
7728             phy = p2.next();
7729             // 5
7730             if ( !p2.hasNext() ) {
7731                 return false;
7732             }
7733             phy = p2.next();
7734             // 6
7735             if ( !p2.hasNext() ) {
7736                 return false;
7737             }
7738             phy = p2.next();
7739             // 7
7740             if ( !p2.hasNext() ) {
7741                 return false;
7742             }
7743             phy = p2.next();
7744             // 8
7745             if ( !p2.hasNext() ) {
7746                 return false;
7747             }
7748             phy = p2.next();
7749             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7750                 return false;
7751             }
7752             if ( p2.hasNext() ) {
7753                 return false;
7754             }
7755             phy = p2.next();
7756             if ( phy != null ) {
7757                 return false;
7758             }
7759             // 0
7760             p2.reset();
7761             if ( !p2.hasNext() ) {
7762                 return false;
7763             }
7764             phy = p2.next();
7765             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7766                 return false;
7767             }
7768             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7769                 return false;
7770             }
7771         }
7772         catch ( final Exception e ) {
7773             e.printStackTrace( System.out );
7774             return false;
7775         }
7776         return true;
7777     }
7778
7779     private static boolean testNexusTreeParsingTranslating() {
7780         try {
7781             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7782             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7783             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7784             if ( phylogenies.length != 1 ) {
7785                 return false;
7786             }
7787             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7788                 return false;
7789             }
7790             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7791                 return false;
7792             }
7793             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7794                 return false;
7795             }
7796             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7797                 return false;
7798             }
7799             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7800                     .equals( "Aranaeus" ) ) {
7801                 return false;
7802             }
7803             phylogenies = null;
7804             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7805             if ( phylogenies.length != 3 ) {
7806                 return false;
7807             }
7808             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7809                 return false;
7810             }
7811             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7812                 return false;
7813             }
7814             if ( phylogenies[ 0 ].isRooted() ) {
7815                 return false;
7816             }
7817             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7818                 return false;
7819             }
7820             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7821                 return false;
7822             }
7823             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7824                     .equals( "Aranaeus" ) ) {
7825                 return false;
7826             }
7827             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7828                 return false;
7829             }
7830             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7831                 return false;
7832             }
7833             if ( phylogenies[ 1 ].isRooted() ) {
7834                 return false;
7835             }
7836             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7837                 return false;
7838             }
7839             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7840                 return false;
7841             }
7842             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7843                     .equals( "Aranaeus" ) ) {
7844                 return false;
7845             }
7846             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7847                 return false;
7848             }
7849             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7850                 return false;
7851             }
7852             if ( !phylogenies[ 2 ].isRooted() ) {
7853                 return false;
7854             }
7855             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7856                 return false;
7857             }
7858             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7859                 return false;
7860             }
7861             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7862                     .equals( "Aranaeus" ) ) {
7863                 return false;
7864             }
7865             phylogenies = null;
7866             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7867             if ( phylogenies.length != 3 ) {
7868                 return false;
7869             }
7870             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7871                 return false;
7872             }
7873             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7874                 return false;
7875             }
7876             if ( phylogenies[ 0 ].isRooted() ) {
7877                 return false;
7878             }
7879             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7880                 return false;
7881             }
7882             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7883                 return false;
7884             }
7885             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7886                     .equals( "Aranaeus" ) ) {
7887                 return false;
7888             }
7889             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7890                 return false;
7891             }
7892             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7893                 return false;
7894             }
7895             if ( phylogenies[ 1 ].isRooted() ) {
7896                 return false;
7897             }
7898             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7899                 return false;
7900             }
7901             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7902                 return false;
7903             }
7904             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7905                     .equals( "Aranaeus" ) ) {
7906                 return false;
7907             }
7908             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7909                 return false;
7910             }
7911             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7912                 return false;
7913             }
7914             if ( !phylogenies[ 2 ].isRooted() ) {
7915                 return false;
7916             }
7917             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7918                 return false;
7919             }
7920             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7921                 return false;
7922             }
7923             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7924                     .equals( "Aranaeus" ) ) {
7925                 return false;
7926             }
7927             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7928             if ( phylogenies.length != 3 ) {
7929                 return false;
7930             }
7931             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7932                            0.00100049 ) ) {
7933                 return false;
7934             }
7935         }
7936         catch ( final Exception e ) {
7937             e.printStackTrace( System.out );
7938             return false;
7939         }
7940         return true;
7941     }
7942
7943     private static boolean testNHParsing() {
7944         try {
7945             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7946             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7947             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7948                 return false;
7949             }
7950             final NHXParser nhxp = new NHXParser();
7951             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7952             nhxp.setReplaceUnderscores( true );
7953             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7954             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7955                 return false;
7956             }
7957             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7958                 return false;
7959             }
7960             final Phylogeny p1b = factory
7961                     .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 ",
7962                              new NHXParser() )[ 0 ];
7963             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7964                 return false;
7965             }
7966             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7967                 return false;
7968             }
7969             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7970             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7971             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7972             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7973             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7974             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7975             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7976             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7977             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7978             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7979             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7980                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7981                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7982                                                     new NHXParser() );
7983             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7984                 return false;
7985             }
7986             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7987                 return false;
7988             }
7989             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7990                 return false;
7991             }
7992             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7993                 return false;
7994             }
7995             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7996             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7997             final String p16_S = "((A,B),C)";
7998             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7999             if ( p16.length != 1 ) {
8000                 return false;
8001             }
8002             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8003                 return false;
8004             }
8005             final String p17_S = "(C,(A,B))";
8006             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8007             if ( p17.length != 1 ) {
8008                 return false;
8009             }
8010             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8011                 return false;
8012             }
8013             final String p18_S = "((A,B),(C,D))";
8014             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8015             if ( p18.length != 1 ) {
8016                 return false;
8017             }
8018             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8019                 return false;
8020             }
8021             final String p19_S = "(((A,B),C),D)";
8022             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8023             if ( p19.length != 1 ) {
8024                 return false;
8025             }
8026             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8027                 return false;
8028             }
8029             final String p20_S = "(A,(B,(C,D)))";
8030             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8031             if ( p20.length != 1 ) {
8032                 return false;
8033             }
8034             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8035                 return false;
8036             }
8037             final String p21_S = "(A,(B,(C,(D,E))))";
8038             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8039             if ( p21.length != 1 ) {
8040                 return false;
8041             }
8042             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8043                 return false;
8044             }
8045             final String p22_S = "((((A,B),C),D),E)";
8046             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8047             if ( p22.length != 1 ) {
8048                 return false;
8049             }
8050             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8051                 return false;
8052             }
8053             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8054             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8055             if ( p23.length != 1 ) {
8056                 System.out.println( "xl=" + p23.length );
8057                 System.exit( -1 );
8058                 return false;
8059             }
8060             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8061                 return false;
8062             }
8063             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8064             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8065             if ( p24.length != 1 ) {
8066                 return false;
8067             }
8068             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8069                 return false;
8070             }
8071             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8072             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8073             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8074             if ( p241.length != 2 ) {
8075                 return false;
8076             }
8077             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8078                 return false;
8079             }
8080             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8081                 return false;
8082             }
8083             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8084                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8085                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8086                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8087                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8088                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8089                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8090                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8091             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8092             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8093                 return false;
8094             }
8095             final String p26_S = "(A,B)ab";
8096             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8097             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8098                 return false;
8099             }
8100             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8101             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8102             if ( p27s.length != 1 ) {
8103                 System.out.println( "xxl=" + p27s.length );
8104                 System.exit( -1 );
8105                 return false;
8106             }
8107             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8108                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8109                 System.exit( -1 );
8110                 return false;
8111             }
8112             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8113                                                     new NHXParser() );
8114             if ( p27.length != 1 ) {
8115                 System.out.println( "yl=" + p27.length );
8116                 System.exit( -1 );
8117                 return false;
8118             }
8119             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8120                 System.out.println( p27[ 0 ].toNewHampshireX() );
8121                 System.exit( -1 );
8122                 return false;
8123             }
8124             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8125             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8126             final String p28_S3 = "(A,B)ab";
8127             final String p28_S4 = "((((A,B),C),D),;E;)";
8128             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8129                                                     new NHXParser() );
8130             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8131                 return false;
8132             }
8133             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8134                 return false;
8135             }
8136             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8137                 return false;
8138             }
8139             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8140                 return false;
8141             }
8142             if ( p28.length != 4 ) {
8143                 return false;
8144             }
8145             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";
8146             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8147             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8148                 return false;
8149             }
8150             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";
8151             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8152             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8153                 return false;
8154             }
8155             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8156             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8157             if ( ( p32.length != 0 ) ) {
8158                 return false;
8159             }
8160             final String p33_S = "A";
8161             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8162             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8163                 return false;
8164             }
8165             final String p34_S = "B;";
8166             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8167             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8168                 return false;
8169             }
8170             final String p35_S = "B:0.2";
8171             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8172             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8173                 return false;
8174             }
8175             final String p36_S = "(A)";
8176             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8177             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8178                 return false;
8179             }
8180             final String p37_S = "((A))";
8181             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8182             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8183                 return false;
8184             }
8185             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8186             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8187             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8188                 return false;
8189             }
8190             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8191             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8192             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8193                 return false;
8194             }
8195             final String p40_S = "(A,B,C)";
8196             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8197             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8198                 return false;
8199             }
8200             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8201             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8202             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8203                 return false;
8204             }
8205             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8206             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8207             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8208                 return false;
8209             }
8210             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)";
8211             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8212             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8213                 return false;
8214             }
8215             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)))";
8216             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8217             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8218                 return false;
8219             }
8220             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8221             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8222             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8223                 return false;
8224             }
8225             final String p46_S = "";
8226             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8227             if ( p46.length != 0 ) {
8228                 return false;
8229             }
8230             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8231             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8232                 return false;
8233             }
8234             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8235             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8236                 return false;
8237             }
8238             final Phylogeny p49 = factory
8239                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8240                              new NHXParser() )[ 0 ];
8241             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8242                 return false;
8243             }
8244             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8245             if ( p50.getNode( "A" ) == null ) {
8246                 return false;
8247             }
8248             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8249                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8250                 return false;
8251             }
8252             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8253                 return false;
8254             }
8255             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8256                     .equals( "((A,B)88:2.0,C);" ) ) {
8257                 return false;
8258             }
8259             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8260             if ( p51.getNode( "A(A" ) == null ) {
8261                 return false;
8262             }
8263             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8264             if ( p52.getNode( "A(A" ) == null ) {
8265                 return false;
8266             }
8267             final Phylogeny p53 = factory
8268                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8269                              new NHXParser() )[ 0 ];
8270             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8271                 return false;
8272             }
8273             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8274             if ( p54.getNode( "A" ) == null ) {
8275                 return false;
8276             }
8277             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8278                 return false;
8279             }
8280             final Phylogeny p55 = factory
8281                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1  s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1x\":0.0798012);" ),
8282                              new NHXParser() )[ 0 ];
8283             if ( !p55
8284                     .toNewHampshire()
8285                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,lcl|HPV66_L1.1x:0.0798012);" ) ) {
8286                 System.out.println( p55.toNewHampshire() );
8287                 return false;
8288             }
8289             final Phylogeny p56 = factory
8290                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8291                              new NHXParser() )[ 0 ];
8292             if ( !p56
8293                     .toNewHampshire()
8294                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8295                 System.out.println( p56.toNewHampshire() );
8296                 return false;
8297             }
8298             final Phylogeny p57 = factory
8299                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8300                              new NHXParser() )[ 0 ];
8301             if ( !p57
8302                     .toNewHampshire()
8303                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8304                 System.out.println( p56.toNewHampshire() );
8305                 return false;
8306             }
8307             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8308             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8309             if ( !p58.toNewHampshire().equals( s58 ) ) {
8310                 System.out.println( p58.toNewHampshire() );
8311                 return false;
8312             }
8313             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8314             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8315             if ( !p59.toNewHampshire().equals( s59 ) ) {
8316                 System.out.println( p59.toNewHampshire() );
8317                 return false;
8318             }
8319             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8320             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8321             if ( !p60.toNewHampshire().equals( s60 ) ) {
8322                 System.out.println( p60.toNewHampshire() );
8323                 return false;
8324             }
8325             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8326             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8327             if ( !p61.toNewHampshire()
8328                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8329                 System.out.println( p61.toNewHampshire() );
8330                 return false;
8331             }
8332         }
8333         catch ( final Exception e ) {
8334             e.printStackTrace( System.out );
8335             return false;
8336         }
8337         return true;
8338     }
8339
8340     private static boolean testNHParsingIter() {
8341         try {
8342             final String p0_str = "(A,B);";
8343             final NHXParser p = new NHXParser();
8344             p.setSource( p0_str );
8345             if ( !p.hasNext() ) {
8346                 return false;
8347             }
8348             final Phylogeny p0 = p.next();
8349             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8350                 System.out.println( p0.toNewHampshire() );
8351                 return false;
8352             }
8353             if ( p.hasNext() ) {
8354                 return false;
8355             }
8356             if ( p.next() != null ) {
8357                 return false;
8358             }
8359             //
8360             final String p00_str = "(A,B)root;";
8361             p.setSource( p00_str );
8362             final Phylogeny p00 = p.next();
8363             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8364                 System.out.println( p00.toNewHampshire() );
8365                 return false;
8366             }
8367             //
8368             final String p000_str = "A;";
8369             p.setSource( p000_str );
8370             final Phylogeny p000 = p.next();
8371             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8372                 System.out.println( p000.toNewHampshire() );
8373                 return false;
8374             }
8375             //
8376             final String p0000_str = "A";
8377             p.setSource( p0000_str );
8378             final Phylogeny p0000 = p.next();
8379             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8380                 System.out.println( p0000.toNewHampshire() );
8381                 return false;
8382             }
8383             //
8384             p.setSource( "(A)" );
8385             final Phylogeny p00000 = p.next();
8386             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8387                 System.out.println( p00000.toNewHampshire() );
8388                 return false;
8389             }
8390             //
8391             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8392             p.setSource( p1_str );
8393             if ( !p.hasNext() ) {
8394                 return false;
8395             }
8396             final Phylogeny p1_0 = p.next();
8397             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8398                 System.out.println( p1_0.toNewHampshire() );
8399                 return false;
8400             }
8401             if ( !p.hasNext() ) {
8402                 return false;
8403             }
8404             final Phylogeny p1_1 = p.next();
8405             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8406                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8407                 return false;
8408             }
8409             if ( !p.hasNext() ) {
8410                 return false;
8411             }
8412             final Phylogeny p1_2 = p.next();
8413             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8414                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8415                 return false;
8416             }
8417             if ( !p.hasNext() ) {
8418                 return false;
8419             }
8420             final Phylogeny p1_3 = p.next();
8421             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8422                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8423                 return false;
8424             }
8425             if ( p.hasNext() ) {
8426                 return false;
8427             }
8428             if ( p.next() != null ) {
8429                 return false;
8430             }
8431             //
8432             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8433             p.setSource( p2_str );
8434             if ( !p.hasNext() ) {
8435                 return false;
8436             }
8437             Phylogeny p2_0 = p.next();
8438             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8439                 System.out.println( p2_0.toNewHampshire() );
8440                 return false;
8441             }
8442             if ( !p.hasNext() ) {
8443                 return false;
8444             }
8445             Phylogeny p2_1 = p.next();
8446             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8447                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8448                 return false;
8449             }
8450             if ( !p.hasNext() ) {
8451                 return false;
8452             }
8453             Phylogeny p2_2 = p.next();
8454             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8455                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8456                 return false;
8457             }
8458             if ( !p.hasNext() ) {
8459                 return false;
8460             }
8461             Phylogeny p2_3 = p.next();
8462             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8463                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8464                 return false;
8465             }
8466             if ( !p.hasNext() ) {
8467                 return false;
8468             }
8469             Phylogeny p2_4 = p.next();
8470             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8471                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8472                 return false;
8473             }
8474             if ( p.hasNext() ) {
8475                 return false;
8476             }
8477             if ( p.next() != null ) {
8478                 return false;
8479             }
8480             ////
8481             p.reset();
8482             if ( !p.hasNext() ) {
8483                 return false;
8484             }
8485             p2_0 = p.next();
8486             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8487                 System.out.println( p2_0.toNewHampshire() );
8488                 return false;
8489             }
8490             if ( !p.hasNext() ) {
8491                 return false;
8492             }
8493             p2_1 = p.next();
8494             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8495                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8496                 return false;
8497             }
8498             if ( !p.hasNext() ) {
8499                 return false;
8500             }
8501             p2_2 = p.next();
8502             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8503                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8504                 return false;
8505             }
8506             if ( !p.hasNext() ) {
8507                 return false;
8508             }
8509             p2_3 = p.next();
8510             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8511                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8512                 return false;
8513             }
8514             if ( !p.hasNext() ) {
8515                 return false;
8516             }
8517             p2_4 = p.next();
8518             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8519                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8520                 return false;
8521             }
8522             if ( p.hasNext() ) {
8523                 return false;
8524             }
8525             if ( p.next() != null ) {
8526                 return false;
8527             }
8528             //
8529             final String p3_str = "((A,B),C)abc";
8530             p.setSource( p3_str );
8531             if ( !p.hasNext() ) {
8532                 return false;
8533             }
8534             final Phylogeny p3_0 = p.next();
8535             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8536                 return false;
8537             }
8538             if ( p.hasNext() ) {
8539                 return false;
8540             }
8541             if ( p.next() != null ) {
8542                 return false;
8543             }
8544             //
8545             final String p4_str = "((A,B)ab,C)abc";
8546             p.setSource( p4_str );
8547             if ( !p.hasNext() ) {
8548                 return false;
8549             }
8550             final Phylogeny p4_0 = p.next();
8551             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8552                 return false;
8553             }
8554             if ( p.hasNext() ) {
8555                 return false;
8556             }
8557             if ( p.next() != null ) {
8558                 return false;
8559             }
8560             //
8561             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8562             p.setSource( p5_str );
8563             if ( !p.hasNext() ) {
8564                 return false;
8565             }
8566             final Phylogeny p5_0 = p.next();
8567             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8568                 return false;
8569             }
8570             if ( p.hasNext() ) {
8571                 return false;
8572             }
8573             if ( p.next() != null ) {
8574                 return false;
8575             }
8576             //
8577             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8578             p.setSource( p6_str );
8579             if ( !p.hasNext() ) {
8580                 return false;
8581             }
8582             Phylogeny p6_0 = p.next();
8583             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8584                 return false;
8585             }
8586             if ( p.hasNext() ) {
8587                 return false;
8588             }
8589             if ( p.next() != null ) {
8590                 return false;
8591             }
8592             p.reset();
8593             if ( !p.hasNext() ) {
8594                 return false;
8595             }
8596             p6_0 = p.next();
8597             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8598                 return false;
8599             }
8600             if ( p.hasNext() ) {
8601                 return false;
8602             }
8603             if ( p.next() != null ) {
8604                 return false;
8605             }
8606             //
8607             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8608             p.setSource( p7_str );
8609             if ( !p.hasNext() ) {
8610                 return false;
8611             }
8612             Phylogeny p7_0 = p.next();
8613             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8614                 return false;
8615             }
8616             if ( p.hasNext() ) {
8617                 return false;
8618             }
8619             if ( p.next() != null ) {
8620                 return false;
8621             }
8622             p.reset();
8623             if ( !p.hasNext() ) {
8624                 return false;
8625             }
8626             p7_0 = p.next();
8627             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8628                 return false;
8629             }
8630             if ( p.hasNext() ) {
8631                 return false;
8632             }
8633             if ( p.next() != null ) {
8634                 return false;
8635             }
8636             //
8637             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8638             p.setSource( p8_str );
8639             if ( !p.hasNext() ) {
8640                 return false;
8641             }
8642             Phylogeny p8_0 = p.next();
8643             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8644                 return false;
8645             }
8646             if ( !p.hasNext() ) {
8647                 return false;
8648             }
8649             if ( !p.hasNext() ) {
8650                 return false;
8651             }
8652             Phylogeny p8_1 = p.next();
8653             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8654                 return false;
8655             }
8656             if ( p.hasNext() ) {
8657                 return false;
8658             }
8659             if ( p.next() != null ) {
8660                 return false;
8661             }
8662             p.reset();
8663             if ( !p.hasNext() ) {
8664                 return false;
8665             }
8666             p8_0 = p.next();
8667             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8668                 return false;
8669             }
8670             if ( !p.hasNext() ) {
8671                 return false;
8672             }
8673             p8_1 = p.next();
8674             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8675                 return false;
8676             }
8677             if ( p.hasNext() ) {
8678                 return false;
8679             }
8680             if ( p.next() != null ) {
8681                 return false;
8682             }
8683             p.reset();
8684             //
8685             p.setSource( "" );
8686             if ( p.hasNext() ) {
8687                 return false;
8688             }
8689             //
8690             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8691             if ( !p.hasNext() ) {
8692                 return false;
8693             }
8694             Phylogeny p_27 = p.next();
8695             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8696                 System.out.println( p_27.toNewHampshireX() );
8697                 System.exit( -1 );
8698                 return false;
8699             }
8700             if ( p.hasNext() ) {
8701                 return false;
8702             }
8703             if ( p.next() != null ) {
8704                 return false;
8705             }
8706             p.reset();
8707             if ( !p.hasNext() ) {
8708                 return false;
8709             }
8710             p_27 = p.next();
8711             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8712                 System.out.println( p_27.toNewHampshireX() );
8713                 System.exit( -1 );
8714                 return false;
8715             }
8716             if ( p.hasNext() ) {
8717                 return false;
8718             }
8719             if ( p.next() != null ) {
8720                 return false;
8721             }
8722             //
8723             final String p30_str = "(A,B);(C,D)";
8724             final NHXParser p30 = new NHXParser();
8725             p30.setSource( p30_str );
8726             if ( !p30.hasNext() ) {
8727                 return false;
8728             }
8729             Phylogeny phy30 = p30.next();
8730             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8731                 System.out.println( phy30.toNewHampshire() );
8732                 return false;
8733             }
8734             if ( !p30.hasNext() ) {
8735                 return false;
8736             }
8737             Phylogeny phy301 = p30.next();
8738             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8739                 System.out.println( phy301.toNewHampshire() );
8740                 return false;
8741             }
8742             if ( p30.hasNext() ) {
8743                 return false;
8744             }
8745             if ( p30.hasNext() ) {
8746                 return false;
8747             }
8748             if ( p30.next() != null ) {
8749                 return false;
8750             }
8751             if ( p30.next() != null ) {
8752                 return false;
8753             }
8754             p30.reset();
8755             if ( !p30.hasNext() ) {
8756                 return false;
8757             }
8758             phy30 = p30.next();
8759             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8760                 System.out.println( phy30.toNewHampshire() );
8761                 return false;
8762             }
8763             if ( !p30.hasNext() ) {
8764                 return false;
8765             }
8766             phy301 = p30.next();
8767             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8768                 System.out.println( phy301.toNewHampshire() );
8769                 return false;
8770             }
8771             if ( p30.hasNext() ) {
8772                 return false;
8773             }
8774             if ( p30.hasNext() ) {
8775                 return false;
8776             }
8777             if ( p30.next() != null ) {
8778                 return false;
8779             }
8780             if ( p30.next() != null ) {
8781                 return false;
8782             }
8783         }
8784         catch ( final Exception e ) {
8785             e.printStackTrace( System.out );
8786             return false;
8787         }
8788         return true;
8789     }
8790
8791     private static boolean testNHXconversion() {
8792         try {
8793             final PhylogenyNode n1 = new PhylogenyNode();
8794             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8795             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8796             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8797             final PhylogenyNode n5 = PhylogenyNode
8798                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8799             final PhylogenyNode n6 = PhylogenyNode
8800                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8801             if ( !n1.toNewHampshireX().equals( "" ) ) {
8802                 return false;
8803             }
8804             if ( !n2.toNewHampshireX().equals( "" ) ) {
8805                 return false;
8806             }
8807             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8808                 return false;
8809             }
8810             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8811                 return false;
8812             }
8813             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8814                 return false;
8815             }
8816             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8817                 System.out.println( n6.toNewHampshireX() );
8818                 return false;
8819             }
8820             final PhylogenyNode n7 = new PhylogenyNode();
8821             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8822             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8823                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8824                 System.out.println( n7
8825                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8826                 return false;
8827             }
8828         }
8829         catch ( final Exception e ) {
8830             e.printStackTrace( System.out );
8831             return false;
8832         }
8833         return true;
8834     }
8835
8836     private static boolean testNHXNodeParsing() {
8837         try {
8838             final PhylogenyNode n1 = new PhylogenyNode();
8839             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8840             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8841             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8842             final PhylogenyNode n5 = PhylogenyNode
8843                     .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]" );
8844             if ( !n3.getName().equals( "n3" ) ) {
8845                 return false;
8846             }
8847             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8848                 return false;
8849             }
8850             if ( n3.isDuplication() ) {
8851                 return false;
8852             }
8853             if ( n3.isHasAssignedEvent() ) {
8854                 return false;
8855             }
8856             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8857                 return false;
8858             }
8859             if ( !n4.getName().equals( "n4" ) ) {
8860                 return false;
8861             }
8862             if ( n4.getDistanceToParent() != 0.01 ) {
8863                 return false;
8864             }
8865             if ( !n5.getName().equals( "n5" ) ) {
8866                 return false;
8867             }
8868             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8869                 return false;
8870             }
8871             if ( n5.getDistanceToParent() != 0.1 ) {
8872                 return false;
8873             }
8874             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8875                 return false;
8876             }
8877             if ( !n5.isDuplication() ) {
8878                 return false;
8879             }
8880             if ( !n5.isHasAssignedEvent() ) {
8881                 return false;
8882             }
8883             final PhylogenyNode n8 = PhylogenyNode
8884                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8885                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8886             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8887                 return false;
8888             }
8889             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8890                 return false;
8891             }
8892             final PhylogenyNode n9 = PhylogenyNode
8893                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8894                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8895             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8896                 return false;
8897             }
8898             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8899                 return false;
8900             }
8901             final PhylogenyNode n10 = PhylogenyNode
8902                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8903             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8904                 return false;
8905             }
8906             final PhylogenyNode n20 = PhylogenyNode
8907                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8908             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8909                 return false;
8910             }
8911             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8912                 return false;
8913             }
8914             final PhylogenyNode n20x = PhylogenyNode
8915                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8916             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8917                 return false;
8918             }
8919             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8920                 return false;
8921             }
8922             final PhylogenyNode n20xx = PhylogenyNode
8923                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8924             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8925                 return false;
8926             }
8927             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8928                 return false;
8929             }
8930             final PhylogenyNode n20xxx = PhylogenyNode
8931                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8932             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8933                 return false;
8934             }
8935             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8936                 return false;
8937             }
8938             final PhylogenyNode n20xxxx = PhylogenyNode
8939                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8940             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8941                 return false;
8942             }
8943             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8944                 return false;
8945             }
8946             final PhylogenyNode n21 = PhylogenyNode
8947                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8948             if ( !n21.getName().equals( "N21_PIG" ) ) {
8949                 return false;
8950             }
8951             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8952                 return false;
8953             }
8954             final PhylogenyNode n21x = PhylogenyNode
8955                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8956             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8957                 return false;
8958             }
8959             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8960                 return false;
8961             }
8962             final PhylogenyNode n22 = PhylogenyNode
8963                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8964             if ( !n22.getName().equals( "n22/PIG" ) ) {
8965                 return false;
8966             }
8967             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8968                 return false;
8969             }
8970             final PhylogenyNode n23 = PhylogenyNode
8971                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8972             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8973                 return false;
8974             }
8975             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8976                 return false;
8977             }
8978             final PhylogenyNode a = PhylogenyNode
8979                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8980             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8981                 return false;
8982             }
8983             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8984                 return false;
8985             }
8986             final PhylogenyNode c1 = PhylogenyNode
8987                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8988                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8989             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8990                 return false;
8991             }
8992             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8993                 return false;
8994             }
8995             final PhylogenyNode c2 = PhylogenyNode
8996                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8997                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8998             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8999                 return false;
9000             }
9001             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9002                 return false;
9003             }
9004             final PhylogenyNode e3 = PhylogenyNode
9005                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9006             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9007                 return false;
9008             }
9009             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9010                 return false;
9011             }
9012             final PhylogenyNode n11 = PhylogenyNode
9013                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9014                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9015             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9016                 return false;
9017             }
9018             if ( n11.getDistanceToParent() != 0.4 ) {
9019                 return false;
9020             }
9021             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9022                 return false;
9023             }
9024             final PhylogenyNode n12 = PhylogenyNode
9025                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9026                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9027             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9028                 return false;
9029             }
9030             if ( n12.getDistanceToParent() != 0.4 ) {
9031                 return false;
9032             }
9033             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9034                 return false;
9035             }
9036             final PhylogenyNode o = PhylogenyNode
9037                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9038             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9039                 return false;
9040             }
9041             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9042                 return false;
9043             }
9044             if ( n1.getName().compareTo( "" ) != 0 ) {
9045                 return false;
9046             }
9047             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9048                 return false;
9049             }
9050             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9051                 return false;
9052             }
9053             if ( n2.getName().compareTo( "" ) != 0 ) {
9054                 return false;
9055             }
9056             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9057                 return false;
9058             }
9059             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9060                 return false;
9061             }
9062             final PhylogenyNode n00 = PhylogenyNode
9063                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9064             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9065                 return false;
9066             }
9067             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9068                 return false;
9069             }
9070             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9071             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9072                 return false;
9073             }
9074             final PhylogenyNode n13 = PhylogenyNode
9075                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9076             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9077                 return false;
9078             }
9079             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9080                 return false;
9081             }
9082             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9083                 return false;
9084             }
9085             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9086                 return false;
9087             }
9088             final PhylogenyNode n14 = PhylogenyNode
9089                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9090             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9091                 return false;
9092             }
9093             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9094                 return false;
9095             }
9096             final PhylogenyNode n15 = PhylogenyNode
9097                     .createInstanceFromNhxString( "something_wicked[123]",
9098                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9099             if ( !n15.getName().equals( "something_wicked" ) ) {
9100                 return false;
9101             }
9102             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9103                 return false;
9104             }
9105             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9106                 return false;
9107             }
9108             final PhylogenyNode n16 = PhylogenyNode
9109                     .createInstanceFromNhxString( "something_wicked2[9]",
9110                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9111             if ( !n16.getName().equals( "something_wicked2" ) ) {
9112                 return false;
9113             }
9114             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9115                 return false;
9116             }
9117             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9118                 return false;
9119             }
9120             final PhylogenyNode n17 = PhylogenyNode
9121                     .createInstanceFromNhxString( "something_wicked3[a]",
9122                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9123             if ( !n17.getName().equals( "something_wicked3" ) ) {
9124                 return false;
9125             }
9126             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9127                 return false;
9128             }
9129             final PhylogenyNode n18 = PhylogenyNode
9130                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9131             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9132                 return false;
9133             }
9134             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9135                 return false;
9136             }
9137             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9138                 return false;
9139             }
9140             final PhylogenyNode n19 = PhylogenyNode
9141                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9142             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9143                 return false;
9144             }
9145             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9146                 return false;
9147             }
9148             final PhylogenyNode n30 = PhylogenyNode
9149                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9150                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9151             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9152                 return false;
9153             }
9154             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9155                 return false;
9156             }
9157             final PhylogenyNode n31 = PhylogenyNode
9158                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9159                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9160             if ( n31.getNodeData().isHasTaxonomy() ) {
9161                 return false;
9162             }
9163             final PhylogenyNode n32 = PhylogenyNode
9164                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9165             if ( n32.getNodeData().isHasTaxonomy() ) {
9166                 return false;
9167             }
9168             final PhylogenyNode n40 = PhylogenyNode
9169                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9170             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9171                 return false;
9172             }
9173             final PhylogenyNode n41 = PhylogenyNode
9174                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9175             if ( n41.getNodeData().isHasTaxonomy() ) {
9176                 return false;
9177             }
9178             final PhylogenyNode n42 = PhylogenyNode
9179                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9180             if ( n42.getNodeData().isHasTaxonomy() ) {
9181                 return false;
9182             }
9183             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9184                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9185             if ( n43.getNodeData().isHasTaxonomy() ) {
9186                 return false;
9187             }
9188             final PhylogenyNode n44 = PhylogenyNode
9189                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9190             if ( n44.getNodeData().isHasTaxonomy() ) {
9191                 return false;
9192             }
9193         }
9194         catch ( final Exception e ) {
9195             e.printStackTrace( System.out );
9196             return false;
9197         }
9198         return true;
9199     }
9200
9201     private static boolean testNHXParsing() {
9202         try {
9203             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9204             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9205             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9206                 return false;
9207             }
9208             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]";
9209             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9210             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9211                 return false;
9212             }
9213             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]";
9214             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9215             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9216                 return false;
9217             }
9218             final Phylogeny[] p3 = factory
9219                     .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]",
9220                              new NHXParser() );
9221             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9222                 return false;
9223             }
9224             final Phylogeny[] p4 = factory
9225                     .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(]",
9226                              new NHXParser() );
9227             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9228                 return false;
9229             }
9230             final Phylogeny[] p5 = factory
9231                     .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(((]",
9232                              new NHXParser() );
9233             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9234                 return false;
9235             }
9236             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)";
9237             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)";
9238             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9239             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9240                 return false;
9241             }
9242             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)))";
9243             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)))";
9244             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9245             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9246                 return false;
9247             }
9248             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])   ))[,,, ])))))))";
9249             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9250             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9251             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9252                 return false;
9253             }
9254             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9255             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9256                 return false;
9257             }
9258             final Phylogeny p10 = factory
9259                     .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]",
9260                              new NHXParser() )[ 0 ];
9261             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9262                 return false;
9263             }
9264             final Phylogeny p11 = factory
9265                     .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]",
9266                              new NHXParser() )[ 0 ];
9267             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9268                 return false;
9269             }
9270         }
9271         catch ( final Exception e ) {
9272             e.printStackTrace( System.out );
9273             return false;
9274         }
9275         return true;
9276     }
9277
9278     private static boolean testNHXParsingMB() {
9279         try {
9280             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9281             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9282                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9283                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9284                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9285                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9286                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9287                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9288                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9289                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9290             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9291                 return false;
9292             }
9293             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9294                 return false;
9295             }
9296             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9297                            0.1100000000000000e+00 ) ) {
9298                 return false;
9299             }
9300             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9301                 return false;
9302             }
9303             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9304                 return false;
9305             }
9306             final Phylogeny p2 = factory
9307                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9308                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9309                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9310                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9311                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9312                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9313                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9314                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9315                                      + "7.369400000000000e-02}])",
9316                              new NHXParser() )[ 0 ];
9317             if ( p2.getNode( "1" ) == null ) {
9318                 return false;
9319             }
9320             if ( p2.getNode( "2" ) == null ) {
9321                 return false;
9322             }
9323         }
9324         catch ( final Exception e ) {
9325             e.printStackTrace( System.out );
9326             System.exit( -1 );
9327             return false;
9328         }
9329         return true;
9330     }
9331
9332     private static boolean testNHXParsingQuotes() {
9333         try {
9334             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9335             final NHXParser p = new NHXParser();
9336             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9337             if ( phylogenies_0.length != 5 ) {
9338                 return false;
9339             }
9340             final Phylogeny phy = phylogenies_0[ 4 ];
9341             if ( phy.getNumberOfExternalNodes() != 7 ) {
9342                 return false;
9343             }
9344             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9345                 return false;
9346             }
9347             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9348                 return false;
9349             }
9350             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9351                     .getScientificName().equals( "hsapiens" ) ) {
9352                 return false;
9353             }
9354             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9355                 return false;
9356             }
9357             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9358                 return false;
9359             }
9360             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9361                 return false;
9362             }
9363             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9364                 return false;
9365             }
9366             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9367                 return false;
9368             }
9369             final NHXParser p1p = new NHXParser();
9370             p1p.setIgnoreQuotes( true );
9371             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9372             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9373                 return false;
9374             }
9375             final NHXParser p2p = new NHXParser();
9376             p1p.setIgnoreQuotes( false );
9377             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9378             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9379                 return false;
9380             }
9381             final NHXParser p3p = new NHXParser();
9382             p3p.setIgnoreQuotes( false );
9383             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9384             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9385                 return false;
9386             }
9387             final NHXParser p4p = new NHXParser();
9388             p4p.setIgnoreQuotes( false );
9389             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9390             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9391                 return false;
9392             }
9393             final Phylogeny p10 = factory
9394                     .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]",
9395                              new NHXParser() )[ 0 ];
9396             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]";
9397             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9398                 return false;
9399             }
9400             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9401             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9402                 return false;
9403             }
9404             final Phylogeny p12 = factory
9405                     .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]",
9406                              new NHXParser() )[ 0 ];
9407             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]";
9408             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9409                 return false;
9410             }
9411             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9412             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9413                 return false;
9414             }
9415             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;";
9416             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9417                 return false;
9418             }
9419             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9420             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9421                 return false;
9422             }
9423         }
9424         catch ( final Exception e ) {
9425             e.printStackTrace( System.out );
9426             return false;
9427         }
9428         return true;
9429     }
9430
9431     private static boolean testNodeRemoval() {
9432         try {
9433             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9434             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9435             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9436             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9437                 return false;
9438             }
9439             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9440             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9441             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9442                 return false;
9443             }
9444             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9445             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9446             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9447                 return false;
9448             }
9449         }
9450         catch ( final Exception e ) {
9451             e.printStackTrace( System.out );
9452             return false;
9453         }
9454         return true;
9455     }
9456
9457     private static boolean testPhylogenyBranch() {
9458         try {
9459             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9460             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9461             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9462             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9463             if ( !a1b1.equals( a1b1 ) ) {
9464                 return false;
9465             }
9466             if ( !a1b1.equals( b1a1 ) ) {
9467                 return false;
9468             }
9469             if ( !b1a1.equals( a1b1 ) ) {
9470                 return false;
9471             }
9472             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9473             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9474             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9475             if ( a1_b1.equals( b1_a1 ) ) {
9476                 return false;
9477             }
9478             if ( a1_b1.equals( a1_b1_ ) ) {
9479                 return false;
9480             }
9481             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9482             if ( !a1_b1.equals( b1_a1_ ) ) {
9483                 return false;
9484             }
9485             if ( a1_b1_.equals( b1_a1_ ) ) {
9486                 return false;
9487             }
9488             if ( !a1_b1_.equals( b1_a1 ) ) {
9489                 return false;
9490             }
9491         }
9492         catch ( final Exception e ) {
9493             e.printStackTrace( System.out );
9494             return false;
9495         }
9496         return true;
9497     }
9498
9499     private static boolean testPhyloXMLparsingOfDistributionElement() {
9500         try {
9501             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9502             PhyloXmlParser xml_parser = null;
9503             try {
9504                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9505             }
9506             catch ( final Exception e ) {
9507                 // Do nothing -- means were not running from jar.
9508             }
9509             if ( xml_parser == null ) {
9510                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9511                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9512                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9513                 }
9514                 else {
9515                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9516                 }
9517             }
9518             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9519                                                               xml_parser );
9520             if ( xml_parser.getErrorCount() > 0 ) {
9521                 System.out.println( xml_parser.getErrorMessages().toString() );
9522                 return false;
9523             }
9524             if ( phylogenies_0.length != 1 ) {
9525                 return false;
9526             }
9527             final Phylogeny t1 = phylogenies_0[ 0 ];
9528             PhylogenyNode n = null;
9529             Distribution d = null;
9530             n = t1.getNode( "root node" );
9531             if ( !n.getNodeData().isHasDistribution() ) {
9532                 return false;
9533             }
9534             if ( n.getNodeData().getDistributions().size() != 1 ) {
9535                 return false;
9536             }
9537             d = n.getNodeData().getDistribution();
9538             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9539                 return false;
9540             }
9541             if ( d.getPoints().size() != 1 ) {
9542                 return false;
9543             }
9544             if ( d.getPolygons() != null ) {
9545                 return false;
9546             }
9547             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9548                 return false;
9549             }
9550             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9551                 return false;
9552             }
9553             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9554                 return false;
9555             }
9556             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9557                 return false;
9558             }
9559             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9560                 return false;
9561             }
9562             n = t1.getNode( "node a" );
9563             if ( !n.getNodeData().isHasDistribution() ) {
9564                 return false;
9565             }
9566             if ( n.getNodeData().getDistributions().size() != 2 ) {
9567                 return false;
9568             }
9569             d = n.getNodeData().getDistribution( 1 );
9570             if ( !d.getDesc().equals( "San Diego" ) ) {
9571                 return false;
9572             }
9573             if ( d.getPoints().size() != 1 ) {
9574                 return false;
9575             }
9576             if ( d.getPolygons() != null ) {
9577                 return false;
9578             }
9579             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9580                 return false;
9581             }
9582             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9583                 return false;
9584             }
9585             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9586                 return false;
9587             }
9588             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9589                 return false;
9590             }
9591             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9592                 return false;
9593             }
9594             n = t1.getNode( "node bb" );
9595             if ( !n.getNodeData().isHasDistribution() ) {
9596                 return false;
9597             }
9598             if ( n.getNodeData().getDistributions().size() != 1 ) {
9599                 return false;
9600             }
9601             d = n.getNodeData().getDistribution( 0 );
9602             if ( d.getPoints().size() != 3 ) {
9603                 return false;
9604             }
9605             if ( d.getPolygons().size() != 2 ) {
9606                 return false;
9607             }
9608             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9609                 return false;
9610             }
9611             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9612                 return false;
9613             }
9614             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9615                 return false;
9616             }
9617             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9618                 return false;
9619             }
9620             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9621                 return false;
9622             }
9623             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9624                 return false;
9625             }
9626             Polygon p = d.getPolygons().get( 0 );
9627             if ( p.getPoints().size() != 3 ) {
9628                 return false;
9629             }
9630             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9631                 return false;
9632             }
9633             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9634                 return false;
9635             }
9636             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9637                 return false;
9638             }
9639             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9640                 return false;
9641             }
9642             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9643                 return false;
9644             }
9645             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9646                 return false;
9647             }
9648             p = d.getPolygons().get( 1 );
9649             if ( p.getPoints().size() != 3 ) {
9650                 return false;
9651             }
9652             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9653                 return false;
9654             }
9655             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9656                 return false;
9657             }
9658             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9659                 return false;
9660             }
9661             // Roundtrip:
9662             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9663             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9664             if ( rt.length != 1 ) {
9665                 return false;
9666             }
9667             final Phylogeny t1_rt = rt[ 0 ];
9668             n = t1_rt.getNode( "root node" );
9669             if ( !n.getNodeData().isHasDistribution() ) {
9670                 return false;
9671             }
9672             if ( n.getNodeData().getDistributions().size() != 1 ) {
9673                 return false;
9674             }
9675             d = n.getNodeData().getDistribution();
9676             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9677                 return false;
9678             }
9679             if ( d.getPoints().size() != 1 ) {
9680                 return false;
9681             }
9682             if ( d.getPolygons() != null ) {
9683                 return false;
9684             }
9685             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9686                 return false;
9687             }
9688             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9689                 return false;
9690             }
9691             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9692                 return false;
9693             }
9694             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9695                 return false;
9696             }
9697             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9698                 return false;
9699             }
9700             n = t1_rt.getNode( "node a" );
9701             if ( !n.getNodeData().isHasDistribution() ) {
9702                 return false;
9703             }
9704             if ( n.getNodeData().getDistributions().size() != 2 ) {
9705                 return false;
9706             }
9707             d = n.getNodeData().getDistribution( 1 );
9708             if ( !d.getDesc().equals( "San Diego" ) ) {
9709                 return false;
9710             }
9711             if ( d.getPoints().size() != 1 ) {
9712                 return false;
9713             }
9714             if ( d.getPolygons() != null ) {
9715                 return false;
9716             }
9717             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9718                 return false;
9719             }
9720             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9721                 return false;
9722             }
9723             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9724                 return false;
9725             }
9726             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9727                 return false;
9728             }
9729             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9730                 return false;
9731             }
9732             n = t1_rt.getNode( "node bb" );
9733             if ( !n.getNodeData().isHasDistribution() ) {
9734                 return false;
9735             }
9736             if ( n.getNodeData().getDistributions().size() != 1 ) {
9737                 return false;
9738             }
9739             d = n.getNodeData().getDistribution( 0 );
9740             if ( d.getPoints().size() != 3 ) {
9741                 return false;
9742             }
9743             if ( d.getPolygons().size() != 2 ) {
9744                 return false;
9745             }
9746             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9747                 return false;
9748             }
9749             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9750                 return false;
9751             }
9752             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9753                 return false;
9754             }
9755             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9756                 return false;
9757             }
9758             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9759                 return false;
9760             }
9761             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9762                 return false;
9763             }
9764             p = d.getPolygons().get( 0 );
9765             if ( p.getPoints().size() != 3 ) {
9766                 return false;
9767             }
9768             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9769                 return false;
9770             }
9771             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9772                 return false;
9773             }
9774             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9775                 return false;
9776             }
9777             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9778                 return false;
9779             }
9780             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9781                 return false;
9782             }
9783             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9784                 return false;
9785             }
9786             p = d.getPolygons().get( 1 );
9787             if ( p.getPoints().size() != 3 ) {
9788                 return false;
9789             }
9790             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9791                 return false;
9792             }
9793             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9794                 return false;
9795             }
9796             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9797                 return false;
9798             }
9799         }
9800         catch ( final Exception e ) {
9801             e.printStackTrace( System.out );
9802             return false;
9803         }
9804         return true;
9805     }
9806
9807     private static boolean testPostOrderIterator() {
9808         try {
9809             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9810             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9811             PhylogenyNodeIterator it0;
9812             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9813                 it0.next();
9814             }
9815             for( it0.reset(); it0.hasNext(); ) {
9816                 it0.next();
9817             }
9818             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9819             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9820             if ( !it.next().getName().equals( "A" ) ) {
9821                 return false;
9822             }
9823             if ( !it.next().getName().equals( "B" ) ) {
9824                 return false;
9825             }
9826             if ( !it.next().getName().equals( "ab" ) ) {
9827                 return false;
9828             }
9829             if ( !it.next().getName().equals( "C" ) ) {
9830                 return false;
9831             }
9832             if ( !it.next().getName().equals( "D" ) ) {
9833                 return false;
9834             }
9835             if ( !it.next().getName().equals( "cd" ) ) {
9836                 return false;
9837             }
9838             if ( !it.next().getName().equals( "abcd" ) ) {
9839                 return false;
9840             }
9841             if ( !it.next().getName().equals( "E" ) ) {
9842                 return false;
9843             }
9844             if ( !it.next().getName().equals( "F" ) ) {
9845                 return false;
9846             }
9847             if ( !it.next().getName().equals( "ef" ) ) {
9848                 return false;
9849             }
9850             if ( !it.next().getName().equals( "G" ) ) {
9851                 return false;
9852             }
9853             if ( !it.next().getName().equals( "H" ) ) {
9854                 return false;
9855             }
9856             if ( !it.next().getName().equals( "gh" ) ) {
9857                 return false;
9858             }
9859             if ( !it.next().getName().equals( "efgh" ) ) {
9860                 return false;
9861             }
9862             if ( !it.next().getName().equals( "r" ) ) {
9863                 return false;
9864             }
9865             if ( it.hasNext() ) {
9866                 return false;
9867             }
9868         }
9869         catch ( final Exception e ) {
9870             e.printStackTrace( System.out );
9871             return false;
9872         }
9873         return true;
9874     }
9875
9876     private static boolean testPreOrderIterator() {
9877         try {
9878             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9879             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9880             PhylogenyNodeIterator it0;
9881             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9882                 it0.next();
9883             }
9884             for( it0.reset(); it0.hasNext(); ) {
9885                 it0.next();
9886             }
9887             PhylogenyNodeIterator it = t0.iteratorPreorder();
9888             if ( !it.next().getName().equals( "r" ) ) {
9889                 return false;
9890             }
9891             if ( !it.next().getName().equals( "ab" ) ) {
9892                 return false;
9893             }
9894             if ( !it.next().getName().equals( "A" ) ) {
9895                 return false;
9896             }
9897             if ( !it.next().getName().equals( "B" ) ) {
9898                 return false;
9899             }
9900             if ( !it.next().getName().equals( "cd" ) ) {
9901                 return false;
9902             }
9903             if ( !it.next().getName().equals( "C" ) ) {
9904                 return false;
9905             }
9906             if ( !it.next().getName().equals( "D" ) ) {
9907                 return false;
9908             }
9909             if ( it.hasNext() ) {
9910                 return false;
9911             }
9912             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9913             it = t1.iteratorPreorder();
9914             if ( !it.next().getName().equals( "r" ) ) {
9915                 return false;
9916             }
9917             if ( !it.next().getName().equals( "abcd" ) ) {
9918                 return false;
9919             }
9920             if ( !it.next().getName().equals( "ab" ) ) {
9921                 return false;
9922             }
9923             if ( !it.next().getName().equals( "A" ) ) {
9924                 return false;
9925             }
9926             if ( !it.next().getName().equals( "B" ) ) {
9927                 return false;
9928             }
9929             if ( !it.next().getName().equals( "cd" ) ) {
9930                 return false;
9931             }
9932             if ( !it.next().getName().equals( "C" ) ) {
9933                 return false;
9934             }
9935             if ( !it.next().getName().equals( "D" ) ) {
9936                 return false;
9937             }
9938             if ( !it.next().getName().equals( "efgh" ) ) {
9939                 return false;
9940             }
9941             if ( !it.next().getName().equals( "ef" ) ) {
9942                 return false;
9943             }
9944             if ( !it.next().getName().equals( "E" ) ) {
9945                 return false;
9946             }
9947             if ( !it.next().getName().equals( "F" ) ) {
9948                 return false;
9949             }
9950             if ( !it.next().getName().equals( "gh" ) ) {
9951                 return false;
9952             }
9953             if ( !it.next().getName().equals( "G" ) ) {
9954                 return false;
9955             }
9956             if ( !it.next().getName().equals( "H" ) ) {
9957                 return false;
9958             }
9959             if ( it.hasNext() ) {
9960                 return false;
9961             }
9962         }
9963         catch ( final Exception e ) {
9964             e.printStackTrace( System.out );
9965             return false;
9966         }
9967         return true;
9968     }
9969
9970     private static boolean testPropertiesMap() {
9971         try {
9972             final PropertiesMap pm = new PropertiesMap();
9973             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9974             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9975             final Property p2 = new Property( "something:else",
9976                                               "?",
9977                                               "improbable:research",
9978                                               "xsd:decimal",
9979                                               AppliesTo.NODE );
9980             pm.addProperty( p0 );
9981             pm.addProperty( p1 );
9982             pm.addProperty( p2 );
9983             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9984                 return false;
9985             }
9986             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9987                 return false;
9988             }
9989             if ( pm.getProperties().size() != 3 ) {
9990                 return false;
9991             }
9992             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9993                 return false;
9994             }
9995             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9996                 return false;
9997             }
9998             if ( pm.getProperties().size() != 3 ) {
9999                 return false;
10000             }
10001             pm.removeProperty( "dimensions:diameter" );
10002             if ( pm.getProperties().size() != 2 ) {
10003                 return false;
10004             }
10005             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10006                 return false;
10007             }
10008             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10009                 return false;
10010             }
10011         }
10012         catch ( final Exception e ) {
10013             e.printStackTrace( System.out );
10014             return false;
10015         }
10016         return true;
10017     }
10018
10019     private static boolean testProteinId() {
10020         try {
10021             final ProteinId id1 = new ProteinId( "a" );
10022             final ProteinId id2 = new ProteinId( "a" );
10023             final ProteinId id3 = new ProteinId( "A" );
10024             final ProteinId id4 = new ProteinId( "b" );
10025             if ( !id1.equals( id1 ) ) {
10026                 return false;
10027             }
10028             if ( id1.getId().equals( "x" ) ) {
10029                 return false;
10030             }
10031             if ( id1.getId().equals( null ) ) {
10032                 return false;
10033             }
10034             if ( !id1.equals( id2 ) ) {
10035                 return false;
10036             }
10037             if ( id1.equals( id3 ) ) {
10038                 return false;
10039             }
10040             if ( id1.hashCode() != id1.hashCode() ) {
10041                 return false;
10042             }
10043             if ( id1.hashCode() != id2.hashCode() ) {
10044                 return false;
10045             }
10046             if ( id1.hashCode() == id3.hashCode() ) {
10047                 return false;
10048             }
10049             if ( id1.compareTo( id1 ) != 0 ) {
10050                 return false;
10051             }
10052             if ( id1.compareTo( id2 ) != 0 ) {
10053                 return false;
10054             }
10055             if ( id1.compareTo( id3 ) != 0 ) {
10056                 return false;
10057             }
10058             if ( id1.compareTo( id4 ) >= 0 ) {
10059                 return false;
10060             }
10061             if ( id4.compareTo( id1 ) <= 0 ) {
10062                 return false;
10063             }
10064             if ( !id4.getId().equals( "b" ) ) {
10065                 return false;
10066             }
10067             final ProteinId id5 = new ProteinId( " C " );
10068             if ( !id5.getId().equals( "C" ) ) {
10069                 return false;
10070             }
10071             if ( id5.equals( id1 ) ) {
10072                 return false;
10073             }
10074         }
10075         catch ( final Exception e ) {
10076             e.printStackTrace( System.out );
10077             return false;
10078         }
10079         return true;
10080     }
10081
10082     private static boolean testReIdMethods() {
10083         try {
10084             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10085             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10086             final long count = PhylogenyNode.getNodeCount();
10087             p.levelOrderReID();
10088             if ( p.getNode( "r" ).getId() != count ) {
10089                 return false;
10090             }
10091             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10092                 return false;
10093             }
10094             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10095                 return false;
10096             }
10097             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10098                 return false;
10099             }
10100             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10101                 return false;
10102             }
10103             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10104                 return false;
10105             }
10106             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10107                 return false;
10108             }
10109             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10110                 return false;
10111             }
10112             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10113                 return false;
10114             }
10115             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10116                 return false;
10117             }
10118             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10119                 return false;
10120             }
10121             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10122                 return false;
10123             }
10124             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10125                 return false;
10126             }
10127             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10128                 return false;
10129             }
10130             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10131                 return false;
10132             }
10133         }
10134         catch ( final Exception e ) {
10135             e.printStackTrace( System.out );
10136             return false;
10137         }
10138         return true;
10139     }
10140
10141     private static boolean testRerooting() {
10142         try {
10143             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10144             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",
10145                                                  new NHXParser() )[ 0 ];
10146             if ( !t1.isRooted() ) {
10147                 return false;
10148             }
10149             t1.reRoot( t1.getNode( "D" ) );
10150             t1.reRoot( t1.getNode( "CD" ) );
10151             t1.reRoot( t1.getNode( "A" ) );
10152             t1.reRoot( t1.getNode( "B" ) );
10153             t1.reRoot( t1.getNode( "AB" ) );
10154             t1.reRoot( t1.getNode( "D" ) );
10155             t1.reRoot( t1.getNode( "C" ) );
10156             t1.reRoot( t1.getNode( "CD" ) );
10157             t1.reRoot( t1.getNode( "A" ) );
10158             t1.reRoot( t1.getNode( "B" ) );
10159             t1.reRoot( t1.getNode( "AB" ) );
10160             t1.reRoot( t1.getNode( "D" ) );
10161             t1.reRoot( t1.getNode( "D" ) );
10162             t1.reRoot( t1.getNode( "C" ) );
10163             t1.reRoot( t1.getNode( "A" ) );
10164             t1.reRoot( t1.getNode( "B" ) );
10165             t1.reRoot( t1.getNode( "AB" ) );
10166             t1.reRoot( t1.getNode( "C" ) );
10167             t1.reRoot( t1.getNode( "D" ) );
10168             t1.reRoot( t1.getNode( "CD" ) );
10169             t1.reRoot( t1.getNode( "D" ) );
10170             t1.reRoot( t1.getNode( "A" ) );
10171             t1.reRoot( t1.getNode( "B" ) );
10172             t1.reRoot( t1.getNode( "AB" ) );
10173             t1.reRoot( t1.getNode( "C" ) );
10174             t1.reRoot( t1.getNode( "D" ) );
10175             t1.reRoot( t1.getNode( "CD" ) );
10176             t1.reRoot( t1.getNode( "D" ) );
10177             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10178                 return false;
10179             }
10180             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10181                 return false;
10182             }
10183             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10184                 return false;
10185             }
10186             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10187                 return false;
10188             }
10189             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10190                 return false;
10191             }
10192             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10193                 return false;
10194             }
10195             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",
10196                                                  new NHXParser() )[ 0 ];
10197             t2.reRoot( t2.getNode( "A" ) );
10198             t2.reRoot( t2.getNode( "D" ) );
10199             t2.reRoot( t2.getNode( "ABC" ) );
10200             t2.reRoot( t2.getNode( "A" ) );
10201             t2.reRoot( t2.getNode( "B" ) );
10202             t2.reRoot( t2.getNode( "D" ) );
10203             t2.reRoot( t2.getNode( "C" ) );
10204             t2.reRoot( t2.getNode( "ABC" ) );
10205             t2.reRoot( t2.getNode( "A" ) );
10206             t2.reRoot( t2.getNode( "B" ) );
10207             t2.reRoot( t2.getNode( "AB" ) );
10208             t2.reRoot( t2.getNode( "AB" ) );
10209             t2.reRoot( t2.getNode( "D" ) );
10210             t2.reRoot( t2.getNode( "C" ) );
10211             t2.reRoot( t2.getNode( "B" ) );
10212             t2.reRoot( t2.getNode( "AB" ) );
10213             t2.reRoot( t2.getNode( "D" ) );
10214             t2.reRoot( t2.getNode( "D" ) );
10215             t2.reRoot( t2.getNode( "ABC" ) );
10216             t2.reRoot( t2.getNode( "A" ) );
10217             t2.reRoot( t2.getNode( "B" ) );
10218             t2.reRoot( t2.getNode( "AB" ) );
10219             t2.reRoot( t2.getNode( "D" ) );
10220             t2.reRoot( t2.getNode( "C" ) );
10221             t2.reRoot( t2.getNode( "ABC" ) );
10222             t2.reRoot( t2.getNode( "A" ) );
10223             t2.reRoot( t2.getNode( "B" ) );
10224             t2.reRoot( t2.getNode( "AB" ) );
10225             t2.reRoot( t2.getNode( "D" ) );
10226             t2.reRoot( t2.getNode( "D" ) );
10227             t2.reRoot( t2.getNode( "C" ) );
10228             t2.reRoot( t2.getNode( "A" ) );
10229             t2.reRoot( t2.getNode( "B" ) );
10230             t2.reRoot( t2.getNode( "AB" ) );
10231             t2.reRoot( t2.getNode( "C" ) );
10232             t2.reRoot( t2.getNode( "D" ) );
10233             t2.reRoot( t2.getNode( "ABC" ) );
10234             t2.reRoot( t2.getNode( "D" ) );
10235             t2.reRoot( t2.getNode( "A" ) );
10236             t2.reRoot( t2.getNode( "B" ) );
10237             t2.reRoot( t2.getNode( "AB" ) );
10238             t2.reRoot( t2.getNode( "C" ) );
10239             t2.reRoot( t2.getNode( "D" ) );
10240             t2.reRoot( t2.getNode( "ABC" ) );
10241             t2.reRoot( t2.getNode( "D" ) );
10242             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10243                 return false;
10244             }
10245             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10246                 return false;
10247             }
10248             t2.reRoot( t2.getNode( "ABC" ) );
10249             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10250                 return false;
10251             }
10252             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10253                 return false;
10254             }
10255             t2.reRoot( t2.getNode( "AB" ) );
10256             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10257                 return false;
10258             }
10259             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10260                 return false;
10261             }
10262             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10263                 return false;
10264             }
10265             t2.reRoot( t2.getNode( "AB" ) );
10266             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10267                 return false;
10268             }
10269             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10270                 return false;
10271             }
10272             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10273                 return false;
10274             }
10275             t2.reRoot( t2.getNode( "D" ) );
10276             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10277                 return false;
10278             }
10279             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10280                 return false;
10281             }
10282             t2.reRoot( t2.getNode( "ABC" ) );
10283             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10284                 return false;
10285             }
10286             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10287                 return false;
10288             }
10289             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10290                                                  new NHXParser() )[ 0 ];
10291             t3.reRoot( t3.getNode( "B" ) );
10292             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10293                 return false;
10294             }
10295             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10296                 return false;
10297             }
10298             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10299                 return false;
10300             }
10301             t3.reRoot( t3.getNode( "B" ) );
10302             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10303                 return false;
10304             }
10305             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10306                 return false;
10307             }
10308             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10309                 return false;
10310             }
10311             t3.reRoot( t3.getRoot() );
10312             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10313                 return false;
10314             }
10315             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10316                 return false;
10317             }
10318             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10319                 return false;
10320             }
10321         }
10322         catch ( final Exception e ) {
10323             e.printStackTrace( System.out );
10324             return false;
10325         }
10326         return true;
10327     }
10328
10329     private static boolean testSDIse() {
10330         try {
10331             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10332             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10333             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10334             gene1.setRooted( true );
10335             species1.setRooted( true );
10336             final SDI sdi = new SDI( gene1, species1 );
10337             if ( !gene1.getRoot().isDuplication() ) {
10338                 return false;
10339             }
10340             final Phylogeny species2 = factory
10341                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10342                              new NHXParser() )[ 0 ];
10343             final Phylogeny gene2 = factory
10344                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10345                              new NHXParser() )[ 0 ];
10346             species2.setRooted( true );
10347             gene2.setRooted( true );
10348             final SDI sdi2 = new SDI( gene2, species2 );
10349             if ( sdi2.getDuplicationsSum() != 0 ) {
10350                 return false;
10351             }
10352             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10353                 return false;
10354             }
10355             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10356                 return false;
10357             }
10358             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10359                 return false;
10360             }
10361             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10362                 return false;
10363             }
10364             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10365                 return false;
10366             }
10367             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10368                 return false;
10369             }
10370             final Phylogeny species3 = factory
10371                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10372                              new NHXParser() )[ 0 ];
10373             final Phylogeny gene3 = factory
10374                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10375                              new NHXParser() )[ 0 ];
10376             species3.setRooted( true );
10377             gene3.setRooted( true );
10378             final SDI sdi3 = new SDI( gene3, species3 );
10379             if ( sdi3.getDuplicationsSum() != 1 ) {
10380                 return false;
10381             }
10382             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10383                 return false;
10384             }
10385             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10386                 return false;
10387             }
10388             final Phylogeny species4 = factory
10389                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10390                              new NHXParser() )[ 0 ];
10391             final Phylogeny gene4 = factory
10392                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10393                              new NHXParser() )[ 0 ];
10394             species4.setRooted( true );
10395             gene4.setRooted( true );
10396             final SDI sdi4 = new SDI( gene4, species4 );
10397             if ( sdi4.getDuplicationsSum() != 1 ) {
10398                 return false;
10399             }
10400             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10401                 return false;
10402             }
10403             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10404                 return false;
10405             }
10406             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10407                 return false;
10408             }
10409             if ( species4.getNumberOfExternalNodes() != 6 ) {
10410                 return false;
10411             }
10412             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10413                 return false;
10414             }
10415             final Phylogeny species5 = factory
10416                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10417                              new NHXParser() )[ 0 ];
10418             final Phylogeny gene5 = factory
10419                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10420                              new NHXParser() )[ 0 ];
10421             species5.setRooted( true );
10422             gene5.setRooted( true );
10423             final SDI sdi5 = new SDI( gene5, species5 );
10424             if ( sdi5.getDuplicationsSum() != 2 ) {
10425                 return false;
10426             }
10427             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10428                 return false;
10429             }
10430             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10431                 return false;
10432             }
10433             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10434                 return false;
10435             }
10436             if ( species5.getNumberOfExternalNodes() != 6 ) {
10437                 return false;
10438             }
10439             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10440                 return false;
10441             }
10442             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10443             // Conjecture for Comparing Molecular Phylogenies"
10444             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10445             final Phylogeny species6 = factory
10446                     .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,"
10447                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10448                              new NHXParser() )[ 0 ];
10449             final Phylogeny gene6 = factory
10450                     .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,"
10451                                      + "((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,"
10452                                      + "(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;",
10453                              new NHXParser() )[ 0 ];
10454             species6.setRooted( true );
10455             gene6.setRooted( true );
10456             final SDI sdi6 = new SDI( gene6, species6 );
10457             if ( sdi6.getDuplicationsSum() != 3 ) {
10458                 return false;
10459             }
10460             if ( !gene6.getNode( "r" ).isDuplication() ) {
10461                 return false;
10462             }
10463             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10464                 return false;
10465             }
10466             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10467                 return false;
10468             }
10469             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10470                 return false;
10471             }
10472             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10473                 return false;
10474             }
10475             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10476                 return false;
10477             }
10478             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10479                 return false;
10480             }
10481             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10482                 return false;
10483             }
10484             sdi6.computeMappingCostL();
10485             if ( sdi6.computeMappingCostL() != 17 ) {
10486                 return false;
10487             }
10488             if ( species6.getNumberOfExternalNodes() != 9 ) {
10489                 return false;
10490             }
10491             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10492                 return false;
10493             }
10494             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10495                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10496                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10497                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10498                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10499             species7.setRooted( true );
10500             final Phylogeny gene7_1 = Test
10501                     .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])" );
10502             gene7_1.setRooted( true );
10503             final SDI sdi7 = new SDI( gene7_1, species7 );
10504             if ( sdi7.getDuplicationsSum() != 0 ) {
10505                 return false;
10506             }
10507             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10508                 return false;
10509             }
10510             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10511                 return false;
10512             }
10513             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10514                 return false;
10515             }
10516             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10517                 return false;
10518             }
10519             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10520                 return false;
10521             }
10522             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10523                 return false;
10524             }
10525             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10526                 return false;
10527             }
10528             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10529                 return false;
10530             }
10531             final Phylogeny gene7_2 = Test
10532                     .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])" );
10533             gene7_2.setRooted( true );
10534             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10535             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10536                 return false;
10537             }
10538             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10539                 return false;
10540             }
10541             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10542                 return false;
10543             }
10544             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10545                 return false;
10546             }
10547             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10548                 return false;
10549             }
10550             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10551                 return false;
10552             }
10553             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10554                 return false;
10555             }
10556             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10557                 return false;
10558             }
10559             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10560                 return false;
10561             }
10562             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10563                 return false;
10564             }
10565         }
10566         catch ( final Exception e ) {
10567             return false;
10568         }
10569         return true;
10570     }
10571
10572     private static boolean testSDIunrooted() {
10573         try {
10574             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10575             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10576             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10577             final Iterator<PhylogenyBranch> iter = l.iterator();
10578             PhylogenyBranch br = iter.next();
10579             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10580                 return false;
10581             }
10582             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10583                 return false;
10584             }
10585             br = iter.next();
10586             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10587                 return false;
10588             }
10589             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10590                 return false;
10591             }
10592             br = iter.next();
10593             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10594                 return false;
10595             }
10596             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10597                 return false;
10598             }
10599             br = iter.next();
10600             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10601                 return false;
10602             }
10603             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10604                 return false;
10605             }
10606             br = iter.next();
10607             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10608                 return false;
10609             }
10610             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10611                 return false;
10612             }
10613             br = iter.next();
10614             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10615                 return false;
10616             }
10617             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10618                 return false;
10619             }
10620             br = iter.next();
10621             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10622                 return false;
10623             }
10624             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10625                 return false;
10626             }
10627             br = iter.next();
10628             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10629                 return false;
10630             }
10631             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10632                 return false;
10633             }
10634             br = iter.next();
10635             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10636                 return false;
10637             }
10638             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10639                 return false;
10640             }
10641             br = iter.next();
10642             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10643                 return false;
10644             }
10645             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10646                 return false;
10647             }
10648             br = iter.next();
10649             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10650                 return false;
10651             }
10652             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10653                 return false;
10654             }
10655             br = iter.next();
10656             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10657                 return false;
10658             }
10659             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10660                 return false;
10661             }
10662             br = iter.next();
10663             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10664                 return false;
10665             }
10666             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10667                 return false;
10668             }
10669             br = iter.next();
10670             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10671                 return false;
10672             }
10673             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10674                 return false;
10675             }
10676             br = iter.next();
10677             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10678                 return false;
10679             }
10680             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10681                 return false;
10682             }
10683             if ( iter.hasNext() ) {
10684                 return false;
10685             }
10686             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10687             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10688             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10689             br = iter1.next();
10690             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10691                 return false;
10692             }
10693             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10694                 return false;
10695             }
10696             br = iter1.next();
10697             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10698                 return false;
10699             }
10700             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10701                 return false;
10702             }
10703             br = iter1.next();
10704             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10705                 return false;
10706             }
10707             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10708                 return false;
10709             }
10710             if ( iter1.hasNext() ) {
10711                 return false;
10712             }
10713             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10714             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10715             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10716             br = iter2.next();
10717             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10718                 return false;
10719             }
10720             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10721                 return false;
10722             }
10723             br = iter2.next();
10724             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10725                 return false;
10726             }
10727             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10728                 return false;
10729             }
10730             br = iter2.next();
10731             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10732                 return false;
10733             }
10734             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10735                 return false;
10736             }
10737             if ( iter2.hasNext() ) {
10738                 return false;
10739             }
10740             final Phylogeny species0 = factory
10741                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10742                              new NHXParser() )[ 0 ];
10743             final Phylogeny gene1 = factory
10744                     .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])",
10745                              new NHXParser() )[ 0 ];
10746             species0.setRooted( true );
10747             gene1.setRooted( true );
10748             final SDIR sdi_unrooted = new SDIR();
10749             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10750             if ( sdi_unrooted.getCount() != 1 ) {
10751                 return false;
10752             }
10753             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10754                 return false;
10755             }
10756             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10757                 return false;
10758             }
10759             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10760                 return false;
10761             }
10762             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10763                 return false;
10764             }
10765             final Phylogeny gene2 = factory
10766                     .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])",
10767                              new NHXParser() )[ 0 ];
10768             gene2.setRooted( true );
10769             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10770             if ( sdi_unrooted.getCount() != 1 ) {
10771                 return false;
10772             }
10773             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10774                 return false;
10775             }
10776             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10777                 return false;
10778             }
10779             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10780                 return false;
10781             }
10782             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10783                 return false;
10784             }
10785             final Phylogeny species6 = factory
10786                     .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,"
10787                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10788                              new NHXParser() )[ 0 ];
10789             final Phylogeny gene6 = factory
10790                     .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],"
10791                                      + "(((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],"
10792                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10793                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10794                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10795                              new NHXParser() )[ 0 ];
10796             species6.setRooted( true );
10797             gene6.setRooted( true );
10798             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10799             if ( sdi_unrooted.getCount() != 1 ) {
10800                 return false;
10801             }
10802             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10803                 return false;
10804             }
10805             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10806                 return false;
10807             }
10808             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10809                 return false;
10810             }
10811             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10812                 return false;
10813             }
10814             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10815                 return false;
10816             }
10817             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10818                 return false;
10819             }
10820             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10821                 return false;
10822             }
10823             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10824                 return false;
10825             }
10826             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10827                 return false;
10828             }
10829             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10830                 return false;
10831             }
10832             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10833                 return false;
10834             }
10835             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10836                 return false;
10837             }
10838             p6 = null;
10839             final Phylogeny species7 = factory
10840                     .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,"
10841                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10842                              new NHXParser() )[ 0 ];
10843             final Phylogeny gene7 = factory
10844                     .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],"
10845                                      + "(((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],"
10846                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10847                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10848                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10849                              new NHXParser() )[ 0 ];
10850             species7.setRooted( true );
10851             gene7.setRooted( true );
10852             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10853             if ( sdi_unrooted.getCount() != 1 ) {
10854                 return false;
10855             }
10856             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10857                 return false;
10858             }
10859             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10860                 return false;
10861             }
10862             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10863                 return false;
10864             }
10865             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10866                 return false;
10867             }
10868             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10869                 return false;
10870             }
10871             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10872                 return false;
10873             }
10874             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10875                 return false;
10876             }
10877             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10878                 return false;
10879             }
10880             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10881                 return false;
10882             }
10883             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10884                 return false;
10885             }
10886             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10887                 return false;
10888             }
10889             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10890                 return false;
10891             }
10892             p7 = null;
10893             final Phylogeny species8 = factory
10894                     .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,"
10895                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10896                              new NHXParser() )[ 0 ];
10897             final Phylogeny gene8 = factory
10898                     .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],"
10899                                      + "(((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],"
10900                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10901                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10902                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10903                              new NHXParser() )[ 0 ];
10904             species8.setRooted( true );
10905             gene8.setRooted( true );
10906             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10907             if ( sdi_unrooted.getCount() != 1 ) {
10908                 return false;
10909             }
10910             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10911                 return false;
10912             }
10913             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10914                 return false;
10915             }
10916             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10917                 return false;
10918             }
10919             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10920                 return false;
10921             }
10922             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10923                 return false;
10924             }
10925             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10926                 return false;
10927             }
10928             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10929                 return false;
10930             }
10931             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10932                 return false;
10933             }
10934             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10935                 return false;
10936             }
10937             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10938                 return false;
10939             }
10940             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10941                 return false;
10942             }
10943             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10944                 return false;
10945             }
10946             p8 = null;
10947         }
10948         catch ( final Exception e ) {
10949             e.printStackTrace( System.out );
10950             return false;
10951         }
10952         return true;
10953     }
10954
10955     private static boolean testSequenceDbWsTools1() {
10956         try {
10957             final PhylogenyNode n = new PhylogenyNode();
10958             n.setName( "NP_001025424" );
10959             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10960             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10961                     || !acc.getValue().equals( "NP_001025424" ) ) {
10962                 return false;
10963             }
10964             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10965             acc = SequenceDbWsTools.obtainSeqAccession( n );
10966             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10967                     || !acc.getValue().equals( "NP_001025424" ) ) {
10968                 return false;
10969             }
10970             n.setName( "NP_001025424.1" );
10971             acc = SequenceDbWsTools.obtainSeqAccession( n );
10972             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10973                     || !acc.getValue().equals( "NP_001025424" ) ) {
10974                 return false;
10975             }
10976             n.setName( "NM_001030253" );
10977             acc = SequenceDbWsTools.obtainSeqAccession( n );
10978             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10979                     || !acc.getValue().equals( "NM_001030253" ) ) {
10980                 return false;
10981             }
10982             n.setName( "BCL2_HUMAN" );
10983             acc = SequenceDbWsTools.obtainSeqAccession( n );
10984             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10985                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10986                 System.out.println( acc.toString() );
10987                 return false;
10988             }
10989             n.setName( "P10415" );
10990             acc = SequenceDbWsTools.obtainSeqAccession( n );
10991             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10992                     || !acc.getValue().equals( "P10415" ) ) {
10993                 System.out.println( acc.toString() );
10994                 return false;
10995             }
10996             n.setName( " P10415 " );
10997             acc = SequenceDbWsTools.obtainSeqAccession( n );
10998             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10999                     || !acc.getValue().equals( "P10415" ) ) {
11000                 System.out.println( acc.toString() );
11001                 return false;
11002             }
11003             n.setName( "_P10415|" );
11004             acc = SequenceDbWsTools.obtainSeqAccession( n );
11005             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11006                     || !acc.getValue().equals( "P10415" ) ) {
11007                 System.out.println( acc.toString() );
11008                 return false;
11009             }
11010             n.setName( "AY695820" );
11011             acc = SequenceDbWsTools.obtainSeqAccession( n );
11012             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11013                     || !acc.getValue().equals( "AY695820" ) ) {
11014                 System.out.println( acc.toString() );
11015                 return false;
11016             }
11017             n.setName( "_AY695820_" );
11018             acc = SequenceDbWsTools.obtainSeqAccession( n );
11019             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11020                     || !acc.getValue().equals( "AY695820" ) ) {
11021                 System.out.println( acc.toString() );
11022                 return false;
11023             }
11024             n.setName( "AAA59452" );
11025             acc = SequenceDbWsTools.obtainSeqAccession( n );
11026             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11027                     || !acc.getValue().equals( "AAA59452" ) ) {
11028                 System.out.println( acc.toString() );
11029                 return false;
11030             }
11031             n.setName( "_AAA59452_" );
11032             acc = SequenceDbWsTools.obtainSeqAccession( n );
11033             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11034                     || !acc.getValue().equals( "AAA59452" ) ) {
11035                 System.out.println( acc.toString() );
11036                 return false;
11037             }
11038             n.setName( "AAA59452.1" );
11039             acc = SequenceDbWsTools.obtainSeqAccession( n );
11040             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11041                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11042                 System.out.println( acc.toString() );
11043                 return false;
11044             }
11045             n.setName( "_AAA59452.1_" );
11046             acc = SequenceDbWsTools.obtainSeqAccession( n );
11047             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11048                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11049                 System.out.println( acc.toString() );
11050                 return false;
11051             }
11052             n.setName( "GI:94894583" );
11053             acc = SequenceDbWsTools.obtainSeqAccession( n );
11054             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11055                     || !acc.getValue().equals( "94894583" ) ) {
11056                 System.out.println( acc.toString() );
11057                 return false;
11058             }
11059             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11060             acc = SequenceDbWsTools.obtainSeqAccession( n );
11061             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11062                     || !acc.getValue().equals( "71845847" ) ) {
11063                 System.out.println( acc.toString() );
11064                 return false;
11065             }
11066             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11067             acc = SequenceDbWsTools.obtainSeqAccession( n );
11068             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11069                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11070                 System.out.println( acc.toString() );
11071                 return false;
11072             }
11073         }
11074         catch ( final Exception e ) {
11075             return false;
11076         }
11077         return true;
11078     }
11079
11080     private static boolean testSequenceDbWsTools2() {
11081         try {
11082             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11083             SequenceDbWsTools.obtainSeqInformation( n1 );
11084             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11085                 return false;
11086             }
11087             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11088                 return false;
11089             }
11090             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11091                 return false;
11092             }
11093             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11094                 return false;
11095             }
11096             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11097             SequenceDbWsTools.obtainSeqInformation( n2 );
11098             if ( !n2.getNodeData().getSequence().getName()
11099                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11100                 return false;
11101             }
11102             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11103                 return false;
11104             }
11105             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11106                 return false;
11107             }
11108             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11109                 return false;
11110             }
11111             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11112             SequenceDbWsTools.obtainSeqInformation( n3 );
11113             if ( !n3.getNodeData().getSequence().getName()
11114                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11115                 return false;
11116             }
11117             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11118                 return false;
11119             }
11120             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11121                 return false;
11122             }
11123             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11124                 return false;
11125             }
11126         }
11127         catch ( final IOException e ) {
11128             System.out.println();
11129             System.out.println( "the following might be due to absence internet connection:" );
11130             e.printStackTrace( System.out );
11131             return true;
11132         }
11133         catch ( final Exception e ) {
11134             e.printStackTrace();
11135             return false;
11136         }
11137         return true;
11138     }
11139
11140     private static boolean testSequenceIdParsing() {
11141         try {
11142             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11143             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11144                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11145                 if ( id != null ) {
11146                     System.out.println( "value   =" + id.getValue() );
11147                     System.out.println( "provider=" + id.getSource() );
11148                 }
11149                 return false;
11150             }
11151             //
11152             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11153             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11154                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11155                 if ( id != null ) {
11156                     System.out.println( "value   =" + id.getValue() );
11157                     System.out.println( "provider=" + id.getSource() );
11158                 }
11159                 return false;
11160             }
11161             //
11162             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11163             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11164                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11165                 if ( id != null ) {
11166                     System.out.println( "value   =" + id.getValue() );
11167                     System.out.println( "provider=" + id.getSource() );
11168                 }
11169                 return false;
11170             }
11171             // 
11172             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11173             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11174                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11175                 if ( id != null ) {
11176                     System.out.println( "value   =" + id.getValue() );
11177                     System.out.println( "provider=" + id.getSource() );
11178                 }
11179                 return false;
11180             }
11181             // 
11182             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11183             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11184                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11185                 if ( id != null ) {
11186                     System.out.println( "value   =" + id.getValue() );
11187                     System.out.println( "provider=" + id.getSource() );
11188                 }
11189                 return false;
11190             }
11191             // 
11192             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11193             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11194                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11195                 if ( id != null ) {
11196                     System.out.println( "value   =" + id.getValue() );
11197                     System.out.println( "provider=" + id.getSource() );
11198                 }
11199                 return false;
11200             }
11201             // 
11202             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11203             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11204                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11205                 if ( id != null ) {
11206                     System.out.println( "value   =" + id.getValue() );
11207                     System.out.println( "provider=" + id.getSource() );
11208                 }
11209                 return false;
11210             }
11211             // 
11212             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11213             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11214                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11215                 if ( id != null ) {
11216                     System.out.println( "value   =" + id.getValue() );
11217                     System.out.println( "provider=" + id.getSource() );
11218                 }
11219                 return false;
11220             }
11221             // 
11222             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11223             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11224                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11225                 if ( id != null ) {
11226                     System.out.println( "value   =" + id.getValue() );
11227                     System.out.println( "provider=" + id.getSource() );
11228                 }
11229                 return false;
11230             }
11231             // 
11232             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11233             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11234                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11235                 if ( id != null ) {
11236                     System.out.println( "value   =" + id.getValue() );
11237                     System.out.println( "provider=" + id.getSource() );
11238                 }
11239                 return false;
11240             }
11241             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11242             if ( id != null ) {
11243                 System.out.println( "value   =" + id.getValue() );
11244                 System.out.println( "provider=" + id.getSource() );
11245                 return false;
11246             }
11247         }
11248         catch ( final Exception e ) {
11249             e.printStackTrace( System.out );
11250             return false;
11251         }
11252         return true;
11253     }
11254
11255     private static boolean testSequenceWriter() {
11256         try {
11257             final String n = ForesterUtil.LINE_SEPARATOR;
11258             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11259                 return false;
11260             }
11261             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11262                 return false;
11263             }
11264             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11265                 return false;
11266             }
11267             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11268                 return false;
11269             }
11270             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11271                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11272                 return false;
11273             }
11274             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11275                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11276                 return false;
11277             }
11278         }
11279         catch ( final Exception e ) {
11280             e.printStackTrace();
11281             return false;
11282         }
11283         return true;
11284     }
11285
11286     private static boolean testSpecies() {
11287         try {
11288             final Species s1 = new BasicSpecies( "a" );
11289             final Species s2 = new BasicSpecies( "a" );
11290             final Species s3 = new BasicSpecies( "A" );
11291             final Species s4 = new BasicSpecies( "b" );
11292             if ( !s1.equals( s1 ) ) {
11293                 return false;
11294             }
11295             if ( s1.getSpeciesId().equals( "x" ) ) {
11296                 return false;
11297             }
11298             if ( s1.getSpeciesId().equals( null ) ) {
11299                 return false;
11300             }
11301             if ( !s1.equals( s2 ) ) {
11302                 return false;
11303             }
11304             if ( s1.equals( s3 ) ) {
11305                 return false;
11306             }
11307             if ( s1.hashCode() != s1.hashCode() ) {
11308                 return false;
11309             }
11310             if ( s1.hashCode() != s2.hashCode() ) {
11311                 return false;
11312             }
11313             if ( s1.hashCode() == s3.hashCode() ) {
11314                 return false;
11315             }
11316             if ( s1.compareTo( s1 ) != 0 ) {
11317                 return false;
11318             }
11319             if ( s1.compareTo( s2 ) != 0 ) {
11320                 return false;
11321             }
11322             if ( s1.compareTo( s3 ) != 0 ) {
11323                 return false;
11324             }
11325             if ( s1.compareTo( s4 ) >= 0 ) {
11326                 return false;
11327             }
11328             if ( s4.compareTo( s1 ) <= 0 ) {
11329                 return false;
11330             }
11331             if ( !s4.getSpeciesId().equals( "b" ) ) {
11332                 return false;
11333             }
11334             final Species s5 = new BasicSpecies( " C " );
11335             if ( !s5.getSpeciesId().equals( "C" ) ) {
11336                 return false;
11337             }
11338             if ( s5.equals( s1 ) ) {
11339                 return false;
11340             }
11341         }
11342         catch ( final Exception e ) {
11343             e.printStackTrace( System.out );
11344             return false;
11345         }
11346         return true;
11347     }
11348
11349     private static boolean testSplit() {
11350         try {
11351             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11352             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11353             //Archaeopteryx.createApplication( p0 );
11354             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11355             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11356             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11357             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11358             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11359             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11360             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11361             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11362             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11363             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11364             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11365             // System.out.println( s0.toString() );
11366             //
11367             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11370             if ( s0.match( query_nodes ) ) {
11371                 return false;
11372             }
11373             query_nodes = new HashSet<PhylogenyNode>();
11374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11381             if ( !s0.match( query_nodes ) ) {
11382                 return false;
11383             }
11384             //
11385             query_nodes = new HashSet<PhylogenyNode>();
11386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11389             if ( !s0.match( query_nodes ) ) {
11390                 return false;
11391             }
11392             //
11393             query_nodes = new HashSet<PhylogenyNode>();
11394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11398             if ( !s0.match( query_nodes ) ) {
11399                 return false;
11400             }
11401             //
11402             query_nodes = new HashSet<PhylogenyNode>();
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11407             if ( !s0.match( query_nodes ) ) {
11408                 return false;
11409             }
11410             //
11411             query_nodes = new HashSet<PhylogenyNode>();
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11415             if ( !s0.match( query_nodes ) ) {
11416                 return false;
11417             }
11418             //
11419             query_nodes = new HashSet<PhylogenyNode>();
11420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11422             if ( !s0.match( query_nodes ) ) {
11423                 return false;
11424             }
11425             //
11426             query_nodes = new HashSet<PhylogenyNode>();
11427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11432             if ( !s0.match( query_nodes ) ) {
11433                 return false;
11434             }
11435             //
11436             query_nodes = new HashSet<PhylogenyNode>();
11437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11440             if ( !s0.match( query_nodes ) ) {
11441                 return false;
11442             }
11443             //
11444             query_nodes = new HashSet<PhylogenyNode>();
11445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11449             if ( !s0.match( query_nodes ) ) {
11450                 return false;
11451             }
11452             //
11453             query_nodes = new HashSet<PhylogenyNode>();
11454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11456             if ( s0.match( query_nodes ) ) {
11457                 return false;
11458             }
11459             //
11460             query_nodes = new HashSet<PhylogenyNode>();
11461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11465             if ( s0.match( query_nodes ) ) {
11466                 return false;
11467             }
11468             //
11469             query_nodes = new HashSet<PhylogenyNode>();
11470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11475             if ( s0.match( query_nodes ) ) {
11476                 return false;
11477             }
11478             //
11479             query_nodes = new HashSet<PhylogenyNode>();
11480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11483             if ( s0.match( query_nodes ) ) {
11484                 return false;
11485             }
11486             //
11487             query_nodes = new HashSet<PhylogenyNode>();
11488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11490             if ( s0.match( query_nodes ) ) {
11491                 return false;
11492             }
11493             //
11494             query_nodes = new HashSet<PhylogenyNode>();
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11497             if ( s0.match( query_nodes ) ) {
11498                 return false;
11499             }
11500             //
11501             query_nodes = new HashSet<PhylogenyNode>();
11502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11504             if ( s0.match( query_nodes ) ) {
11505                 return false;
11506             }
11507             //
11508             query_nodes = new HashSet<PhylogenyNode>();
11509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11511             if ( s0.match( query_nodes ) ) {
11512                 return false;
11513             }
11514             //
11515             query_nodes = new HashSet<PhylogenyNode>();
11516             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11517             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11518             if ( s0.match( query_nodes ) ) {
11519                 return false;
11520             }
11521             //
11522             query_nodes = new HashSet<PhylogenyNode>();
11523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11525             if ( s0.match( query_nodes ) ) {
11526                 return false;
11527             }
11528             //
11529             query_nodes = new HashSet<PhylogenyNode>();
11530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11533             if ( s0.match( query_nodes ) ) {
11534                 return false;
11535             }
11536             //
11537             query_nodes = new HashSet<PhylogenyNode>();
11538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11541             if ( s0.match( query_nodes ) ) {
11542                 return false;
11543             }
11544             //
11545             query_nodes = new HashSet<PhylogenyNode>();
11546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11549             if ( s0.match( query_nodes ) ) {
11550                 return false;
11551             }
11552             //
11553             query_nodes = new HashSet<PhylogenyNode>();
11554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11558             if ( s0.match( query_nodes ) ) {
11559                 return false;
11560             }
11561             /////////
11562             //            query_nodes = new HashSet<PhylogenyNode>();
11563             //            query_nodes.add( new PhylogenyNode( "X" ) );
11564             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11565             //            query_nodes.add( new PhylogenyNode( "A" ) );
11566             //            query_nodes.add( new PhylogenyNode( "B" ) );
11567             //            query_nodes.add( new PhylogenyNode( "C" ) );
11568             //            query_nodes.add( new PhylogenyNode( "D" ) );
11569             //            query_nodes.add( new PhylogenyNode( "E" ) );
11570             //            query_nodes.add( new PhylogenyNode( "F" ) );
11571             //            query_nodes.add( new PhylogenyNode( "G" ) );
11572             //            if ( !s0.match( query_nodes ) ) {
11573             //                return false;
11574             //            }
11575             //            query_nodes = new HashSet<PhylogenyNode>();
11576             //            query_nodes.add( new PhylogenyNode( "X" ) );
11577             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11578             //            query_nodes.add( new PhylogenyNode( "A" ) );
11579             //            query_nodes.add( new PhylogenyNode( "B" ) );
11580             //            query_nodes.add( new PhylogenyNode( "C" ) );
11581             //            if ( !s0.match( query_nodes ) ) {
11582             //                return false;
11583             //            }
11584             //            //
11585             //            query_nodes = new HashSet<PhylogenyNode>();
11586             //            query_nodes.add( new PhylogenyNode( "X" ) );
11587             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11588             //            query_nodes.add( new PhylogenyNode( "D" ) );
11589             //            query_nodes.add( new PhylogenyNode( "E" ) );
11590             //            query_nodes.add( new PhylogenyNode( "F" ) );
11591             //            query_nodes.add( new PhylogenyNode( "G" ) );
11592             //            if ( !s0.match( query_nodes ) ) {
11593             //                return false;
11594             //            }
11595             //            //
11596             //            query_nodes = new HashSet<PhylogenyNode>();
11597             //            query_nodes.add( new PhylogenyNode( "X" ) );
11598             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11599             //            query_nodes.add( new PhylogenyNode( "A" ) );
11600             //            query_nodes.add( new PhylogenyNode( "B" ) );
11601             //            query_nodes.add( new PhylogenyNode( "C" ) );
11602             //            query_nodes.add( new PhylogenyNode( "D" ) );
11603             //            if ( !s0.match( query_nodes ) ) {
11604             //                return false;
11605             //            }
11606             //            //
11607             //            query_nodes = new HashSet<PhylogenyNode>();
11608             //            query_nodes.add( new PhylogenyNode( "X" ) );
11609             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11610             //            query_nodes.add( new PhylogenyNode( "E" ) );
11611             //            query_nodes.add( new PhylogenyNode( "F" ) );
11612             //            query_nodes.add( new PhylogenyNode( "G" ) );
11613             //            if ( !s0.match( query_nodes ) ) {
11614             //                return false;
11615             //            }
11616             //            //
11617             //            query_nodes = new HashSet<PhylogenyNode>();
11618             //            query_nodes.add( new PhylogenyNode( "X" ) );
11619             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11620             //            query_nodes.add( new PhylogenyNode( "F" ) );
11621             //            query_nodes.add( new PhylogenyNode( "G" ) );
11622             //            if ( !s0.match( query_nodes ) ) {
11623             //                return false;
11624             //            }
11625             //
11626             query_nodes = new HashSet<PhylogenyNode>();
11627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11631             if ( s0.match( query_nodes ) ) {
11632                 return false;
11633             }
11634             //
11635             query_nodes = new HashSet<PhylogenyNode>();
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11640             if ( s0.match( query_nodes ) ) {
11641                 return false;
11642             }
11643             ///////////////////////////
11644             //
11645             query_nodes = new HashSet<PhylogenyNode>();
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11650             if ( s0.match( query_nodes ) ) {
11651                 return false;
11652             }
11653             //
11654             query_nodes = new HashSet<PhylogenyNode>();
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11659             if ( s0.match( query_nodes ) ) {
11660                 return false;
11661             }
11662             //
11663             query_nodes = new HashSet<PhylogenyNode>();
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11668             if ( s0.match( query_nodes ) ) {
11669                 return false;
11670             }
11671             //
11672             query_nodes = new HashSet<PhylogenyNode>();
11673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11677             if ( s0.match( query_nodes ) ) {
11678                 return false;
11679             }
11680             //
11681             query_nodes = new HashSet<PhylogenyNode>();
11682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11686             if ( s0.match( query_nodes ) ) {
11687                 return false;
11688             }
11689             //
11690             query_nodes = new HashSet<PhylogenyNode>();
11691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11694             if ( s0.match( query_nodes ) ) {
11695                 return false;
11696             }
11697             //
11698             query_nodes = new HashSet<PhylogenyNode>();
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11704             if ( s0.match( query_nodes ) ) {
11705                 return false;
11706             }
11707             //
11708             query_nodes = new HashSet<PhylogenyNode>();
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11714             if ( s0.match( query_nodes ) ) {
11715                 return false;
11716             }
11717             //
11718             query_nodes = new HashSet<PhylogenyNode>();
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11724             if ( s0.match( query_nodes ) ) {
11725                 return false;
11726             }
11727             //
11728             query_nodes = new HashSet<PhylogenyNode>();
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11735             if ( s0.match( query_nodes ) ) {
11736                 return false;
11737             }
11738         }
11739         catch ( final Exception e ) {
11740             e.printStackTrace();
11741             return false;
11742         }
11743         return true;
11744     }
11745
11746     private static boolean testSplitStrict() {
11747         try {
11748             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11749             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11750             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11751             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11752             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11753             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11754             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11755             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11756             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11757             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11758             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11759             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11762             if ( s0.match( query_nodes ) ) {
11763                 return false;
11764             }
11765             query_nodes = new HashSet<PhylogenyNode>();
11766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11769             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11773             if ( !s0.match( query_nodes ) ) {
11774                 return false;
11775             }
11776             //
11777             query_nodes = new HashSet<PhylogenyNode>();
11778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11781             if ( !s0.match( query_nodes ) ) {
11782                 return false;
11783             }
11784             //
11785             query_nodes = new HashSet<PhylogenyNode>();
11786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11790             if ( !s0.match( query_nodes ) ) {
11791                 return false;
11792             }
11793             //
11794             query_nodes = new HashSet<PhylogenyNode>();
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11799             if ( !s0.match( query_nodes ) ) {
11800                 return false;
11801             }
11802             //
11803             query_nodes = new HashSet<PhylogenyNode>();
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11807             if ( !s0.match( query_nodes ) ) {
11808                 return false;
11809             }
11810             //
11811             query_nodes = new HashSet<PhylogenyNode>();
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11814             if ( !s0.match( query_nodes ) ) {
11815                 return false;
11816             }
11817             //
11818             query_nodes = new HashSet<PhylogenyNode>();
11819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11824             if ( !s0.match( query_nodes ) ) {
11825                 return false;
11826             }
11827             //
11828             query_nodes = new HashSet<PhylogenyNode>();
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11832             if ( !s0.match( query_nodes ) ) {
11833                 return false;
11834             }
11835             //
11836             query_nodes = new HashSet<PhylogenyNode>();
11837             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11841             if ( !s0.match( query_nodes ) ) {
11842                 return false;
11843             }
11844             //
11845             query_nodes = new HashSet<PhylogenyNode>();
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11848             if ( s0.match( query_nodes ) ) {
11849                 return false;
11850             }
11851             //
11852             query_nodes = new HashSet<PhylogenyNode>();
11853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11857             if ( s0.match( query_nodes ) ) {
11858                 return false;
11859             }
11860             //
11861             query_nodes = new HashSet<PhylogenyNode>();
11862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11867             if ( s0.match( query_nodes ) ) {
11868                 return false;
11869             }
11870             //
11871             query_nodes = new HashSet<PhylogenyNode>();
11872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11875             if ( s0.match( query_nodes ) ) {
11876                 return false;
11877             }
11878             //
11879             query_nodes = new HashSet<PhylogenyNode>();
11880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11882             if ( s0.match( query_nodes ) ) {
11883                 return false;
11884             }
11885             //
11886             query_nodes = new HashSet<PhylogenyNode>();
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11889             if ( s0.match( query_nodes ) ) {
11890                 return false;
11891             }
11892             //
11893             query_nodes = new HashSet<PhylogenyNode>();
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11896             if ( s0.match( query_nodes ) ) {
11897                 return false;
11898             }
11899             //
11900             query_nodes = new HashSet<PhylogenyNode>();
11901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11903             if ( s0.match( query_nodes ) ) {
11904                 return false;
11905             }
11906             //
11907             query_nodes = new HashSet<PhylogenyNode>();
11908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11910             if ( s0.match( query_nodes ) ) {
11911                 return false;
11912             }
11913             //
11914             query_nodes = new HashSet<PhylogenyNode>();
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11917             if ( s0.match( query_nodes ) ) {
11918                 return false;
11919             }
11920             //
11921             query_nodes = new HashSet<PhylogenyNode>();
11922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11925             if ( s0.match( query_nodes ) ) {
11926                 return false;
11927             }
11928             //
11929             query_nodes = new HashSet<PhylogenyNode>();
11930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11933             if ( s0.match( query_nodes ) ) {
11934                 return false;
11935             }
11936             //
11937             query_nodes = new HashSet<PhylogenyNode>();
11938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11941             if ( s0.match( query_nodes ) ) {
11942                 return false;
11943             }
11944             //
11945             query_nodes = new HashSet<PhylogenyNode>();
11946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11950             if ( s0.match( query_nodes ) ) {
11951                 return false;
11952             }
11953         }
11954         catch ( final Exception e ) {
11955             e.printStackTrace();
11956             return false;
11957         }
11958         return true;
11959     }
11960
11961     private static boolean testSubtreeDeletion() {
11962         try {
11963             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11964             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11965             t1.deleteSubtree( t1.getNode( "A" ), false );
11966             if ( t1.getNumberOfExternalNodes() != 5 ) {
11967                 return false;
11968             }
11969             t1.toNewHampshireX();
11970             t1.deleteSubtree( t1.getNode( "E" ), false );
11971             if ( t1.getNumberOfExternalNodes() != 4 ) {
11972                 return false;
11973             }
11974             t1.toNewHampshireX();
11975             t1.deleteSubtree( t1.getNode( "F" ), false );
11976             if ( t1.getNumberOfExternalNodes() != 3 ) {
11977                 return false;
11978             }
11979             t1.toNewHampshireX();
11980             t1.deleteSubtree( t1.getNode( "D" ), false );
11981             t1.toNewHampshireX();
11982             if ( t1.getNumberOfExternalNodes() != 3 ) {
11983                 return false;
11984             }
11985             t1.deleteSubtree( t1.getNode( "def" ), false );
11986             t1.toNewHampshireX();
11987             if ( t1.getNumberOfExternalNodes() != 2 ) {
11988                 return false;
11989             }
11990             t1.deleteSubtree( t1.getNode( "B" ), false );
11991             t1.toNewHampshireX();
11992             if ( t1.getNumberOfExternalNodes() != 1 ) {
11993                 return false;
11994             }
11995             t1.deleteSubtree( t1.getNode( "C" ), false );
11996             t1.toNewHampshireX();
11997             if ( t1.getNumberOfExternalNodes() != 1 ) {
11998                 return false;
11999             }
12000             t1.deleteSubtree( t1.getNode( "abc" ), false );
12001             t1.toNewHampshireX();
12002             if ( t1.getNumberOfExternalNodes() != 1 ) {
12003                 return false;
12004             }
12005             t1.deleteSubtree( t1.getNode( "r" ), false );
12006             if ( t1.getNumberOfExternalNodes() != 0 ) {
12007                 return false;
12008             }
12009             if ( !t1.isEmpty() ) {
12010                 return false;
12011             }
12012             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12013             t2.deleteSubtree( t2.getNode( "A" ), false );
12014             t2.toNewHampshireX();
12015             if ( t2.getNumberOfExternalNodes() != 5 ) {
12016                 return false;
12017             }
12018             t2.deleteSubtree( t2.getNode( "abc" ), false );
12019             t2.toNewHampshireX();
12020             if ( t2.getNumberOfExternalNodes() != 3 ) {
12021                 return false;
12022             }
12023             t2.deleteSubtree( t2.getNode( "def" ), false );
12024             t2.toNewHampshireX();
12025             if ( t2.getNumberOfExternalNodes() != 1 ) {
12026                 return false;
12027             }
12028         }
12029         catch ( final Exception e ) {
12030             e.printStackTrace( System.out );
12031             return false;
12032         }
12033         return true;
12034     }
12035
12036     private static boolean testSupportCount() {
12037         try {
12038             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12039             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12040             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12041                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12042                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12043                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12044                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12045                                                               new NHXParser() );
12046             SupportCount.count( t0_1, phylogenies_1, true, false );
12047             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12048             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12049                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12050                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12051                                                                       + "(((((A,B),C),D),E),(F,G))"
12052                                                                       + "(((((A,B),C),D),E),(F,G))"
12053                                                                       + "(((((A,B),C),D),E),(F,G))"
12054                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12055                                                                       + "(((((A,B),C),D),E),(F,G))"
12056                                                                       + "((((((A,B),C),D),E),F),G)"
12057                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12058                                                               new NHXParser() );
12059             SupportCount.count( t0_2, phylogenies_2, true, false );
12060             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12061             while ( it.hasNext() ) {
12062                 final PhylogenyNode n = it.next();
12063                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12064                     return false;
12065                 }
12066             }
12067             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12068             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12069                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12070             SupportCount.count( t0_3, phylogenies_3, true, false );
12071             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12072             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12073                 return false;
12074             }
12075             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12076                 return false;
12077             }
12078             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12079                 return false;
12080             }
12081             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12082                 return false;
12083             }
12084             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12085                 return false;
12086             }
12087             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12088                 return false;
12089             }
12090             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12091                 return false;
12092             }
12093             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12094                 return false;
12095             }
12096             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12097                 return false;
12098             }
12099             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12100                 return false;
12101             }
12102             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12103             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12104                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12105             SupportCount.count( t0_4, phylogenies_4, true, false );
12106             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12107             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12108                 return false;
12109             }
12110             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12111                 return false;
12112             }
12113             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12114                 return false;
12115             }
12116             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12117                 return false;
12118             }
12119             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12120                 return false;
12121             }
12122             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12123                 return false;
12124             }
12125             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12126                 return false;
12127             }
12128             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12129                 return false;
12130             }
12131             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12132                 return false;
12133             }
12134             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12135                 return false;
12136             }
12137             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12138             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12139             double d = SupportCount.compare( b1, a, true, true, true );
12140             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12141                 return false;
12142             }
12143             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12144             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12145             d = SupportCount.compare( b2, a, true, true, true );
12146             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12147                 return false;
12148             }
12149             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12150             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12151             d = SupportCount.compare( b3, a, true, true, true );
12152             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12153                 return false;
12154             }
12155             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12156             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12157             d = SupportCount.compare( b4, a, true, true, false );
12158             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12159                 return false;
12160             }
12161         }
12162         catch ( final Exception e ) {
12163             e.printStackTrace( System.out );
12164             return false;
12165         }
12166         return true;
12167     }
12168
12169     private static boolean testSupportTransfer() {
12170         try {
12171             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12172             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)",
12173                                                  new NHXParser() )[ 0 ];
12174             final Phylogeny p2 = factory
12175                     .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 ];
12176             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12177                 return false;
12178             }
12179             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12180                 return false;
12181             }
12182             support_transfer.moveBranchLengthsToBootstrap( p1 );
12183             support_transfer.transferSupportValues( p1, p2 );
12184             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12185                 return false;
12186             }
12187             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12188                 return false;
12189             }
12190             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12191                 return false;
12192             }
12193             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12194                 return false;
12195             }
12196             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12197                 return false;
12198             }
12199             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12200                 return false;
12201             }
12202             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12203                 return false;
12204             }
12205             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12206                 return false;
12207             }
12208         }
12209         catch ( final Exception e ) {
12210             e.printStackTrace( System.out );
12211             return false;
12212         }
12213         return true;
12214     }
12215
12216     private static boolean testTaxonomyExtraction() {
12217         try {
12218             final PhylogenyNode n0 = PhylogenyNode
12219                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12220             if ( n0.getNodeData().isHasTaxonomy() ) {
12221                 return false;
12222             }
12223             final PhylogenyNode n1 = PhylogenyNode
12224                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12225             if ( n1.getNodeData().isHasTaxonomy() ) {
12226                 System.out.println( n1.toString() );
12227                 return false;
12228             }
12229             final PhylogenyNode n2x = PhylogenyNode
12230                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12231             if ( n2x.getNodeData().isHasTaxonomy() ) {
12232                 return false;
12233             }
12234             final PhylogenyNode n3 = PhylogenyNode
12235                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12236             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12237                 System.out.println( n3.toString() );
12238                 return false;
12239             }
12240             final PhylogenyNode n4 = PhylogenyNode
12241                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12242             if ( n4.getNodeData().isHasTaxonomy() ) {
12243                 System.out.println( n4.toString() );
12244                 return false;
12245             }
12246             final PhylogenyNode n5 = PhylogenyNode
12247                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12248             if ( n5.getNodeData().isHasTaxonomy() ) {
12249                 System.out.println( n5.toString() );
12250                 return false;
12251             }
12252             final PhylogenyNode n6 = PhylogenyNode
12253                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12254             if ( n6.getNodeData().isHasTaxonomy() ) {
12255                 System.out.println( n6.toString() );
12256                 return false;
12257             }
12258             final PhylogenyNode n7 = PhylogenyNode
12259                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12260             if ( n7.getNodeData().isHasTaxonomy() ) {
12261                 System.out.println( n7.toString() );
12262                 return false;
12263             }
12264             final PhylogenyNode n8 = PhylogenyNode
12265                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12266             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12267                 System.out.println( n8.toString() );
12268                 return false;
12269             }
12270             final PhylogenyNode n9 = PhylogenyNode
12271                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12272             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12273                 System.out.println( n9.toString() );
12274                 return false;
12275             }
12276             final PhylogenyNode n10x = PhylogenyNode
12277                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12278             if ( n10x.getNodeData().isHasTaxonomy() ) {
12279                 System.out.println( n10x.toString() );
12280                 return false;
12281             }
12282             final PhylogenyNode n10xx = PhylogenyNode
12283                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12284             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12285                 System.out.println( n10xx.toString() );
12286                 return false;
12287             }
12288             final PhylogenyNode n10 = PhylogenyNode
12289                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12290             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12291                 System.out.println( n10.toString() );
12292                 return false;
12293             }
12294             final PhylogenyNode n11 = PhylogenyNode
12295                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12296             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12297                 System.out.println( n11.toString() );
12298                 return false;
12299             }
12300             final PhylogenyNode n12 = PhylogenyNode
12301                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12302                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12303             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12304                 System.out.println( n12.toString() );
12305                 return false;
12306             }
12307             final PhylogenyNode n13 = PhylogenyNode
12308                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12309             if ( n13.getNodeData().isHasTaxonomy() ) {
12310                 System.out.println( n13.toString() );
12311                 return false;
12312             }
12313             final PhylogenyNode n14 = PhylogenyNode
12314                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12315             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12316                 System.out.println( n14.toString() );
12317                 return false;
12318             }
12319             final PhylogenyNode n15 = PhylogenyNode
12320                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12321             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12322                 System.out.println( n15.toString() );
12323                 return false;
12324             }
12325             final PhylogenyNode n16 = PhylogenyNode
12326                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12327             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12328                 System.out.println( n16.toString() );
12329                 return false;
12330             }
12331             final PhylogenyNode n17 = PhylogenyNode
12332                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12333             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12334                 System.out.println( n17.toString() );
12335                 return false;
12336             }
12337             //
12338             final PhylogenyNode n18 = PhylogenyNode
12339                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12340             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12341                 System.out.println( n18.toString() );
12342                 return false;
12343             }
12344             final PhylogenyNode n19 = PhylogenyNode
12345                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12346                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12347             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12348                 System.out.println( n19.toString() );
12349                 return false;
12350             }
12351             final PhylogenyNode n20 = PhylogenyNode
12352                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12353             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12354                 System.out.println( n20.toString() );
12355                 return false;
12356             }
12357             final PhylogenyNode n21 = PhylogenyNode
12358                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12359                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12360             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12361                 System.out.println( n21.toString() );
12362                 return false;
12363             }
12364             final PhylogenyNode n22 = PhylogenyNode
12365                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12366                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12367             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12368                 System.out.println( n22.toString() );
12369                 return false;
12370             }
12371             final PhylogenyNode n23 = PhylogenyNode
12372                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12373                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12374             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12375                 System.out.println( n23.toString() );
12376                 return false;
12377             }
12378             final PhylogenyNode n24 = PhylogenyNode
12379                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12380             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12381                 System.out.println( n24.toString() );
12382                 return false;
12383             }
12384             //
12385             final PhylogenyNode n25 = PhylogenyNode
12386                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12387                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12388             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12389                 System.out.println( n25.toString() );
12390                 return false;
12391             }
12392             final PhylogenyNode n26 = PhylogenyNode
12393                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12394                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12395             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12396                 System.out.println( n26.toString() );
12397                 return false;
12398             }
12399             final PhylogenyNode n27 = PhylogenyNode
12400                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12401             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12402                 System.out.println( n27.toString() );
12403                 return false;
12404             }
12405         }
12406         catch ( final Exception e ) {
12407             e.printStackTrace( System.out );
12408             return false;
12409         }
12410         return true;
12411     }
12412
12413     private static boolean testTreeCopy() {
12414         try {
12415             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12416             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12417             final Phylogeny t1 = t0.copy();
12418             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12419                 return false;
12420             }
12421             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12422                 return false;
12423             }
12424             t0.deleteSubtree( t0.getNode( "c" ), true );
12425             t0.deleteSubtree( t0.getNode( "a" ), true );
12426             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12427             t0.getNode( "b" ).setName( "Bee" );
12428             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12429                 return false;
12430             }
12431             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12432                 return false;
12433             }
12434             t0.deleteSubtree( t0.getNode( "e" ), true );
12435             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12436             t0.deleteSubtree( t0.getNode( "d" ), true );
12437             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12438                 return false;
12439             }
12440         }
12441         catch ( final Exception e ) {
12442             e.printStackTrace();
12443             return false;
12444         }
12445         return true;
12446     }
12447
12448     private static boolean testTreeMethods() {
12449         try {
12450             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12451             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12452             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12453             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12454                 System.out.println( t0.toNewHampshireX() );
12455                 return false;
12456             }
12457             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12458             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12459             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12460                 return false;
12461             }
12462             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12463                 return false;
12464             }
12465             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12466                 return false;
12467             }
12468         }
12469         catch ( final Exception e ) {
12470             e.printStackTrace( System.out );
12471             return false;
12472         }
12473         return true;
12474     }
12475
12476     private static boolean testUniprotEntryRetrieval() {
12477         try {
12478             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12479             if ( !entry.getAccession().equals( "P12345" ) ) {
12480                 return false;
12481             }
12482             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12483                 return false;
12484             }
12485             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12486                 return false;
12487             }
12488             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12489                 return false;
12490             }
12491             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12492                 return false;
12493             }
12494             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12495                 return false;
12496             }
12497         }
12498         catch ( final IOException e ) {
12499             System.out.println();
12500             System.out.println( "the following might be due to absence internet connection:" );
12501             e.printStackTrace( System.out );
12502             return true;
12503         }
12504         catch ( final Exception e ) {
12505             return false;
12506         }
12507         return true;
12508     }
12509
12510     private static boolean testUniprotTaxonomySearch() {
12511         try {
12512             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12513                                                                                                  10 );
12514             if ( results.size() != 1 ) {
12515                 return false;
12516             }
12517             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12518                 return false;
12519             }
12520             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12521                 return false;
12522             }
12523             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12524                 return false;
12525             }
12526             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12527                 return false;
12528             }
12529             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12530                 return false;
12531             }
12532             results = null;
12533             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12534             if ( results.size() != 1 ) {
12535                 return false;
12536             }
12537             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12538                 return false;
12539             }
12540             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12541                 return false;
12542             }
12543             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12544                 return false;
12545             }
12546             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12547                 return false;
12548             }
12549             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12550                 return false;
12551             }
12552             results = null;
12553             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12554             if ( results.size() != 1 ) {
12555                 return false;
12556             }
12557             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12558                 return false;
12559             }
12560             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12561                 return false;
12562             }
12563             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12564                 return false;
12565             }
12566             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12567                 return false;
12568             }
12569             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12570                 return false;
12571             }
12572             results = null;
12573             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12574             if ( results.size() != 1 ) {
12575                 return false;
12576             }
12577             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12578                 return false;
12579             }
12580             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12581                 return false;
12582             }
12583             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12584                 return false;
12585             }
12586             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12587                 return false;
12588             }
12589             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12590                 return false;
12591             }
12592             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12593                 return false;
12594             }
12595             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12596                 return false;
12597             }
12598             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12599                     .equals( "Nematostella vectensis" ) ) {
12600                 System.out.println( results.get( 0 ).getLineage() );
12601                 return false;
12602             }
12603             //
12604             results = null;
12605             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12606             if ( results.size() != 1 ) {
12607                 return false;
12608             }
12609             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12610                 return false;
12611             }
12612             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12613                 return false;
12614             }
12615             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12616                 return false;
12617             }
12618             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12619                 return false;
12620             }
12621             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12622                 return false;
12623             }
12624             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12625                     .equals( "Xenopus tropicalis" ) ) {
12626                 System.out.println( results.get( 0 ).getLineage() );
12627                 return false;
12628             }
12629             //
12630             results = null;
12631             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12632             if ( results.size() != 1 ) {
12633                 return false;
12634             }
12635             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12636                 return false;
12637             }
12638             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12639                 return false;
12640             }
12641             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12642                 return false;
12643             }
12644             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12645                 return false;
12646             }
12647             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12648                 return false;
12649             }
12650             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12651                     .equals( "Xenopus tropicalis" ) ) {
12652                 System.out.println( results.get( 0 ).getLineage() );
12653                 return false;
12654             }
12655             //
12656             results = null;
12657             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12658             if ( results.size() != 1 ) {
12659                 return false;
12660             }
12661             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12662                 return false;
12663             }
12664             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12665                 return false;
12666             }
12667             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12668                 return false;
12669             }
12670             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12671                 return false;
12672             }
12673             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12674                 return false;
12675             }
12676             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12677                     .equals( "Xenopus tropicalis" ) ) {
12678                 System.out.println( results.get( 0 ).getLineage() );
12679                 return false;
12680             }
12681         }
12682         catch ( final IOException e ) {
12683             System.out.println();
12684             System.out.println( "the following might be due to absence internet connection:" );
12685             e.printStackTrace( System.out );
12686             return true;
12687         }
12688         catch ( final Exception e ) {
12689             return false;
12690         }
12691         return true;
12692     }
12693
12694     private static boolean testWabiTxSearch() {
12695         try {
12696             String result = "";
12697             result = TxSearch.searchSimple( "nematostella" );
12698             result = TxSearch.getTxId( "nematostella" );
12699             if ( !result.equals( "45350" ) ) {
12700                 return false;
12701             }
12702             result = TxSearch.getTxName( "45350" );
12703             if ( !result.equals( "Nematostella" ) ) {
12704                 return false;
12705             }
12706             result = TxSearch.getTxId( "nematostella vectensis" );
12707             if ( !result.equals( "45351" ) ) {
12708                 return false;
12709             }
12710             result = TxSearch.getTxName( "45351" );
12711             if ( !result.equals( "Nematostella vectensis" ) ) {
12712                 return false;
12713             }
12714             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12715             if ( !result.equals( "536089" ) ) {
12716                 return false;
12717             }
12718             result = TxSearch.getTxName( "536089" );
12719             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12720                 return false;
12721             }
12722             final List<String> queries = new ArrayList<String>();
12723             queries.add( "Campylobacter coli" );
12724             queries.add( "Escherichia coli" );
12725             queries.add( "Arabidopsis" );
12726             queries.add( "Trichoplax" );
12727             queries.add( "Samanea saman" );
12728             queries.add( "Kluyveromyces marxianus" );
12729             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12730             queries.add( "Bornavirus parrot/PDD/2008" );
12731             final List<RANKS> ranks = new ArrayList<RANKS>();
12732             ranks.add( RANKS.SUPERKINGDOM );
12733             ranks.add( RANKS.KINGDOM );
12734             ranks.add( RANKS.FAMILY );
12735             ranks.add( RANKS.GENUS );
12736             ranks.add( RANKS.TRIBE );
12737             result = TxSearch.searchLineage( queries, ranks );
12738             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12739             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12740         }
12741         catch ( final Exception e ) {
12742             System.out.println();
12743             System.out.println( "the following might be due to absence internet connection:" );
12744             e.printStackTrace( System.out );
12745             return false;
12746         }
12747         return true;
12748     }
12749 }