14c18efbf2bf0ba88c3eeda01e38e0f6d6622622
[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.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesMap;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.MolecularSequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128 import org.forester.ws.wabi.TxSearch;
129 import org.forester.ws.wabi.TxSearch.RANKS;
130 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
131 import org.forester.ws.wabi.TxSearch.TAX_RANK;
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137                                                                    + ForesterUtil.getFileSeparator() + "resources"
138                                                                    + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140                                                                    + ForesterUtil.getFileSeparator() + "test_data"
141                                                                    + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = false;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
146                                                                    + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
149                                                                    + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     public static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                 + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         
185      
186         
187         System.out.print( "MSA entropy: " );
188         if ( Test.testMsaEntropy() ) {
189             System.out.println( "OK." );
190             succeeded++;
191         }
192         else {
193             System.out.println( "failed." );
194             failed++;
195         }
196         System.out.print( "Basic node methods: " );
197         if ( Test.testBasicNodeMethods() ) {
198             System.out.println( "OK." );
199             succeeded++;
200         }
201         else {
202             System.out.println( "failed." );
203             failed++;
204         }
205         System.out.print( "Protein id: " );
206         if ( !testProteinId() ) {
207             System.out.println( "failed." );
208             failed++;
209         }
210         else {
211             succeeded++;
212         }
213         System.out.println( "OK." );
214         System.out.print( "Species: " );
215         if ( !testSpecies() ) {
216             System.out.println( "failed." );
217             failed++;
218         }
219         else {
220             succeeded++;
221         }
222         System.out.println( "OK." );
223         System.out.print( "Basic domain: " );
224         if ( !testBasicDomain() ) {
225             System.out.println( "failed." );
226             failed++;
227         }
228         else {
229             succeeded++;
230         }
231         System.out.println( "OK." );
232         System.out.print( "Basic protein: " );
233         if ( !testBasicProtein() ) {
234             System.out.println( "failed." );
235             failed++;
236         }
237         else {
238             succeeded++;
239         }
240         System.out.println( "OK." );
241         System.out.print( "Sequence writer: " );
242         if ( testSequenceWriter() ) {
243             System.out.println( "OK." );
244             succeeded++;
245         }
246         else {
247             System.out.println( "failed." );
248             failed++;
249         }
250         System.out.print( "Sequence id parsing: " );
251         if ( testSequenceIdParsing() ) {
252             System.out.println( "OK." );
253             succeeded++;
254         }
255         else {
256             System.out.println( "failed." );
257             failed++;
258         }
259         System.out.print( "UniProtKB id extraction: " );
260         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
261             System.out.println( "OK." );
262             succeeded++;
263         }
264         else {
265             System.out.println( "failed." );
266             failed++;
267         }
268         System.out.print( "Sequence DB tools 1: " );
269         if ( testSequenceDbWsTools1() ) {
270             System.out.println( "OK." );
271             succeeded++;
272         }
273         else {
274             System.out.println( "failed." );
275             failed++;
276         }
277         System.out.print( "Hmmscan output parser: " );
278         if ( testHmmscanOutputParser() ) {
279             System.out.println( "OK." );
280             succeeded++;
281         }
282         else {
283             System.out.println( "failed." );
284             failed++;
285         }
286         System.out.print( "Overlap removal: " );
287         if ( !org.forester.test.Test.testOverlapRemoval() ) {
288             System.out.println( "failed." );
289             failed++;
290         }
291         else {
292             succeeded++;
293         }
294         System.out.println( "OK." );
295         System.out.print( "Engulfing overlap removal: " );
296         if ( !Test.testEngulfingOverlapRemoval() ) {
297             System.out.println( "failed." );
298             failed++;
299         }
300         else {
301             succeeded++;
302         }
303         System.out.println( "OK." );
304         System.out.print( "Taxonomy data extraction: " );
305         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
306             System.out.println( "OK." );
307             succeeded++;
308         }
309         else {
310             System.out.println( "failed." );
311             failed++;
312         }
313         System.out.print( "Taxonomy code extraction: " );
314         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
315             System.out.println( "OK." );
316             succeeded++;
317         }
318         else {
319             System.out.println( "failed." );
320             failed++;
321         }
322         System.out.print( "SN extraction: " );
323         if ( Test.testExtractSNFromNodeName() ) {
324             System.out.println( "OK." );
325             succeeded++;
326         }
327         else {
328             System.out.println( "failed." );
329             failed++;
330         }
331         System.out.print( "Taxonomy extraction (general): " );
332         if ( Test.testTaxonomyExtraction() ) {
333             System.out.println( "OK." );
334             succeeded++;
335         }
336         else {
337             System.out.println( "failed." );
338             failed++;
339         }
340         System.out.print( "Uri for Aptx web sequence accession: " );
341         if ( Test.testCreateUriForSeqWeb() ) {
342             System.out.println( "OK." );
343             succeeded++;
344         }
345         else {
346             System.out.println( "failed." );
347             failed++;
348         }
349         System.out.print( "Basic node construction and parsing of NHX (node level): " );
350         if ( Test.testNHXNodeParsing() ) {
351             System.out.println( "OK." );
352             succeeded++;
353         }
354         else {
355             System.out.println( "failed." );
356             failed++;
357         }
358         System.out.print( "NHX parsing iterating: " );
359         if ( Test.testNHParsingIter() ) {
360             System.out.println( "OK." );
361             succeeded++;
362         }
363         else {
364             System.out.println( "failed." );
365             failed++;
366         }
367         System.out.print( "NH parsing: " );
368         if ( Test.testNHParsing() ) {
369             System.out.println( "OK." );
370             succeeded++;
371         }
372         else {
373             System.out.println( "failed." );
374             failed++;
375         }
376         System.out.print( "Conversion to NHX (node level): " );
377         if ( Test.testNHXconversion() ) {
378             System.out.println( "OK." );
379             succeeded++;
380         }
381         else {
382             System.out.println( "failed." );
383             failed++;
384         }
385         System.out.print( "NHX parsing: " );
386         if ( Test.testNHXParsing() ) {
387             System.out.println( "OK." );
388             succeeded++;
389         }
390         else {
391             System.out.println( "failed." );
392             failed++;
393         }
394         System.out.print( "NHX parsing with quotes: " );
395         if ( Test.testNHXParsingQuotes() ) {
396             System.out.println( "OK." );
397             succeeded++;
398         }
399         else {
400             System.out.println( "failed." );
401             failed++;
402         }
403         System.out.print( "NHX parsing (MrBayes): " );
404         if ( Test.testNHXParsingMB() ) {
405             System.out.println( "OK." );
406             succeeded++;
407         }
408         else {
409             System.out.println( "failed." );
410             failed++;
411         }
412         System.out.print( "Nexus characters parsing: " );
413         if ( Test.testNexusCharactersParsing() ) {
414             System.out.println( "OK." );
415             succeeded++;
416         }
417         else {
418             System.out.println( "failed." );
419             failed++;
420         }
421         System.out.print( "Nexus tree parsing iterating: " );
422         if ( Test.testNexusTreeParsingIterating() ) {
423             System.out.println( "OK." );
424             succeeded++;
425         }
426         else {
427             System.out.println( "failed." );
428             failed++;
429         }
430         System.out.print( "Nexus tree parsing: " );
431         if ( Test.testNexusTreeParsing() ) {
432             System.out.println( "OK." );
433             succeeded++;
434         }
435         else {
436             System.out.println( "failed." );
437             failed++;
438         }
439         System.out.print( "Nexus tree parsing (translating): " );
440         if ( Test.testNexusTreeParsingTranslating() ) {
441             System.out.println( "OK." );
442             succeeded++;
443         }
444         else {
445             System.out.println( "failed." );
446             failed++;
447         }
448         System.out.print( "Nexus matrix parsing: " );
449         if ( Test.testNexusMatrixParsing() ) {
450             System.out.println( "OK." );
451             succeeded++;
452         }
453         else {
454             System.out.println( "failed." );
455             failed++;
456         }
457         System.out.print( "Basic phyloXML parsing: " );
458         if ( Test.testBasicPhyloXMLparsing() ) {
459             System.out.println( "OK." );
460             succeeded++;
461         }
462         else {
463             System.out.println( "failed." );
464             failed++;
465         }
466         System.out.print( "Basic phyloXML parsing (validating against schema): " );
467         if ( testBasicPhyloXMLparsingValidating() ) {
468             System.out.println( "OK." );
469             succeeded++;
470         }
471         else {
472             System.out.println( "failed." );
473             failed++;
474         }
475         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
476         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
477             System.out.println( "OK." );
478             succeeded++;
479         }
480         else {
481             System.out.println( "failed." );
482             failed++;
483         }
484         System.out.print( "phyloXML Distribution Element: " );
485         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
486             System.out.println( "OK." );
487             succeeded++;
488         }
489         else {
490             System.out.println( "failed." );
491             failed++;
492         }
493         System.out.print( "Tol XML parsing: " );
494         if ( Test.testBasicTolXMLparsing() ) {
495             System.out.println( "OK." );
496             succeeded++;
497         }
498         else {
499             System.out.println( "failed." );
500             failed++;
501         }
502         System.out.print( "Copying of node data: " );
503         if ( Test.testCopyOfNodeData() ) {
504             System.out.println( "OK." );
505             succeeded++;
506         }
507         else {
508             System.out.println( "failed." );
509             failed++;
510         }
511         System.out.print( "Tree copy: " );
512         if ( Test.testTreeCopy() ) {
513             System.out.println( "OK." );
514             succeeded++;
515         }
516         else {
517             System.out.println( "failed." );
518             failed++;
519         }
520         System.out.print( "Basic tree methods: " );
521         if ( Test.testBasicTreeMethods() ) {
522             System.out.println( "OK." );
523             succeeded++;
524         }
525         else {
526             System.out.println( "failed." );
527             failed++;
528         }
529         System.out.print( "Tree methods: " );
530         if ( Test.testTreeMethods() ) {
531             System.out.println( "OK." );
532             succeeded++;
533         }
534         else {
535             System.out.println( "failed." );
536             failed++;
537         }
538         System.out.print( "Postorder Iterator: " );
539         if ( Test.testPostOrderIterator() ) {
540             System.out.println( "OK." );
541             succeeded++;
542         }
543         else {
544             System.out.println( "failed." );
545             failed++;
546         }
547         System.out.print( "Preorder Iterator: " );
548         if ( Test.testPreOrderIterator() ) {
549             System.out.println( "OK." );
550             succeeded++;
551         }
552         else {
553             System.out.println( "failed." );
554             failed++;
555         }
556         System.out.print( "Levelorder Iterator: " );
557         if ( Test.testLevelOrderIterator() ) {
558             System.out.println( "OK." );
559             succeeded++;
560         }
561         else {
562             System.out.println( "failed." );
563             failed++;
564         }
565         System.out.print( "Re-id methods: " );
566         if ( Test.testReIdMethods() ) {
567             System.out.println( "OK." );
568             succeeded++;
569         }
570         else {
571             System.out.println( "failed." );
572             failed++;
573         }
574         System.out.print( "Methods on last external nodes: " );
575         if ( Test.testLastExternalNodeMethods() ) {
576             System.out.println( "OK." );
577             succeeded++;
578         }
579         else {
580             System.out.println( "failed." );
581             failed++;
582         }
583         System.out.print( "Methods on external nodes: " );
584         if ( Test.testExternalNodeRelatedMethods() ) {
585             System.out.println( "OK." );
586             succeeded++;
587         }
588         else {
589             System.out.println( "failed." );
590             failed++;
591         }
592         System.out.print( "Deletion of external nodes: " );
593         if ( Test.testDeletionOfExternalNodes() ) {
594             System.out.println( "OK." );
595             succeeded++;
596         }
597         else {
598             System.out.println( "failed." );
599             failed++;
600         }
601         System.out.print( "Subtree deletion: " );
602         if ( Test.testSubtreeDeletion() ) {
603             System.out.println( "OK." );
604             succeeded++;
605         }
606         else {
607             System.out.println( "failed." );
608             failed++;
609         }
610         System.out.print( "Phylogeny branch: " );
611         if ( Test.testPhylogenyBranch() ) {
612             System.out.println( "OK." );
613             succeeded++;
614         }
615         else {
616             System.out.println( "failed." );
617             failed++;
618         }
619         System.out.print( "Rerooting: " );
620         if ( Test.testRerooting() ) {
621             System.out.println( "OK." );
622             succeeded++;
623         }
624         else {
625             System.out.println( "failed." );
626             failed++;
627         }
628         System.out.print( "Mipoint rooting: " );
629         if ( Test.testMidpointrooting() ) {
630             System.out.println( "OK." );
631             succeeded++;
632         }
633         else {
634             System.out.println( "failed." );
635             failed++;
636         }
637         System.out.print( "Node removal: " );
638         if ( Test.testNodeRemoval() ) {
639             System.out.println( "OK." );
640             succeeded++;
641         }
642         else {
643             System.out.println( "failed." );
644             failed++;
645         }
646         System.out.print( "Support count: " );
647         if ( Test.testSupportCount() ) {
648             System.out.println( "OK." );
649             succeeded++;
650         }
651         else {
652             System.out.println( "failed." );
653             failed++;
654         }
655         System.out.print( "Support transfer: " );
656         if ( Test.testSupportTransfer() ) {
657             System.out.println( "OK." );
658             succeeded++;
659         }
660         else {
661             System.out.println( "failed." );
662             failed++;
663         }
664         System.out.print( "Finding of LCA: " );
665         if ( Test.testGetLCA() ) {
666             System.out.println( "OK." );
667             succeeded++;
668         }
669         else {
670             System.out.println( "failed." );
671             failed++;
672         }
673         System.out.print( "Finding of LCA 2: " );
674         if ( Test.testGetLCA2() ) {
675             System.out.println( "OK." );
676             succeeded++;
677         }
678         else {
679             System.out.println( "failed." );
680             failed++;
681         }
682         System.out.print( "Calculation of distance between nodes: " );
683         if ( Test.testGetDistance() ) {
684             System.out.println( "OK." );
685             succeeded++;
686         }
687         else {
688             System.out.println( "failed." );
689             failed++;
690         }
691         System.out.print( "Descriptive statistics: " );
692         if ( Test.testDescriptiveStatistics() ) {
693             System.out.println( "OK." );
694             succeeded++;
695         }
696         else {
697             System.out.println( "failed." );
698             failed++;
699         }
700         System.out.print( "Data objects and methods: " );
701         if ( Test.testDataObjects() ) {
702             System.out.println( "OK." );
703             succeeded++;
704         }
705         else {
706             System.out.println( "failed." );
707             failed++;
708         }
709         System.out.print( "Properties map: " );
710         if ( Test.testPropertiesMap() ) {
711             System.out.println( "OK." );
712             succeeded++;
713         }
714         else {
715             System.out.println( "failed." );
716             failed++;
717         }
718         System.out.print( "SDIse: " );
719         if ( Test.testSDIse() ) {
720             System.out.println( "OK." );
721             succeeded++;
722         }
723         else {
724             System.out.println( "failed." );
725             failed++;
726         }
727         System.out.print( "SDIunrooted: " );
728         if ( Test.testSDIunrooted() ) {
729             System.out.println( "OK." );
730             succeeded++;
731         }
732         else {
733             System.out.println( "failed." );
734             failed++;
735         }
736         System.out.print( "GSDI: " );
737         if ( TestGSDI.test() ) {
738             System.out.println( "OK." );
739             succeeded++;
740         }
741         else {
742             System.out.println( "failed." );
743             failed++;
744         }
745         System.out.print( "RIO: " );
746         if ( TestRIO.test() ) {
747             System.out.println( "OK." );
748             succeeded++;
749         }
750         else {
751             System.out.println( "failed." );
752             failed++;
753         }
754         System.out.print( "Phylogeny reconstruction:" );
755         System.out.println();
756         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.print( "Analysis of domain architectures: " );
765         System.out.println();
766         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "GO: " );
775         System.out.println();
776         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
777             System.out.println( "OK." );
778             succeeded++;
779         }
780         else {
781             System.out.println( "failed." );
782             failed++;
783         }
784         System.out.print( "Modeling tools: " );
785         if ( TestPccx.test() ) {
786             System.out.println( "OK." );
787             succeeded++;
788         }
789         else {
790             System.out.println( "failed." );
791             failed++;
792         }
793         System.out.print( "Split Matrix strict: " );
794         if ( Test.testSplitStrict() ) {
795             System.out.println( "OK." );
796             succeeded++;
797         }
798         else {
799             System.out.println( "failed." );
800             failed++;
801         }
802         System.out.print( "Split Matrix: " );
803         if ( Test.testSplit() ) {
804             System.out.println( "OK." );
805             succeeded++;
806         }
807         else {
808             System.out.println( "failed." );
809             failed++;
810         }
811         System.out.print( "Confidence Assessor: " );
812         if ( Test.testConfidenceAssessor() ) {
813             System.out.println( "OK." );
814             succeeded++;
815         }
816         else {
817             System.out.println( "failed." );
818             failed++;
819         }
820         System.out.print( "Basic table: " );
821         if ( Test.testBasicTable() ) {
822             System.out.println( "OK." );
823             succeeded++;
824         }
825         else {
826             System.out.println( "failed." );
827             failed++;
828         }
829         System.out.print( "General table: " );
830         if ( Test.testGeneralTable() ) {
831             System.out.println( "OK." );
832             succeeded++;
833         }
834         else {
835             System.out.println( "failed." );
836             failed++;
837         }
838         System.out.print( "Amino acid sequence: " );
839         if ( Test.testAminoAcidSequence() ) {
840             System.out.println( "OK." );
841             succeeded++;
842         }
843         else {
844             System.out.println( "failed." );
845             failed++;
846         }
847         System.out.print( "General MSA parser: " );
848         if ( Test.testGeneralMsaParser() ) {
849             System.out.println( "OK." );
850             succeeded++;
851         }
852         else {
853             System.out.println( "failed." );
854             failed++;
855         }
856         System.out.print( "Fasta parser for msa: " );
857         if ( Test.testFastaParser() ) {
858             System.out.println( "OK." );
859             succeeded++;
860         }
861         else {
862             System.out.println( "failed." );
863             failed++;
864         }
865         System.out.print( "Creation of balanced phylogeny: " );
866         if ( Test.testCreateBalancedPhylogeny() ) {
867             System.out.println( "OK." );
868             succeeded++;
869         }
870         else {
871             System.out.println( "failed." );
872             failed++;
873         }
874         System.out.print( "Genbank accessor parsing: " );
875         if ( Test.testGenbankAccessorParsing() ) {
876             System.out.println( "OK." );
877             succeeded++;
878         }
879         else {
880             System.out.println( "failed." );
881             failed++;
882         }
883         String path = "";
884         final String os = ForesterUtil.OS_NAME.toLowerCase();
885         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
886             path = "/usr/local/bin/mafft";
887         }
888         else if ( os.indexOf( "win" ) >= 0 ) {
889             path = "C:\\Program Files\\mafft-win\\mafft.bat";
890         }
891         else {
892             path = "mafft";
893             if ( !MsaInferrer.isInstalled( path ) ) {
894                 path = "/usr/bin/mafft";
895             }
896             if ( !MsaInferrer.isInstalled( path ) ) {
897                 path = "/usr/local/bin/mafft";
898             }
899         }
900         if ( MsaInferrer.isInstalled( path ) ) {
901             System.out.print( "MAFFT (external program): " );
902             if ( Test.testMafft( path ) ) {
903                 System.out.println( "OK." );
904                 succeeded++;
905             }
906             else {
907                 System.out.println( "failed [will not count towards failed tests]" );
908             }
909         }
910         System.out.print( "Next nodes with collapsed: " );
911         if ( Test.testNextNodeWithCollapsing() ) {
912             System.out.println( "OK." );
913             succeeded++;
914         }
915         else {
916             System.out.println( "failed." );
917             failed++;
918         }
919         System.out.print( "Simple MSA quality: " );
920         if ( Test.testMsaQualityMethod() ) {
921             System.out.println( "OK." );
922             succeeded++;
923         }
924         else {
925             System.out.println( "failed." );
926             failed++;
927         }
928         System.out.print( "Deleteable MSA: " );
929         if ( Test.testDeleteableMsa() ) {
930             System.out.println( "OK." );
931             succeeded++;
932         }
933         else {
934             System.out.println( "failed." );
935             failed++;
936         }
937         if ( PERFORM_DB_TESTS ) {
938             System.out.print( "Uniprot Entry Retrieval: " );
939             if ( Test.testUniprotEntryRetrieval() ) {
940                 System.out.println( "OK." );
941                 succeeded++;
942             }
943             else {
944                 System.out.println( "failed." );
945                 failed++;
946             }
947             System.out.print( "Ebi Entry Retrieval: " );
948             if ( Test.testEbiEntryRetrieval() ) {
949                 System.out.println( "OK." );
950                 succeeded++;
951             }
952             else {
953                 System.out.println( "failed." );
954                 failed++;
955             }
956             System.out.print( "Sequence DB tools 2: " );
957             if ( testSequenceDbWsTools2() ) {
958                 System.out.println( "OK." );
959                 succeeded++;
960             }
961             else {
962                 System.out.println( "failed." );
963                 failed++;
964                 System.exit( -1 );
965             }
966             System.out.print( "Uniprot Taxonomy Search: " );
967             if ( Test.testUniprotTaxonomySearch() ) {
968                 System.out.println( "OK." );
969                 succeeded++;
970             }
971             else {
972                 System.out.println( "failed." );
973                 failed++;
974             }
975         }
976         if ( PERFORM_WEB_TREE_ACCESS ) {
977             System.out.print( "NHX parsing from URL: " );
978             if ( Test.testNHXparsingFromURL() ) {
979                 System.out.println( "OK." );
980                 succeeded++;
981             }
982             else {
983                 System.out.println( "failed." );
984                 failed++;
985             }
986             System.out.print( "NHX parsing from URL 2: " );
987             if ( Test.testNHXparsingFromURL2() ) {
988                 System.out.println( "OK." );
989                 succeeded++;
990             }
991             else {
992                 System.out.println( "failed." );
993                 failed++;
994             }
995             System.out.print( "phyloXML parsing from URL: " );
996             if ( Test.testPhyloXMLparsingFromURL() ) {
997                 System.out.println( "OK." );
998                 succeeded++;
999             }
1000             else {
1001                 System.out.println( "failed." );
1002                 failed++;
1003             }
1004             System.out.print( "TreeBase acccess: " );
1005             if ( Test.testTreeBaseReading() ) {
1006                 System.out.println( "OK." );
1007                 succeeded++;
1008             }
1009             else {
1010                 System.out.println( "failed." );
1011                 failed++;
1012             }
1013             //
1014             System.out.print( "ToL access: " );
1015             if ( Test.testToLReading() ) {
1016                 System.out.println( "OK." );
1017                 succeeded++;
1018             }
1019             else {
1020                 System.out.println( "failed." );
1021                 failed++;
1022             }
1023             //
1024             System.out.print( "TreeFam access: " );
1025             if ( Test.testTreeFamReading() ) {
1026                 System.out.println( "OK." );
1027                 succeeded++;
1028             }
1029             else {
1030                 System.out.println( "failed." );
1031                 failed++;
1032             }
1033             //
1034             //
1035             System.out.print( "Pfam tree access: " );
1036             if ( Test.testPfamTreeReading() ) {
1037                 System.out.println( "OK." );
1038                 succeeded++;
1039             }
1040             else {
1041                 System.out.println( "failed." );
1042                 failed++;
1043             }
1044         }
1045         System.out.println();
1046         final Runtime rt = java.lang.Runtime.getRuntime();
1047         final long free_memory = rt.freeMemory() / 1000000;
1048         final long total_memory = rt.totalMemory() / 1000000;
1049         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1050                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1051         System.out.println();
1052         System.out.println( "Successful tests: " + succeeded );
1053         System.out.println( "Failed     tests: " + failed );
1054         System.out.println();
1055         if ( failed < 1 ) {
1056             System.out.println( "OK." );
1057         }
1058         else {
1059             System.out.println( "Not OK." );
1060         }
1061     }
1062
1063     public static boolean testEngulfingOverlapRemoval() {
1064         try {
1065             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1067             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1068             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1069             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1070             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1071             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1072             final List<Boolean> covered = new ArrayList<Boolean>();
1073             covered.add( true ); // 0
1074             covered.add( false ); // 1
1075             covered.add( true ); // 2
1076             covered.add( false ); // 3
1077             covered.add( true ); // 4
1078             covered.add( true ); // 5
1079             covered.add( false ); // 6
1080             covered.add( true ); // 7
1081             covered.add( true ); // 8
1082             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1086                 return false;
1087             }
1088             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1089                 return false;
1090             }
1091             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1092                 return false;
1093             }
1094             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1095                 return false;
1096             }
1097             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1098                 return false;
1099             }
1100             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1101                 return false;
1102             }
1103             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1104             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1105             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1106             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1107             abc.addProteinDomain( a );
1108             abc.addProteinDomain( b );
1109             abc.addProteinDomain( c );
1110             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1111             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1112             if ( abc.getNumberOfProteinDomains() != 3 ) {
1113                 return false;
1114             }
1115             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1116                 return false;
1117             }
1118             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1119                 return false;
1120             }
1121             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1122                 return false;
1123             }
1124             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1125                 return false;
1126             }
1127             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1128             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1129             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1130             final Protein def = new BasicProtein( "def", "nemve", 0 );
1131             def.addProteinDomain( d );
1132             def.addProteinDomain( e );
1133             def.addProteinDomain( f );
1134             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1135             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1136             if ( def.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1140                 return false;
1141             }
1142             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1146                 return false;
1147             }
1148             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1149                 return false;
1150             }
1151             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1152                 return false;
1153             }
1154         }
1155         catch ( final Exception e ) {
1156             e.printStackTrace( System.out );
1157             return false;
1158         }
1159         return true;
1160     }
1161
1162     public static final boolean testNHXparsingFromURL2() {
1163         try {
1164             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1165             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1166                                                                       false,
1167                                                                       false,
1168                                                                       false,
1169                                                                       TAXONOMY_EXTRACTION.NO,
1170                                                                       false );
1171             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1172                 return false;
1173             }
1174             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1175                 System.out.println( phys[ 0 ].toNewHampshire() );
1176                 return false;
1177             }
1178             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1179                 System.out.println( phys[ 1 ].toNewHampshire() );
1180                 return false;
1181             }
1182             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1183                                                                        false,
1184                                                                        false,
1185                                                                        false,
1186                                                                        TAXONOMY_EXTRACTION.NO,
1187                                                                        false );
1188             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1189                 return false;
1190             }
1191             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1192                 System.out.println( phys2[ 0 ].toNewHampshire() );
1193                 return false;
1194             }
1195             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1196                 System.out.println( phys2[ 1 ].toNewHampshire() );
1197                 return false;
1198             }
1199             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1200                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1201             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1202                 return false;
1203             }
1204             if ( !phys3[ 0 ]
1205                     .toNewHampshire()
1206                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1207                 System.out.println( phys3[ 0 ].toNewHampshire() );
1208                 return false;
1209             }
1210             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1211                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1212             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1213                 return false;
1214             }
1215             if ( !phys4[ 0 ]
1216                     .toNewHampshire()
1217                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1218                 System.out.println( phys4[ 0 ].toNewHampshire() );
1219                 return false;
1220             }
1221         }
1222         catch ( final Exception e ) {
1223             e.printStackTrace();
1224             return false;
1225         }
1226         return true;
1227     }
1228
1229     public static final boolean testNHXparsingFromURL() {
1230         try {
1231             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1232             final URL u = new URL( s );
1233             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1234             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1235             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1236                 return false;
1237             }
1238             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1239                 System.out.println( phys[ 0 ].toNewHampshire() );
1240                 return false;
1241             }
1242             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1243                 System.out.println( phys[ 1 ].toNewHampshire() );
1244                 return false;
1245             }
1246             
1247             final URL u2 = new URL( s );
1248             
1249             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1250             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1251                 return false;
1252             }
1253             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1254                 System.out.println( phys2[ 0 ].toNewHampshire() );
1255                 return false;
1256             }
1257             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1258             final NHXParser p = new NHXParser();
1259             final URL u3 = new URL( s );
1260             p.setSource( u3 );
1261             if ( !p.hasNext() ) {
1262                 return false;
1263             }
1264             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1265                 return false;
1266             }
1267             if ( !p.hasNext() ) {
1268                 return false;
1269             }
1270             p.reset();
1271             if ( !p.hasNext() ) {
1272                 return false;
1273             }
1274             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1275                 return false;
1276             }
1277             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1278                 return false;
1279             }
1280             p.reset();
1281             if ( !p.hasNext() ) {
1282                 return false;
1283             }
1284             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1285                 return false;
1286             }
1287             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1288                 return false;
1289             }
1290         }
1291         catch ( final Exception e ) {
1292             System.out.println( e.toString());
1293             e.printStackTrace();
1294             return false;
1295         }
1296         return true;
1297     }
1298
1299     public static boolean testOverlapRemoval() {
1300         try {
1301             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1302             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1303             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1304             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1305             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1306             final List<Boolean> covered = new ArrayList<Boolean>();
1307             covered.add( true ); // 0
1308             covered.add( false ); // 1
1309             covered.add( true ); // 2
1310             covered.add( false ); // 3
1311             covered.add( true ); // 4
1312             covered.add( true ); // 5
1313             covered.add( false ); // 6
1314             covered.add( true ); // 7
1315             covered.add( true ); // 8
1316             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1317                 return false;
1318             }
1319             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1320                 return false;
1321             }
1322             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1323                 return false;
1324             }
1325             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1326                 return false;
1327             }
1328             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1329                 return false;
1330             }
1331             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1332             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1333             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1334             ab.addProteinDomain( a );
1335             ab.addProteinDomain( b );
1336             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1337             if ( ab.getNumberOfProteinDomains() != 2 ) {
1338                 return false;
1339             }
1340             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1341                 return false;
1342             }
1343             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1344                 return false;
1345             }
1346             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1347             if ( ab.getNumberOfProteinDomains() != 2 ) {
1348                 return false;
1349             }
1350             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1351                 return false;
1352             }
1353             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1354             final Domain d = new BasicDomain( "d",
1355                                               ( short ) 10000,
1356                                               ( short ) 10500,
1357                                               ( short ) 1,
1358                                               ( short ) 1,
1359                                               0.0000001,
1360                                               1 );
1361             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1362             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1363             cde.addProteinDomain( c );
1364             cde.addProteinDomain( d );
1365             cde.addProteinDomain( e );
1366             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1367             if ( cde.getNumberOfProteinDomains() != 3 ) {
1368                 return false;
1369             }
1370             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1371                 return false;
1372             }
1373             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1374             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1375             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1376             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1377             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1378             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1379             fghi.addProteinDomain( f );
1380             fghi.addProteinDomain( g );
1381             fghi.addProteinDomain( h );
1382             fghi.addProteinDomain( i );
1383             fghi.addProteinDomain( i );
1384             fghi.addProteinDomain( i );
1385             fghi.addProteinDomain( i2 );
1386             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1387             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1388                 return false;
1389             }
1390             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1391                 return false;
1392             }
1393             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1394                 return false;
1395             }
1396             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1397             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1398                 return false;
1399             }
1400             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1401                 return false;
1402             }
1403             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1404             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1405             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1406             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1407             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1408             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1409             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1410             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1411             jklm.addProteinDomain( j );
1412             jklm.addProteinDomain( k );
1413             jklm.addProteinDomain( l );
1414             jklm.addProteinDomain( m );
1415             jklm.addProteinDomain( m0 );
1416             jklm.addProteinDomain( m1 );
1417             jklm.addProteinDomain( m2 );
1418             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1419             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1420                 return false;
1421             }
1422             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1423                 return false;
1424             }
1425             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1426                 return false;
1427             }
1428             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1429             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1430                 return false;
1431             }
1432             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1433                 return false;
1434             }
1435             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1436             final Protein od = new BasicProtein( "od", "varanus", 0 );
1437             od.addProteinDomain( only );
1438             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1439             if ( od.getNumberOfProteinDomains() != 1 ) {
1440                 return false;
1441             }
1442             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1443                 return false;
1444             }
1445         }
1446         catch ( final Exception e ) {
1447             e.printStackTrace( System.out );
1448             return false;
1449         }
1450         return true;
1451     }
1452
1453     public static final boolean testPfamTreeReading() {
1454         try {
1455             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1456             final NHXParser parser = new NHXParser();
1457             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1458             parser.setReplaceUnderscores( false );
1459             parser.setGuessRootedness( true );
1460             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1461             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1462             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1463                 return false;
1464             }
1465             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1466                 return false;
1467             }
1468         }
1469         catch ( final Exception e ) {
1470             e.printStackTrace();
1471         }
1472         return true;
1473     }
1474
1475     public static final boolean testPhyloXMLparsingFromURL() {
1476         try {
1477             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1478             final URL u = new URL( s );
1479             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1480             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1481             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1482                 return false;
1483             }
1484         }
1485         catch ( final Exception e ) {
1486             e.printStackTrace();
1487         }
1488         return true;
1489     }
1490
1491     public static final boolean testToLReading() {
1492         try {
1493             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1494             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1495             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1496             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1497                 return false;
1498             }
1499             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1500                 return false;
1501             }
1502             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1503                 return false;
1504             }
1505             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1506                 return false;
1507             }
1508         }
1509         catch ( final Exception e ) {
1510             e.printStackTrace();
1511         }
1512         return true;
1513     }
1514
1515     public static final boolean testTreeBaseReading() {
1516         try {
1517             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1518             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1519             parser.setReplaceUnderscores( true );
1520             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1521             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1522             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1523                 return false;
1524             }
1525             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1526             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1527             parser2.setReplaceUnderscores( true );
1528             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1529             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1530             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1531                 return false;
1532             }
1533         }
1534         catch ( final Exception e ) {
1535             e.printStackTrace();
1536         }
1537         return true;
1538     }
1539
1540     public static final boolean testTreeFamReading() {
1541         try {
1542             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1543             final NHXParser parser = new NHXParser();
1544             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1545             parser.setReplaceUnderscores( false );
1546             parser.setGuessRootedness( true );
1547             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1548             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1549             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1550                 return false;
1551             }
1552             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1553                 return false;
1554             }
1555         }
1556         catch ( final Exception e ) {
1557             e.printStackTrace();
1558         }
1559         return true;
1560     }
1561
1562     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1563         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1564         return p;
1565     }
1566
1567     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1568         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1569     }
1570
1571     private static boolean testAminoAcidSequence() {
1572         try {
1573             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1574             if ( aa1.getLength() != 13 ) {
1575                 return false;
1576             }
1577             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1578                 return false;
1579             }
1580             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1581                 return false;
1582             }
1583             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1584                 return false;
1585             }
1586             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1587             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1588                 return false;
1589             }
1590             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1591             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1592                 return false;
1593             }
1594             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1595             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1596                 return false;
1597             }
1598         }
1599         catch ( final Exception e ) {
1600             e.printStackTrace();
1601             return false;
1602         }
1603         return true;
1604     }
1605
1606     private static boolean testBasicDomain() {
1607         try {
1608             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1609             if ( !pd.getDomainId().equals( "id" ) ) {
1610                 return false;
1611             }
1612             if ( pd.getNumber() != 1 ) {
1613                 return false;
1614             }
1615             if ( pd.getTotalCount() != 4 ) {
1616                 return false;
1617             }
1618             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1619                 return false;
1620             }
1621             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1622             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1623             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1624             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1625             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1626             if ( !a1.equals( a1 ) ) {
1627                 return false;
1628             }
1629             if ( !a1.equals( a1_copy ) ) {
1630                 return false;
1631             }
1632             if ( !a1.equals( a1_equal ) ) {
1633                 return false;
1634             }
1635             if ( !a1.equals( a2 ) ) {
1636                 return false;
1637             }
1638             if ( a1.equals( a3 ) ) {
1639                 return false;
1640             }
1641             if ( a1.compareTo( a1 ) != 0 ) {
1642                 return false;
1643             }
1644             if ( a1.compareTo( a1_copy ) != 0 ) {
1645                 return false;
1646             }
1647             if ( a1.compareTo( a1_equal ) != 0 ) {
1648                 return false;
1649             }
1650             if ( a1.compareTo( a2 ) != 0 ) {
1651                 return false;
1652             }
1653             if ( a1.compareTo( a3 ) == 0 ) {
1654                 return false;
1655             }
1656         }
1657         catch ( final Exception e ) {
1658             e.printStackTrace( System.out );
1659             return false;
1660         }
1661         return true;
1662     }
1663
1664     private static boolean testBasicNodeMethods() {
1665         try {
1666             if ( PhylogenyNode.getNodeCount() != 0 ) {
1667                 return false;
1668             }
1669             final PhylogenyNode n1 = new PhylogenyNode();
1670             final PhylogenyNode n2 = PhylogenyNode
1671                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1672             final PhylogenyNode n3 = PhylogenyNode
1673                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1674             final PhylogenyNode n4 = PhylogenyNode
1675                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1676             if ( n1.isHasAssignedEvent() ) {
1677                 return false;
1678             }
1679             if ( PhylogenyNode.getNodeCount() != 4 ) {
1680                 return false;
1681             }
1682             if ( n3.getIndicator() != 0 ) {
1683                 return false;
1684             }
1685             if ( n3.getNumberOfExternalNodes() != 1 ) {
1686                 return false;
1687             }
1688             if ( !n3.isExternal() ) {
1689                 return false;
1690             }
1691             if ( !n3.isRoot() ) {
1692                 return false;
1693             }
1694             if ( !n4.getName().equals( "n4" ) ) {
1695                 return false;
1696             }
1697         }
1698         catch ( final Exception e ) {
1699             e.printStackTrace( System.out );
1700             return false;
1701         }
1702         return true;
1703     }
1704
1705     private static boolean testBasicPhyloXMLparsing() {
1706         try {
1707             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1708             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1709             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1710                                                               xml_parser );
1711             if ( xml_parser.getErrorCount() > 0 ) {
1712                 System.out.println( xml_parser.getErrorMessages().toString() );
1713                 return false;
1714             }
1715             if ( phylogenies_0.length != 4 ) {
1716                 return false;
1717             }
1718             final Phylogeny t1 = phylogenies_0[ 0 ];
1719             final Phylogeny t2 = phylogenies_0[ 1 ];
1720             final Phylogeny t3 = phylogenies_0[ 2 ];
1721             final Phylogeny t4 = phylogenies_0[ 3 ];
1722             if ( t1.getNumberOfExternalNodes() != 1 ) {
1723                 return false;
1724             }
1725             if ( !t1.isRooted() ) {
1726                 return false;
1727             }
1728             if ( t1.isRerootable() ) {
1729                 return false;
1730             }
1731             if ( !t1.getType().equals( "gene_tree" ) ) {
1732                 return false;
1733             }
1734             if ( t2.getNumberOfExternalNodes() != 2 ) {
1735                 return false;
1736             }
1737             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1738                 return false;
1739             }
1740             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1741                 return false;
1742             }
1743             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1744                 return false;
1745             }
1746             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1747                 return false;
1748             }
1749             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1750                 return false;
1751             }
1752             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1753                 return false;
1754             }
1755             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1756                     .startsWith( "actgtgggggt" ) ) {
1757                 return false;
1758             }
1759             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1760                     .startsWith( "ctgtgatgcat" ) ) {
1761                 return false;
1762             }
1763             if ( t3.getNumberOfExternalNodes() != 4 ) {
1764                 return false;
1765             }
1766             if ( !t1.getName().equals( "t1" ) ) {
1767                 return false;
1768             }
1769             if ( !t2.getName().equals( "t2" ) ) {
1770                 return false;
1771             }
1772             if ( !t3.getName().equals( "t3" ) ) {
1773                 return false;
1774             }
1775             if ( !t4.getName().equals( "t4" ) ) {
1776                 return false;
1777             }
1778             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1779                 return false;
1780             }
1781             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1782                 return false;
1783             }
1784             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1785                 return false;
1786             }
1787             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1788                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1789                 return false;
1790             }
1791             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1792                 return false;
1793             }
1794             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1795                 return false;
1796             }
1797             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1798                 return false;
1799             }
1800             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1801                     .equals( "apoptosis" ) ) {
1802                 return false;
1803             }
1804             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1805                     .equals( "GO:0006915" ) ) {
1806                 return false;
1807             }
1808             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1809                     .equals( "UniProtKB" ) ) {
1810                 return false;
1811             }
1812             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1813                     .equals( "experimental" ) ) {
1814                 return false;
1815             }
1816             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1817                     .equals( "function" ) ) {
1818                 return false;
1819             }
1820             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1821                     .getValue() != 1 ) {
1822                 return false;
1823             }
1824             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1825                     .getType().equals( "ml" ) ) {
1826                 return false;
1827             }
1828             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1829                     .equals( "apoptosis" ) ) {
1830                 return false;
1831             }
1832             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1833                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1834                 return false;
1835             }
1836             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1837                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1838                 return false;
1839             }
1840             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1841                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1842                 return false;
1843             }
1844             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1845                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1846                 return false;
1847             }
1848             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1849                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1850                 return false;
1851             }
1852             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1853                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1854                 return false;
1855             }
1856             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1857                     .equals( "GO:0005829" ) ) {
1858                 return false;
1859             }
1860             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1861                     .equals( "intracellular organelle" ) ) {
1862                 return false;
1863             }
1864             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1865                 return false;
1866             }
1867             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1868                     .equals( "UniProt link" ) ) ) {
1869                 return false;
1870             }
1871             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1872                 return false;
1873             }
1874             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1875             if ( x.size() != 4 ) {
1876                 return false;
1877             }
1878             int c = 0;
1879             for( final Accession acc : x ) {
1880                 if ( c == 0 ) {
1881                     if ( !acc.getSource().equals( "KEGG" ) ) {
1882                         return false;
1883                     }
1884                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1885                         return false;
1886                     }
1887                 }
1888                 c++;
1889             }
1890         }
1891         catch ( final Exception e ) {
1892             e.printStackTrace( System.out );
1893             return false;
1894         }
1895         return true;
1896     }
1897
1898     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1899         try {
1900             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1901             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1902             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1903                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1904             }
1905             else {
1906                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1907             }
1908             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1909                                                               xml_parser );
1910             if ( xml_parser.getErrorCount() > 0 ) {
1911                 System.out.println( xml_parser.getErrorMessages().toString() );
1912                 return false;
1913             }
1914             if ( phylogenies_0.length != 4 ) {
1915                 return false;
1916             }
1917             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1918             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1919             if ( phylogenies_t1.length != 1 ) {
1920                 return false;
1921             }
1922             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1923             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1924                 return false;
1925             }
1926             if ( !t1_rt.isRooted() ) {
1927                 return false;
1928             }
1929             if ( t1_rt.isRerootable() ) {
1930                 return false;
1931             }
1932             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1933                 return false;
1934             }
1935             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1936             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1937             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1938             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1939                 return false;
1940             }
1941             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1942                 return false;
1943             }
1944             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1945                 return false;
1946             }
1947             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1948                 return false;
1949             }
1950             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1951                     .startsWith( "actgtgggggt" ) ) {
1952                 return false;
1953             }
1954             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1955                     .startsWith( "ctgtgatgcat" ) ) {
1956                 return false;
1957             }
1958             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1959             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1960             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1961             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1962             if ( phylogenies_1.length != 1 ) {
1963                 return false;
1964             }
1965             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1966             if ( !t3_rt.getName().equals( "t3" ) ) {
1967                 return false;
1968             }
1969             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1970                 return false;
1971             }
1972             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1973                 return false;
1974             }
1975             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1976                 return false;
1977             }
1978             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1979                 return false;
1980             }
1981             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1982                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1983                 return false;
1984             }
1985             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1986                 return false;
1987             }
1988             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1989                 return false;
1990             }
1991             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1992                     .equals( "UniProtKB" ) ) {
1993                 return false;
1994             }
1995             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1996                     .equals( "apoptosis" ) ) {
1997                 return false;
1998             }
1999             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2000                     .equals( "GO:0006915" ) ) {
2001                 return false;
2002             }
2003             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2004                     .equals( "UniProtKB" ) ) {
2005                 return false;
2006             }
2007             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2008                     .equals( "experimental" ) ) {
2009                 return false;
2010             }
2011             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2012                     .equals( "function" ) ) {
2013                 return false;
2014             }
2015             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2016                     .getValue() != 1 ) {
2017                 return false;
2018             }
2019             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2020                     .getType().equals( "ml" ) ) {
2021                 return false;
2022             }
2023             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2024                     .equals( "apoptosis" ) ) {
2025                 return false;
2026             }
2027             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2028                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2029                 return false;
2030             }
2031             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2032                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2033                 return false;
2034             }
2035             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2036                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2037                 return false;
2038             }
2039             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2040                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2041                 return false;
2042             }
2043             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2044                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2045                 return false;
2046             }
2047             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2048                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2049                 return false;
2050             }
2051             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2052                     .equals( "GO:0005829" ) ) {
2053                 return false;
2054             }
2055             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2056                     .equals( "intracellular organelle" ) ) {
2057                 return false;
2058             }
2059             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2060                 return false;
2061             }
2062             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2063                     .equals( "UniProt link" ) ) ) {
2064                 return false;
2065             }
2066             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2067                 return false;
2068             }
2069             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2070                 return false;
2071             }
2072             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2073                     .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." ) ) ) {
2074                 return false;
2075             }
2076             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2077                 return false;
2078             }
2079             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2080                 return false;
2081             }
2082             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2083                 return false;
2084             }
2085             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2086                 return false;
2087             }
2088             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2089                     .equals( "ncbi" ) ) {
2090                 return false;
2091             }
2092             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2096                     .getName().equals( "B" ) ) {
2097                 return false;
2098             }
2099             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2100                     .getFrom() != 21 ) {
2101                 return false;
2102             }
2103             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2104                 return false;
2105             }
2106             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2107                     .getLength() != 24 ) {
2108                 return false;
2109             }
2110             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2111                     .getConfidence() != 2144 ) {
2112                 return false;
2113             }
2114             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2115                     .equals( "pfam" ) ) {
2116                 return false;
2117             }
2118             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2119                 return false;
2120             }
2121             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2122                 return false;
2123             }
2124             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2125                 return false;
2126             }
2127             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2128                 return false;
2129             }
2130             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2131             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2132                 return false;
2133             }
2134             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2135                 return false;
2136             }
2137             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2138                 return false;
2139             }
2140             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2141                 return false;
2142             }
2143             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2144                 return false;
2145             }
2146             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2147                 return false;
2148             }
2149             if ( taxbb.getSynonyms().size() != 2 ) {
2150                 return false;
2151             }
2152             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2153                 return false;
2154             }
2155             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2156                 return false;
2157             }
2158             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2159                 return false;
2160             }
2161             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2162                 return false;
2163             }
2164             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2165                 return false;
2166             }
2167             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2168                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2169                 return false;
2170             }
2171             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2172                 return false;
2173             }
2174             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2175                 return false;
2176             }
2177             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2178                 return false;
2179             }
2180             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2181                 return false;
2182             }
2183             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2184                 return false;
2185             }
2186             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2187                 return false;
2188             }
2189             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2190                 return false;
2191             }
2192             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2193                 return false;
2194             }
2195             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2196                     .equalsIgnoreCase( "435" ) ) {
2197                 return false;
2198             }
2199             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2200                 return false;
2201             }
2202             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2203                     .equalsIgnoreCase( "443.7" ) ) {
2204                 return false;
2205             }
2206             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2207                 return false;
2208             }
2209             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2210                 return false;
2211             }
2212             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2213                     .equalsIgnoreCase( "433" ) ) {
2214                 return false;
2215             }
2216             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2217                     .getCrossReferences();
2218             if ( x.size() != 4 ) {
2219                 return false;
2220             }
2221             int c = 0;
2222             for( final Accession acc : x ) {
2223                 if ( c == 0 ) {
2224                     if ( !acc.getSource().equals( "KEGG" ) ) {
2225                         return false;
2226                     }
2227                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2228                         return false;
2229                     }
2230                 }
2231                 c++;
2232             }
2233         }
2234         catch ( final Exception e ) {
2235             e.printStackTrace( System.out );
2236             return false;
2237         }
2238         return true;
2239     }
2240
2241     private static boolean testBasicPhyloXMLparsingValidating() {
2242         try {
2243             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2244             PhyloXmlParser xml_parser = null;
2245             try {
2246                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2247             }
2248             catch ( final Exception e ) {
2249                 // Do nothing -- means were not running from jar.
2250             }
2251             if ( xml_parser == null ) {
2252                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2253                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2254                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2255                 }
2256                 else {
2257                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2258                 }
2259             }
2260             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2261                                                               xml_parser );
2262             if ( xml_parser.getErrorCount() > 0 ) {
2263                 System.out.println( xml_parser.getErrorMessages().toString() );
2264                 return false;
2265             }
2266             if ( phylogenies_0.length != 4 ) {
2267                 return false;
2268             }
2269             final Phylogeny t1 = phylogenies_0[ 0 ];
2270             final Phylogeny t2 = phylogenies_0[ 1 ];
2271             final Phylogeny t3 = phylogenies_0[ 2 ];
2272             final Phylogeny t4 = phylogenies_0[ 3 ];
2273             if ( !t1.getName().equals( "t1" ) ) {
2274                 return false;
2275             }
2276             if ( !t2.getName().equals( "t2" ) ) {
2277                 return false;
2278             }
2279             if ( !t3.getName().equals( "t3" ) ) {
2280                 return false;
2281             }
2282             if ( !t4.getName().equals( "t4" ) ) {
2283                 return false;
2284             }
2285             if ( t1.getNumberOfExternalNodes() != 1 ) {
2286                 return false;
2287             }
2288             if ( t2.getNumberOfExternalNodes() != 2 ) {
2289                 return false;
2290             }
2291             if ( t3.getNumberOfExternalNodes() != 4 ) {
2292                 return false;
2293             }
2294             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2295             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2296             if ( xml_parser.getErrorCount() > 0 ) {
2297                 System.out.println( "errors:" );
2298                 System.out.println( xml_parser.getErrorMessages().toString() );
2299                 return false;
2300             }
2301             if ( phylogenies_1.length != 4 ) {
2302                 return false;
2303             }
2304             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2305                                                               xml_parser );
2306             if ( xml_parser.getErrorCount() > 0 ) {
2307                 System.out.println( "errors:" );
2308                 System.out.println( xml_parser.getErrorMessages().toString() );
2309                 return false;
2310             }
2311             if ( phylogenies_2.length != 1 ) {
2312                 return false;
2313             }
2314             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2315                 return false;
2316             }
2317             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2318                                                               xml_parser );
2319             if ( xml_parser.getErrorCount() > 0 ) {
2320                 System.out.println( xml_parser.getErrorMessages().toString() );
2321                 return false;
2322             }
2323             if ( phylogenies_3.length != 2 ) {
2324                 return false;
2325             }
2326             final Phylogeny a = phylogenies_3[ 0 ];
2327             if ( !a.getName().equals( "tree 4" ) ) {
2328                 return false;
2329             }
2330             if ( a.getNumberOfExternalNodes() != 3 ) {
2331                 return false;
2332             }
2333             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2334                 return false;
2335             }
2336             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2337                 return false;
2338             }
2339             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2340                                                               xml_parser );
2341             if ( xml_parser.getErrorCount() > 0 ) {
2342                 System.out.println( xml_parser.getErrorMessages().toString() );
2343                 return false;
2344             }
2345             if ( phylogenies_4.length != 1 ) {
2346                 return false;
2347             }
2348             final Phylogeny s = phylogenies_4[ 0 ];
2349             if ( s.getNumberOfExternalNodes() != 6 ) {
2350                 return false;
2351             }
2352             s.getNode( "first" );
2353             s.getNode( "<>" );
2354             s.getNode( "\"<a'b&c'd\">\"" );
2355             s.getNode( "'''\"" );
2356             s.getNode( "\"\"\"" );
2357             s.getNode( "dick & doof" );
2358         }
2359         catch ( final Exception e ) {
2360             e.printStackTrace( System.out );
2361             return false;
2362         }
2363         return true;
2364     }
2365
2366     private static boolean testBasicProtein() {
2367         try {
2368             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2369             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             p0.addProteinDomain( y );
2377             p0.addProteinDomain( e );
2378             p0.addProteinDomain( b );
2379             p0.addProteinDomain( c );
2380             p0.addProteinDomain( d );
2381             p0.addProteinDomain( a );
2382             p0.addProteinDomain( x );
2383             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2384                 return false;
2385             }
2386             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2387                 return false;
2388             }
2389             //
2390             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2391             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2392             aa0.addProteinDomain( a1 );
2393             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2394                 return false;
2395             }
2396             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2397                 return false;
2398             }
2399             //
2400             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2401             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2402             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2403             aa1.addProteinDomain( a11 );
2404             aa1.addProteinDomain( a12 );
2405             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2406                 return false;
2407             }
2408             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2409                 return false;
2410             }
2411             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2412             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2413                 return false;
2414             }
2415             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2416                 return false;
2417             }
2418             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2419                 return false;
2420             }
2421             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2422             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2423                 return false;
2424             }
2425             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2426                 return false;
2427             }
2428             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2429                 return false;
2430             }
2431             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2432                 return false;
2433             }
2434             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2435             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2436                 return false;
2437             }
2438             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2439                 return false;
2440             }
2441             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2442                 return false;
2443             }
2444             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2445                 return false;
2446             }
2447             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2448             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2449                 return false;
2450             }
2451             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2452                 return false;
2453             }
2454             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2455                 return false;
2456             }
2457             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2458                 return false;
2459             }
2460             //
2461             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2462             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2463             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2464             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2465             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2466             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2467             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2468             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2469             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2470             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2471             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2472             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2473             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2474             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2475             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2476             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2477             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2478             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2479             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2480             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2481             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2482             p00.addProteinDomain( y0 );
2483             p00.addProteinDomain( e0 );
2484             p00.addProteinDomain( b0 );
2485             p00.addProteinDomain( c0 );
2486             p00.addProteinDomain( d0 );
2487             p00.addProteinDomain( a0 );
2488             p00.addProteinDomain( x0 );
2489             p00.addProteinDomain( y1 );
2490             p00.addProteinDomain( y2 );
2491             p00.addProteinDomain( y3 );
2492             p00.addProteinDomain( e1 );
2493             p00.addProteinDomain( e2 );
2494             p00.addProteinDomain( e3 );
2495             p00.addProteinDomain( e4 );
2496             p00.addProteinDomain( e5 );
2497             p00.addProteinDomain( z0 );
2498             p00.addProteinDomain( z1 );
2499             p00.addProteinDomain( z2 );
2500             p00.addProteinDomain( zz0 );
2501             p00.addProteinDomain( zz1 );
2502             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2503                 return false;
2504             }
2505             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2506                 return false;
2507             }
2508             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2509                 return false;
2510             }
2511             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2512                 return false;
2513             }
2514             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" ) ) {
2515                 return false;
2516             }
2517             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2518             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2519             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2520             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2521             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2522             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2523             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2524             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2525             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2526             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2527             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2528             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2529             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2530             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2531             p.addProteinDomain( B15 );
2532             p.addProteinDomain( C50 );
2533             p.addProteinDomain( A60 );
2534             p.addProteinDomain( A30 );
2535             p.addProteinDomain( C70 );
2536             p.addProteinDomain( B35 );
2537             p.addProteinDomain( B40 );
2538             p.addProteinDomain( A0 );
2539             p.addProteinDomain( A10 );
2540             p.addProteinDomain( A20 );
2541             p.addProteinDomain( B25 );
2542             p.addProteinDomain( D80 );
2543             List<String> domains_ids = new ArrayList<String>();
2544             domains_ids.add( "A" );
2545             domains_ids.add( "B" );
2546             domains_ids.add( "C" );
2547             if ( !p.contains( domains_ids, false ) ) {
2548                 return false;
2549             }
2550             if ( !p.contains( domains_ids, true ) ) {
2551                 return false;
2552             }
2553             domains_ids.add( "X" );
2554             if ( p.contains( domains_ids, false ) ) {
2555                 return false;
2556             }
2557             if ( p.contains( domains_ids, true ) ) {
2558                 return false;
2559             }
2560             domains_ids = new ArrayList<String>();
2561             domains_ids.add( "A" );
2562             domains_ids.add( "C" );
2563             domains_ids.add( "D" );
2564             if ( !p.contains( domains_ids, false ) ) {
2565                 return false;
2566             }
2567             if ( !p.contains( domains_ids, true ) ) {
2568                 return false;
2569             }
2570             domains_ids = new ArrayList<String>();
2571             domains_ids.add( "A" );
2572             domains_ids.add( "D" );
2573             domains_ids.add( "C" );
2574             if ( !p.contains( domains_ids, false ) ) {
2575                 return false;
2576             }
2577             if ( p.contains( domains_ids, true ) ) {
2578                 return false;
2579             }
2580             domains_ids = new ArrayList<String>();
2581             domains_ids.add( "A" );
2582             domains_ids.add( "A" );
2583             domains_ids.add( "B" );
2584             if ( !p.contains( domains_ids, false ) ) {
2585                 return false;
2586             }
2587             if ( !p.contains( domains_ids, true ) ) {
2588                 return false;
2589             }
2590             domains_ids = new ArrayList<String>();
2591             domains_ids.add( "A" );
2592             domains_ids.add( "A" );
2593             domains_ids.add( "A" );
2594             domains_ids.add( "B" );
2595             domains_ids.add( "B" );
2596             if ( !p.contains( domains_ids, false ) ) {
2597                 return false;
2598             }
2599             if ( !p.contains( domains_ids, true ) ) {
2600                 return false;
2601             }
2602             domains_ids = new ArrayList<String>();
2603             domains_ids.add( "A" );
2604             domains_ids.add( "A" );
2605             domains_ids.add( "B" );
2606             domains_ids.add( "A" );
2607             domains_ids.add( "B" );
2608             domains_ids.add( "B" );
2609             domains_ids.add( "A" );
2610             domains_ids.add( "B" );
2611             domains_ids.add( "C" );
2612             domains_ids.add( "A" );
2613             domains_ids.add( "C" );
2614             domains_ids.add( "D" );
2615             if ( !p.contains( domains_ids, false ) ) {
2616                 return false;
2617             }
2618             if ( p.contains( domains_ids, true ) ) {
2619                 return false;
2620             }
2621         }
2622         catch ( final Exception e ) {
2623             e.printStackTrace( System.out );
2624             return false;
2625         }
2626         return true;
2627     }
2628
2629     private static boolean testBasicTable() {
2630         try {
2631             final BasicTable<String> t0 = new BasicTable<String>();
2632             if ( t0.getNumberOfColumns() != 0 ) {
2633                 return false;
2634             }
2635             if ( t0.getNumberOfRows() != 0 ) {
2636                 return false;
2637             }
2638             t0.setValue( 3, 2, "23" );
2639             t0.setValue( 10, 1, "error" );
2640             t0.setValue( 10, 1, "110" );
2641             t0.setValue( 9, 1, "19" );
2642             t0.setValue( 1, 10, "101" );
2643             t0.setValue( 10, 10, "1010" );
2644             t0.setValue( 100, 10, "10100" );
2645             t0.setValue( 0, 0, "00" );
2646             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2647                 return false;
2648             }
2649             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2650                 return false;
2651             }
2652             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2653                 return false;
2654             }
2655             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2656                 return false;
2657             }
2658             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2659                 return false;
2660             }
2661             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2662                 return false;
2663             }
2664             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2665                 return false;
2666             }
2667             if ( t0.getNumberOfColumns() != 101 ) {
2668                 return false;
2669             }
2670             if ( t0.getNumberOfRows() != 11 ) {
2671                 return false;
2672             }
2673             if ( t0.getValueAsString( 49, 4 ) != null ) {
2674                 return false;
2675             }
2676             final String l = ForesterUtil.getLineSeparator();
2677             final StringBuffer source = new StringBuffer();
2678             source.append( "" + l );
2679             source.append( "# 1 1 1 1 1 1 1 1" + l );
2680             source.append( " 00 01 02 03" + l );
2681             source.append( "   10 11 12 13  " + l );
2682             source.append( "20 21 22 23 " + l );
2683             source.append( "    30  31    32 33" + l );
2684             source.append( "40 41 42 43" + l );
2685             source.append( "  # 1 1 1 1 1 " + l );
2686             source.append( "50 51 52 53 54" + l );
2687             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2688             if ( t1.getNumberOfColumns() != 5 ) {
2689                 return false;
2690             }
2691             if ( t1.getNumberOfRows() != 6 ) {
2692                 return false;
2693             }
2694             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2695                 return false;
2696             }
2697             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2698                 return false;
2699             }
2700             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2701                 return false;
2702             }
2703             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2704                 return false;
2705             }
2706             final StringBuffer source1 = new StringBuffer();
2707             source1.append( "" + l );
2708             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2709             source1.append( " 00; 01 ;02;03" + l );
2710             source1.append( "   10; 11; 12; 13  " + l );
2711             source1.append( "20; 21; 22; 23 " + l );
2712             source1.append( "    30;  31;    32; 33" + l );
2713             source1.append( "40;41;42;43" + l );
2714             source1.append( "  # 1 1 1 1 1 " + l );
2715             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2716             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2717             if ( t2.getNumberOfColumns() != 5 ) {
2718                 return false;
2719             }
2720             if ( t2.getNumberOfRows() != 6 ) {
2721                 return false;
2722             }
2723             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2724                 return false;
2725             }
2726             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2727                 return false;
2728             }
2729             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2730                 return false;
2731             }
2732             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2733                 return false;
2734             }
2735             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2736                 return false;
2737             }
2738             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2739                 return false;
2740             }
2741             final StringBuffer source2 = new StringBuffer();
2742             source2.append( "" + l );
2743             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2744             source2.append( " 00; 01 ;02;03" + l );
2745             source2.append( "   10; 11; 12; 13  " + l );
2746             source2.append( "20; 21; 22; 23 " + l );
2747             source2.append( "                     " + l );
2748             source2.append( "    30;  31;    32; 33" + l );
2749             source2.append( "40;41;42;43" + l );
2750             source2.append( "  comment: 1 1 1 1 1 " + l );
2751             source2.append( ";;;50  ;   52; 53;;54   " + l );
2752             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2753                                                                         ';',
2754                                                                         false,
2755                                                                         false,
2756                                                                         "comment:",
2757                                                                         false );
2758             if ( tl.size() != 2 ) {
2759                 return false;
2760             }
2761             final BasicTable<String> t3 = tl.get( 0 );
2762             final BasicTable<String> t4 = tl.get( 1 );
2763             if ( t3.getNumberOfColumns() != 4 ) {
2764                 return false;
2765             }
2766             if ( t3.getNumberOfRows() != 3 ) {
2767                 return false;
2768             }
2769             if ( t4.getNumberOfColumns() != 4 ) {
2770                 return false;
2771             }
2772             if ( t4.getNumberOfRows() != 3 ) {
2773                 return false;
2774             }
2775             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2776                 return false;
2777             }
2778             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2779                 return false;
2780             }
2781         }
2782         catch ( final Exception e ) {
2783             e.printStackTrace( System.out );
2784             return false;
2785         }
2786         return true;
2787     }
2788
2789     private static boolean testBasicTolXMLparsing() {
2790         try {
2791             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2792             final TolParser parser = new TolParser();
2793             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2794             if ( parser.getErrorCount() > 0 ) {
2795                 System.out.println( parser.getErrorMessages().toString() );
2796                 return false;
2797             }
2798             if ( phylogenies_0.length != 1 ) {
2799                 return false;
2800             }
2801             final Phylogeny t1 = phylogenies_0[ 0 ];
2802             if ( t1.getNumberOfExternalNodes() != 5 ) {
2803                 return false;
2804             }
2805             if ( !t1.isRooted() ) {
2806                 return false;
2807             }
2808             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2809                 return false;
2810             }
2811             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2812                 return false;
2813             }
2814             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2815                 return false;
2816             }
2817             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2818                 return false;
2819             }
2820             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2821             if ( parser.getErrorCount() > 0 ) {
2822                 System.out.println( parser.getErrorMessages().toString() );
2823                 return false;
2824             }
2825             if ( phylogenies_1.length != 1 ) {
2826                 return false;
2827             }
2828             final Phylogeny t2 = phylogenies_1[ 0 ];
2829             if ( t2.getNumberOfExternalNodes() != 664 ) {
2830                 return false;
2831             }
2832             if ( !t2.isRooted() ) {
2833                 return false;
2834             }
2835             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2836                 return false;
2837             }
2838             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2839                 return false;
2840             }
2841             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2842                 return false;
2843             }
2844             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2845                 return false;
2846             }
2847             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2848                 return false;
2849             }
2850             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2851                     .equals( "Aquifex" ) ) {
2852                 return false;
2853             }
2854             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2855             if ( parser.getErrorCount() > 0 ) {
2856                 System.out.println( parser.getErrorMessages().toString() );
2857                 return false;
2858             }
2859             if ( phylogenies_2.length != 1 ) {
2860                 return false;
2861             }
2862             final Phylogeny t3 = phylogenies_2[ 0 ];
2863             if ( t3.getNumberOfExternalNodes() != 184 ) {
2864                 return false;
2865             }
2866             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2867                 return false;
2868             }
2869             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2870                 return false;
2871             }
2872             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2873                 return false;
2874             }
2875             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2876             if ( parser.getErrorCount() > 0 ) {
2877                 System.out.println( parser.getErrorMessages().toString() );
2878                 return false;
2879             }
2880             if ( phylogenies_3.length != 1 ) {
2881                 return false;
2882             }
2883             final Phylogeny t4 = phylogenies_3[ 0 ];
2884             if ( t4.getNumberOfExternalNodes() != 1 ) {
2885                 return false;
2886             }
2887             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2888                 return false;
2889             }
2890             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2891                 return false;
2892             }
2893             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2894                 return false;
2895             }
2896             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2897             if ( parser.getErrorCount() > 0 ) {
2898                 System.out.println( parser.getErrorMessages().toString() );
2899                 return false;
2900             }
2901             if ( phylogenies_4.length != 1 ) {
2902                 return false;
2903             }
2904             final Phylogeny t5 = phylogenies_4[ 0 ];
2905             if ( t5.getNumberOfExternalNodes() != 13 ) {
2906                 return false;
2907             }
2908             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2909                 return false;
2910             }
2911             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2912                 return false;
2913             }
2914             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2915                 return false;
2916             }
2917         }
2918         catch ( final Exception e ) {
2919             e.printStackTrace( System.out );
2920             return false;
2921         }
2922         return true;
2923     }
2924
2925     private static boolean testBasicTreeMethods() {
2926         try {
2927             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2928             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2929             if ( t2.getNumberOfExternalNodes() != 4 ) {
2930                 return false;
2931             }
2932             if ( t2.getHeight() != 8.5 ) {
2933                 return false;
2934             }
2935             if ( !t2.isCompletelyBinary() ) {
2936                 return false;
2937             }
2938             if ( t2.isEmpty() ) {
2939                 return false;
2940             }
2941             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2942             if ( t3.getNumberOfExternalNodes() != 5 ) {
2943                 return false;
2944             }
2945             if ( t3.getHeight() != 11 ) {
2946                 return false;
2947             }
2948             if ( t3.isCompletelyBinary() ) {
2949                 return false;
2950             }
2951             final PhylogenyNode n = t3.getNode( "ABC" );
2952             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 ];
2953             if ( t4.getNumberOfExternalNodes() != 9 ) {
2954                 return false;
2955             }
2956             if ( t4.getHeight() != 11 ) {
2957                 return false;
2958             }
2959             if ( t4.isCompletelyBinary() ) {
2960                 return false;
2961             }
2962             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)" );
2963             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2964             if ( t5.getNumberOfExternalNodes() != 8 ) {
2965                 return false;
2966             }
2967             if ( t5.getHeight() != 15 ) {
2968                 return false;
2969             }
2970             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)" );
2971             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2972             if ( t6.getHeight() != 15 ) {
2973                 return false;
2974             }
2975             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)" );
2976             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2977             if ( t7.getHeight() != 15 ) {
2978                 return false;
2979             }
2980             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)" );
2981             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2982             if ( t8.getNumberOfExternalNodes() != 10 ) {
2983                 return false;
2984             }
2985             if ( t8.getHeight() != 15 ) {
2986                 return false;
2987             }
2988             final char[] a9 = new char[] { 'a' };
2989             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2990             if ( t9.getHeight() != 0 ) {
2991                 return false;
2992             }
2993             final char[] a10 = new char[] { 'a', ':', '6' };
2994             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2995             if ( t10.getHeight() != 6 ) {
2996                 return false;
2997             }
2998         }
2999         catch ( final Exception e ) {
3000             e.printStackTrace( System.out );
3001             return false;
3002         }
3003         return true;
3004     }
3005
3006     private static boolean testConfidenceAssessor() {
3007         try {
3008             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3009             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3010             final Phylogeny[] ev0 = factory
3011                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3012                              new NHXParser() );
3013             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3014             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3015                 return false;
3016             }
3017             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3018                 return false;
3019             }
3020             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3021             final Phylogeny[] ev1 = factory
3022                     .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)));",
3023                              new NHXParser() );
3024             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3025             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3026                 return false;
3027             }
3028             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3029                 return false;
3030             }
3031             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3032             final Phylogeny[] ev_b = factory
3033                     .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",
3034                              new NHXParser() );
3035             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3036             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3037                 return false;
3038             }
3039             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3040                 return false;
3041             }
3042             //
3043             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3044             final Phylogeny[] ev1x = factory
3045                     .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)));",
3046                              new NHXParser() );
3047             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3048             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3049                 return false;
3050             }
3051             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3052                 return false;
3053             }
3054             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3055             final Phylogeny[] ev_bx = factory
3056                     .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",
3057                              new NHXParser() );
3058             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3059             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3060                 return false;
3061             }
3062             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3063                 return false;
3064             }
3065             final Phylogeny[] t2 = factory
3066                     .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);",
3067                              new NHXParser() );
3068             final Phylogeny[] ev2 = factory
3069                     .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);",
3070                              new NHXParser() );
3071             for( final Phylogeny target : t2 ) {
3072                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3073             }
3074             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3075                                                  new NHXParser() )[ 0 ];
3076             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3077             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3078             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3079                 return false;
3080             }
3081             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3082                 return false;
3083             }
3084             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3085                 return false;
3086             }
3087         }
3088         catch ( final Exception e ) {
3089             e.printStackTrace();
3090             return false;
3091         }
3092         return true;
3093     }
3094
3095     private static boolean testCopyOfNodeData() {
3096         try {
3097             final PhylogenyNode n1 = PhylogenyNode
3098                     .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]" );
3099             final PhylogenyNode n2 = n1.copyNodeData();
3100             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3101                 return false;
3102             }
3103         }
3104         catch ( final Exception e ) {
3105             e.printStackTrace();
3106             return false;
3107         }
3108         return true;
3109     }
3110
3111     private static boolean testCreateBalancedPhylogeny() {
3112         try {
3113             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3114             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3115                 return false;
3116             }
3117             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3118                 return false;
3119             }
3120             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3121             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3122                 return false;
3123             }
3124             if ( p1.getNumberOfExternalNodes() != 100 ) {
3125                 return false;
3126             }
3127         }
3128         catch ( final Exception e ) {
3129             e.printStackTrace();
3130             return false;
3131         }
3132         return true;
3133     }
3134
3135     private static boolean testCreateUriForSeqWeb() {
3136         try {
3137             final PhylogenyNode n = new PhylogenyNode();
3138             n.setName( "tr|B3RJ64" );
3139             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3140                 return false;
3141             }
3142             n.setName( "B0LM41_HUMAN" );
3143             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3144                 return false;
3145             }
3146             n.setName( "NP_001025424" );
3147             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3148                 return false;
3149             }
3150             n.setName( "_NM_001030253-" );
3151             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3152                 return false;
3153             }
3154             n.setName( "XM_002122186" );
3155             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3156                 return false;
3157             }
3158             n.setName( "dgh_AAA34956_gdg" );
3159             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3160                 return false;
3161             }
3162             n.setName( "AAA34956" );
3163             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3164                 return false;
3165             }
3166             n.setName( "GI:394892" );
3167             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3168                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3169                 return false;
3170             }
3171             n.setName( "gi_394892" );
3172             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3173                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3174                 return false;
3175             }
3176             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3177             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3178                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3179                 return false;
3180             }
3181             n.setName( "P12345" );
3182             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3183                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3184                 return false;
3185             }
3186             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3187             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3188                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3189                 return false;
3190             }
3191         }
3192         catch ( final Exception e ) {
3193             e.printStackTrace( System.out );
3194             return false;
3195         }
3196         return true;
3197     }
3198
3199     private static boolean testDataObjects() {
3200         try {
3201             final Confidence s0 = new Confidence();
3202             final Confidence s1 = new Confidence();
3203             if ( !s0.isEqual( s1 ) ) {
3204                 return false;
3205             }
3206             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3207             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3208             if ( s2.isEqual( s1 ) ) {
3209                 return false;
3210             }
3211             if ( !s2.isEqual( s3 ) ) {
3212                 return false;
3213             }
3214             final Confidence s4 = ( Confidence ) s3.copy();
3215             if ( !s4.isEqual( s3 ) ) {
3216                 return false;
3217             }
3218             s3.asSimpleText();
3219             s3.asText();
3220             // Taxonomy
3221             // ----------
3222             final Taxonomy t1 = new Taxonomy();
3223             final Taxonomy t2 = new Taxonomy();
3224             final Taxonomy t3 = new Taxonomy();
3225             final Taxonomy t4 = new Taxonomy();
3226             final Taxonomy t5 = new Taxonomy();
3227             t1.setIdentifier( new Identifier( "ecoli" ) );
3228             t1.setTaxonomyCode( "ECOLI" );
3229             t1.setScientificName( "E. coli" );
3230             t1.setCommonName( "coli" );
3231             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3232             if ( !t1.isEqual( t0 ) ) {
3233                 return false;
3234             }
3235             t2.setIdentifier( new Identifier( "ecoli" ) );
3236             t2.setTaxonomyCode( "OTHER" );
3237             t2.setScientificName( "what" );
3238             t2.setCommonName( "something" );
3239             if ( !t1.isEqual( t2 ) ) {
3240                 return false;
3241             }
3242             t2.setIdentifier( new Identifier( "nemve" ) );
3243             if ( t1.isEqual( t2 ) ) {
3244                 return false;
3245             }
3246             t1.setIdentifier( null );
3247             t3.setTaxonomyCode( "ECOLI" );
3248             t3.setScientificName( "what" );
3249             t3.setCommonName( "something" );
3250             if ( !t1.isEqual( t3 ) ) {
3251                 return false;
3252             }
3253             t1.setIdentifier( null );
3254             t1.setTaxonomyCode( "" );
3255             t4.setScientificName( "E. ColI" );
3256             t4.setCommonName( "something" );
3257             if ( !t1.isEqual( t4 ) ) {
3258                 return false;
3259             }
3260             t4.setScientificName( "B. subtilis" );
3261             t4.setCommonName( "something" );
3262             if ( t1.isEqual( t4 ) ) {
3263                 return false;
3264             }
3265             t1.setIdentifier( null );
3266             t1.setTaxonomyCode( "" );
3267             t1.setScientificName( "" );
3268             t5.setCommonName( "COLI" );
3269             if ( !t1.isEqual( t5 ) ) {
3270                 return false;
3271             }
3272             t5.setCommonName( "vibrio" );
3273             if ( t1.isEqual( t5 ) ) {
3274                 return false;
3275             }
3276             // Identifier
3277             // ----------
3278             final Identifier id0 = new Identifier( "123", "pfam" );
3279             final Identifier id1 = ( Identifier ) id0.copy();
3280             if ( !id1.isEqual( id1 ) ) {
3281                 return false;
3282             }
3283             if ( !id1.isEqual( id0 ) ) {
3284                 return false;
3285             }
3286             if ( !id0.isEqual( id1 ) ) {
3287                 return false;
3288             }
3289             id1.asSimpleText();
3290             id1.asText();
3291             // ProteinDomain
3292             // ---------------
3293             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3294             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3295             if ( !pd1.isEqual( pd1 ) ) {
3296                 return false;
3297             }
3298             if ( !pd1.isEqual( pd0 ) ) {
3299                 return false;
3300             }
3301             pd1.asSimpleText();
3302             pd1.asText();
3303             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3304             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3305             if ( !pd3.isEqual( pd3 ) ) {
3306                 return false;
3307             }
3308             if ( !pd2.isEqual( pd3 ) ) {
3309                 return false;
3310             }
3311             if ( !pd0.isEqual( pd3 ) ) {
3312                 return false;
3313             }
3314             pd3.asSimpleText();
3315             pd3.asText();
3316             // DomainArchitecture
3317             // ------------------
3318             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3319             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3320             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3321             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3322             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3323             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3324             domains0.add( d2 );
3325             domains0.add( d0 );
3326             domains0.add( d3 );
3327             domains0.add( d1 );
3328             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3329             if ( ds0.getNumberOfDomains() != 4 ) {
3330                 return false;
3331             }
3332             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3333             if ( !ds0.isEqual( ds0 ) ) {
3334                 return false;
3335             }
3336             if ( !ds0.isEqual( ds1 ) ) {
3337                 return false;
3338             }
3339             if ( ds1.getNumberOfDomains() != 4 ) {
3340                 return false;
3341             }
3342             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3343             domains1.add( d1 );
3344             domains1.add( d2 );
3345             domains1.add( d4 );
3346             domains1.add( d0 );
3347             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3348             if ( ds0.isEqual( ds2 ) ) {
3349                 return false;
3350             }
3351             ds1.asSimpleText();
3352             ds1.asText();
3353             ds1.toNHX();
3354             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3355             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3356                 System.out.println( ds3.toNHX() );
3357                 return false;
3358             }
3359             if ( ds3.getNumberOfDomains() != 3 ) {
3360                 return false;
3361             }
3362             // Event
3363             // -----
3364             final Event e1 = new Event( Event.EventType.fusion );
3365             if ( e1.isDuplication() ) {
3366                 return false;
3367             }
3368             if ( !e1.isFusion() ) {
3369                 return false;
3370             }
3371             if ( !e1.asText().toString().equals( "fusion" ) ) {
3372                 return false;
3373             }
3374             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3375                 return false;
3376             }
3377             final Event e11 = new Event( Event.EventType.fusion );
3378             if ( !e11.isEqual( e1 ) ) {
3379                 return false;
3380             }
3381             if ( !e11.toNHX().toString().equals( "" ) ) {
3382                 return false;
3383             }
3384             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3385             if ( e2.isDuplication() ) {
3386                 return false;
3387             }
3388             if ( !e2.isSpeciationOrDuplication() ) {
3389                 return false;
3390             }
3391             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3392                 return false;
3393             }
3394             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3395                 return false;
3396             }
3397             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3398                 return false;
3399             }
3400             if ( e11.isEqual( e2 ) ) {
3401                 return false;
3402             }
3403             final Event e2c = ( Event ) e2.copy();
3404             if ( !e2c.isEqual( e2 ) ) {
3405                 return false;
3406             }
3407             Event e3 = new Event( 1, 2, 3 );
3408             if ( e3.isDuplication() ) {
3409                 return false;
3410             }
3411             if ( e3.isSpeciation() ) {
3412                 return false;
3413             }
3414             if ( e3.isGeneLoss() ) {
3415                 return false;
3416             }
3417             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3418                 return false;
3419             }
3420             final Event e3c = ( Event ) e3.copy();
3421             final Event e3cc = ( Event ) e3c.copy();
3422             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3423                 return false;
3424             }
3425             e3 = null;
3426             if ( !e3c.isEqual( e3cc ) ) {
3427                 return false;
3428             }
3429             Event e4 = new Event( 1, 2, 3 );
3430             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3431                 return false;
3432             }
3433             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3434                 return false;
3435             }
3436             final Event e4c = ( Event ) e4.copy();
3437             e4 = null;
3438             final Event e4cc = ( Event ) e4c.copy();
3439             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3440                 return false;
3441             }
3442             if ( !e4c.isEqual( e4cc ) ) {
3443                 return false;
3444             }
3445             final Event e5 = new Event();
3446             if ( !e5.isUnassigned() ) {
3447                 return false;
3448             }
3449             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3450                 return false;
3451             }
3452             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3453                 return false;
3454             }
3455             final Event e6 = new Event( 1, 0, 0 );
3456             if ( !e6.asText().toString().equals( "duplication" ) ) {
3457                 return false;
3458             }
3459             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3460                 return false;
3461             }
3462             final Event e7 = new Event( 0, 1, 0 );
3463             if ( !e7.asText().toString().equals( "speciation" ) ) {
3464                 return false;
3465             }
3466             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3467                 return false;
3468             }
3469             final Event e8 = new Event( 0, 0, 1 );
3470             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3471                 return false;
3472             }
3473             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3474                 return false;
3475             }
3476         }
3477         catch ( final Exception e ) {
3478             e.printStackTrace( System.out );
3479             return false;
3480         }
3481         return true;
3482     }
3483
3484     private static boolean testDeletionOfExternalNodes() {
3485         try {
3486             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3487             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3488             final PhylogenyWriter w = new PhylogenyWriter();
3489             if ( t0.isEmpty() ) {
3490                 return false;
3491             }
3492             if ( t0.getNumberOfExternalNodes() != 1 ) {
3493                 return false;
3494             }
3495             t0.deleteSubtree( t0.getNode( "A" ), false );
3496             if ( t0.getNumberOfExternalNodes() != 0 ) {
3497                 return false;
3498             }
3499             if ( !t0.isEmpty() ) {
3500                 return false;
3501             }
3502             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3503             if ( t1.getNumberOfExternalNodes() != 2 ) {
3504                 return false;
3505             }
3506             t1.deleteSubtree( t1.getNode( "A" ), false );
3507             if ( t1.getNumberOfExternalNodes() != 1 ) {
3508                 return false;
3509             }
3510             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3511                 return false;
3512             }
3513             t1.deleteSubtree( t1.getNode( "B" ), false );
3514             if ( t1.getNumberOfExternalNodes() != 1 ) {
3515                 return false;
3516             }
3517             t1.deleteSubtree( t1.getNode( "r" ), false );
3518             if ( !t1.isEmpty() ) {
3519                 return false;
3520             }
3521             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3522             if ( t2.getNumberOfExternalNodes() != 3 ) {
3523                 return false;
3524             }
3525             t2.deleteSubtree( t2.getNode( "B" ), false );
3526             if ( t2.getNumberOfExternalNodes() != 2 ) {
3527                 return false;
3528             }
3529             t2.toNewHampshireX();
3530             PhylogenyNode n = t2.getNode( "A" );
3531             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3532                 return false;
3533             }
3534             t2.deleteSubtree( t2.getNode( "A" ), false );
3535             if ( t2.getNumberOfExternalNodes() != 2 ) {
3536                 return false;
3537             }
3538             t2.deleteSubtree( t2.getNode( "C" ), true );
3539             if ( t2.getNumberOfExternalNodes() != 1 ) {
3540                 return false;
3541             }
3542             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3543             if ( t3.getNumberOfExternalNodes() != 4 ) {
3544                 return false;
3545             }
3546             t3.deleteSubtree( t3.getNode( "B" ), true );
3547             if ( t3.getNumberOfExternalNodes() != 3 ) {
3548                 return false;
3549             }
3550             n = t3.getNode( "A" );
3551             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3552                 return false;
3553             }
3554             n = n.getNextExternalNode();
3555             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3556                 return false;
3557             }
3558             t3.deleteSubtree( t3.getNode( "A" ), true );
3559             if ( t3.getNumberOfExternalNodes() != 2 ) {
3560                 return false;
3561             }
3562             n = t3.getNode( "C" );
3563             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3564                 return false;
3565             }
3566             t3.deleteSubtree( t3.getNode( "C" ), true );
3567             if ( t3.getNumberOfExternalNodes() != 1 ) {
3568                 return false;
3569             }
3570             t3.deleteSubtree( t3.getNode( "D" ), true );
3571             if ( t3.getNumberOfExternalNodes() != 0 ) {
3572                 return false;
3573             }
3574             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3575             if ( t4.getNumberOfExternalNodes() != 6 ) {
3576                 return false;
3577             }
3578             t4.deleteSubtree( t4.getNode( "B2" ), true );
3579             if ( t4.getNumberOfExternalNodes() != 5 ) {
3580                 return false;
3581             }
3582             String s = w.toNewHampshire( t4, true ).toString();
3583             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3584                 return false;
3585             }
3586             t4.deleteSubtree( t4.getNode( "B11" ), true );
3587             if ( t4.getNumberOfExternalNodes() != 4 ) {
3588                 return false;
3589             }
3590             t4.deleteSubtree( t4.getNode( "C" ), true );
3591             if ( t4.getNumberOfExternalNodes() != 3 ) {
3592                 return false;
3593             }
3594             n = t4.getNode( "A" );
3595             n = n.getNextExternalNode();
3596             if ( !n.getName().equals( "B12" ) ) {
3597                 return false;
3598             }
3599             n = n.getNextExternalNode();
3600             if ( !n.getName().equals( "D" ) ) {
3601                 return false;
3602             }
3603             s = w.toNewHampshire( t4, true ).toString();
3604             if ( !s.equals( "((A,B12),D);" ) ) {
3605                 return false;
3606             }
3607             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3608             t5.deleteSubtree( t5.getNode( "A" ), true );
3609             if ( t5.getNumberOfExternalNodes() != 5 ) {
3610                 return false;
3611             }
3612             s = w.toNewHampshire( t5, true ).toString();
3613             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3614                 return false;
3615             }
3616             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3617             t6.deleteSubtree( t6.getNode( "B11" ), true );
3618             if ( t6.getNumberOfExternalNodes() != 5 ) {
3619                 return false;
3620             }
3621             s = w.toNewHampshire( t6, false ).toString();
3622             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3623                 return false;
3624             }
3625             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3626             t7.deleteSubtree( t7.getNode( "B12" ), true );
3627             if ( t7.getNumberOfExternalNodes() != 5 ) {
3628                 return false;
3629             }
3630             s = w.toNewHampshire( t7, true ).toString();
3631             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3632                 return false;
3633             }
3634             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3635             t8.deleteSubtree( t8.getNode( "B2" ), true );
3636             if ( t8.getNumberOfExternalNodes() != 5 ) {
3637                 return false;
3638             }
3639             s = w.toNewHampshire( t8, false ).toString();
3640             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3641                 return false;
3642             }
3643             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3644             t9.deleteSubtree( t9.getNode( "C" ), true );
3645             if ( t9.getNumberOfExternalNodes() != 5 ) {
3646                 return false;
3647             }
3648             s = w.toNewHampshire( t9, true ).toString();
3649             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3650                 return false;
3651             }
3652             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3653             t10.deleteSubtree( t10.getNode( "D" ), true );
3654             if ( t10.getNumberOfExternalNodes() != 5 ) {
3655                 return false;
3656             }
3657             s = w.toNewHampshire( t10, true ).toString();
3658             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3659                 return false;
3660             }
3661             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3662             t11.deleteSubtree( t11.getNode( "A" ), true );
3663             if ( t11.getNumberOfExternalNodes() != 2 ) {
3664                 return false;
3665             }
3666             s = w.toNewHampshire( t11, true ).toString();
3667             if ( !s.equals( "(B,C);" ) ) {
3668                 return false;
3669             }
3670             t11.deleteSubtree( t11.getNode( "C" ), true );
3671             if ( t11.getNumberOfExternalNodes() != 1 ) {
3672                 return false;
3673             }
3674             s = w.toNewHampshire( t11, false ).toString();
3675             if ( !s.equals( "B;" ) ) {
3676                 return false;
3677             }
3678             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3679             t12.deleteSubtree( t12.getNode( "B2" ), true );
3680             if ( t12.getNumberOfExternalNodes() != 8 ) {
3681                 return false;
3682             }
3683             s = w.toNewHampshire( t12, true ).toString();
3684             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3685                 return false;
3686             }
3687             t12.deleteSubtree( t12.getNode( "B3" ), true );
3688             if ( t12.getNumberOfExternalNodes() != 7 ) {
3689                 return false;
3690             }
3691             s = w.toNewHampshire( t12, true ).toString();
3692             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3693                 return false;
3694             }
3695             t12.deleteSubtree( t12.getNode( "C3" ), true );
3696             if ( t12.getNumberOfExternalNodes() != 6 ) {
3697                 return false;
3698             }
3699             s = w.toNewHampshire( t12, true ).toString();
3700             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3701                 return false;
3702             }
3703             t12.deleteSubtree( t12.getNode( "A1" ), true );
3704             if ( t12.getNumberOfExternalNodes() != 5 ) {
3705                 return false;
3706             }
3707             s = w.toNewHampshire( t12, true ).toString();
3708             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3709                 return false;
3710             }
3711             t12.deleteSubtree( t12.getNode( "B1" ), true );
3712             if ( t12.getNumberOfExternalNodes() != 4 ) {
3713                 return false;
3714             }
3715             s = w.toNewHampshire( t12, true ).toString();
3716             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3717                 return false;
3718             }
3719             t12.deleteSubtree( t12.getNode( "A3" ), true );
3720             if ( t12.getNumberOfExternalNodes() != 3 ) {
3721                 return false;
3722             }
3723             s = w.toNewHampshire( t12, true ).toString();
3724             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3725                 return false;
3726             }
3727             t12.deleteSubtree( t12.getNode( "A2" ), true );
3728             if ( t12.getNumberOfExternalNodes() != 2 ) {
3729                 return false;
3730             }
3731             s = w.toNewHampshire( t12, true ).toString();
3732             if ( !s.equals( "(C1,C2);" ) ) {
3733                 return false;
3734             }
3735             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3736             t13.deleteSubtree( t13.getNode( "D" ), true );
3737             if ( t13.getNumberOfExternalNodes() != 4 ) {
3738                 return false;
3739             }
3740             s = w.toNewHampshire( t13, true ).toString();
3741             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3742                 return false;
3743             }
3744             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3745             t14.deleteSubtree( t14.getNode( "E" ), true );
3746             if ( t14.getNumberOfExternalNodes() != 5 ) {
3747                 return false;
3748             }
3749             s = w.toNewHampshire( t14, true ).toString();
3750             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3751                 return false;
3752             }
3753             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3754             t15.deleteSubtree( t15.getNode( "B2" ), true );
3755             if ( t15.getNumberOfExternalNodes() != 11 ) {
3756                 return false;
3757             }
3758             t15.deleteSubtree( t15.getNode( "B1" ), true );
3759             if ( t15.getNumberOfExternalNodes() != 10 ) {
3760                 return false;
3761             }
3762             t15.deleteSubtree( t15.getNode( "B3" ), true );
3763             if ( t15.getNumberOfExternalNodes() != 9 ) {
3764                 return false;
3765             }
3766             t15.deleteSubtree( t15.getNode( "B4" ), true );
3767             if ( t15.getNumberOfExternalNodes() != 8 ) {
3768                 return false;
3769             }
3770             t15.deleteSubtree( t15.getNode( "A1" ), true );
3771             if ( t15.getNumberOfExternalNodes() != 7 ) {
3772                 return false;
3773             }
3774             t15.deleteSubtree( t15.getNode( "C4" ), true );
3775             if ( t15.getNumberOfExternalNodes() != 6 ) {
3776                 return false;
3777             }
3778         }
3779         catch ( final Exception e ) {
3780             e.printStackTrace( System.out );
3781             return false;
3782         }
3783         return true;
3784     }
3785
3786     private static boolean testDescriptiveStatistics() {
3787         try {
3788             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3789             dss1.addValue( 82 );
3790             dss1.addValue( 78 );
3791             dss1.addValue( 70 );
3792             dss1.addValue( 58 );
3793             dss1.addValue( 42 );
3794             if ( dss1.getN() != 5 ) {
3795                 return false;
3796             }
3797             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3798                 return false;
3799             }
3800             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3801                 return false;
3802             }
3803             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3804                 return false;
3805             }
3806             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3807                 return false;
3808             }
3809             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3810                 return false;
3811             }
3812             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3813                 return false;
3814             }
3815             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3816                 return false;
3817             }
3818             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3819                 return false;
3820             }
3821             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3822                 return false;
3823             }
3824             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3825                 return false;
3826             }
3827             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3828                 return false;
3829             }
3830             dss1.addValue( 123 );
3831             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3832                 return false;
3833             }
3834             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3835                 return false;
3836             }
3837             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3838                 return false;
3839             }
3840             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3841             dss2.addValue( -1.85 );
3842             dss2.addValue( 57.5 );
3843             dss2.addValue( 92.78 );
3844             dss2.addValue( 57.78 );
3845             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3846                 return false;
3847             }
3848             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3849                 return false;
3850             }
3851             final double[] a = dss2.getDataAsDoubleArray();
3852             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3853                 return false;
3854             }
3855             dss2.addValue( -100 );
3856             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3857                 return false;
3858             }
3859             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3860                 return false;
3861             }
3862             final double[] ds = new double[ 14 ];
3863             ds[ 0 ] = 34;
3864             ds[ 1 ] = 23;
3865             ds[ 2 ] = 1;
3866             ds[ 3 ] = 32;
3867             ds[ 4 ] = 11;
3868             ds[ 5 ] = 2;
3869             ds[ 6 ] = 12;
3870             ds[ 7 ] = 33;
3871             ds[ 8 ] = 13;
3872             ds[ 9 ] = 22;
3873             ds[ 10 ] = 21;
3874             ds[ 11 ] = 35;
3875             ds[ 12 ] = 24;
3876             ds[ 13 ] = 31;
3877             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3878             if ( bins.length != 4 ) {
3879                 return false;
3880             }
3881             if ( bins[ 0 ] != 2 ) {
3882                 return false;
3883             }
3884             if ( bins[ 1 ] != 3 ) {
3885                 return false;
3886             }
3887             if ( bins[ 2 ] != 4 ) {
3888                 return false;
3889             }
3890             if ( bins[ 3 ] != 5 ) {
3891                 return false;
3892             }
3893             final double[] ds1 = new double[ 9 ];
3894             ds1[ 0 ] = 10.0;
3895             ds1[ 1 ] = 19.0;
3896             ds1[ 2 ] = 9.999;
3897             ds1[ 3 ] = 0.0;
3898             ds1[ 4 ] = 39.9;
3899             ds1[ 5 ] = 39.999;
3900             ds1[ 6 ] = 30.0;
3901             ds1[ 7 ] = 19.999;
3902             ds1[ 8 ] = 30.1;
3903             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3904             if ( bins1.length != 4 ) {
3905                 return false;
3906             }
3907             if ( bins1[ 0 ] != 2 ) {
3908                 return false;
3909             }
3910             if ( bins1[ 1 ] != 3 ) {
3911                 return false;
3912             }
3913             if ( bins1[ 2 ] != 0 ) {
3914                 return false;
3915             }
3916             if ( bins1[ 3 ] != 4 ) {
3917                 return false;
3918             }
3919             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3920             if ( bins1_1.length != 3 ) {
3921                 return false;
3922             }
3923             if ( bins1_1[ 0 ] != 3 ) {
3924                 return false;
3925             }
3926             if ( bins1_1[ 1 ] != 2 ) {
3927                 return false;
3928             }
3929             if ( bins1_1[ 2 ] != 4 ) {
3930                 return false;
3931             }
3932             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3933             if ( bins1_2.length != 3 ) {
3934                 return false;
3935             }
3936             if ( bins1_2[ 0 ] != 2 ) {
3937                 return false;
3938             }
3939             if ( bins1_2[ 1 ] != 2 ) {
3940                 return false;
3941             }
3942             if ( bins1_2[ 2 ] != 2 ) {
3943                 return false;
3944             }
3945             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3946             dss3.addValue( 1 );
3947             dss3.addValue( 1 );
3948             dss3.addValue( 1 );
3949             dss3.addValue( 2 );
3950             dss3.addValue( 3 );
3951             dss3.addValue( 4 );
3952             dss3.addValue( 5 );
3953             dss3.addValue( 5 );
3954             dss3.addValue( 5 );
3955             dss3.addValue( 6 );
3956             dss3.addValue( 7 );
3957             dss3.addValue( 8 );
3958             dss3.addValue( 9 );
3959             dss3.addValue( 10 );
3960             dss3.addValue( 10 );
3961             dss3.addValue( 10 );
3962             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3963             histo.toStringBuffer( 10, '=', 40, 5 );
3964             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3965         }
3966         catch ( final Exception e ) {
3967             e.printStackTrace( System.out );
3968             return false;
3969         }
3970         return true;
3971     }
3972
3973     private static boolean testDir( final String file ) {
3974         try {
3975             final File f = new File( file );
3976             if ( !f.exists() ) {
3977                 return false;
3978             }
3979             if ( !f.isDirectory() ) {
3980                 return false;
3981             }
3982             if ( !f.canRead() ) {
3983                 return false;
3984             }
3985         }
3986         catch ( final Exception e ) {
3987             return false;
3988         }
3989         return true;
3990     }
3991
3992     private static boolean testEbiEntryRetrieval() {
3993         try {
3994             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3995             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3996                 System.out.println( entry.getAccession() );
3997                 return false;
3998             }
3999             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4000                 System.out.println( entry.getTaxonomyScientificName() );
4001                 return false;
4002             }
4003             if ( !entry.getSequenceName()
4004                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4005                 System.out.println( entry.getSequenceName() );
4006                 return false;
4007             }
4008             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4009                 System.out.println( entry.getGeneName() );
4010                 return false;
4011             }
4012             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4013                 System.out.println( entry.getTaxonomyIdentifier() );
4014                 return false;
4015             }
4016             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4017                 System.out.println( entry.getAnnotations().first().getRefValue() );
4018                 return false;
4019             }
4020             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4021                 System.out.println( entry.getAnnotations().first().getRefSource() );
4022                 return false;
4023             }
4024             if ( entry.getCrossReferences().size() != 5 ) {
4025                 return false;
4026             }
4027             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4028             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4029                 return false;
4030             }
4031             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4032                 System.out.println( entry1.getTaxonomyScientificName() );
4033                 return false;
4034             }
4035             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4036                 System.out.println( entry1.getSequenceName() );
4037                 return false;
4038             }
4039             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4040                 System.out.println( entry1.getTaxonomyIdentifier() );
4041                 return false;
4042             }
4043             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4044                 System.out.println( entry1.getGeneName() );
4045                 return false;
4046             }
4047             if ( entry1.getCrossReferences().size() != 6 ) {
4048                 return false;
4049             }
4050             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4051             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4052                 return false;
4053             }
4054             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4055                 System.out.println( entry2.getTaxonomyScientificName() );
4056                 return false;
4057             }
4058             if ( !entry2.getSequenceName()
4059                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4060                 System.out.println( entry2.getSequenceName() );
4061                 return false;
4062             }
4063             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4064                 System.out.println( entry2.getTaxonomyIdentifier() );
4065                 return false;
4066             }
4067             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4068                 System.out.println( entry2.getGeneName() );
4069                 return false;
4070             }
4071             if ( entry2.getCrossReferences().size() != 3 ) {
4072                 return false;
4073             }
4074             //
4075             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4076             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4077                 return false;
4078             }
4079             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4080                 System.out.println( entry3.getTaxonomyScientificName() );
4081                 return false;
4082             }
4083             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4084                 System.out.println( entry3.getSequenceName() );
4085                 return false;
4086             }
4087             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4088                 System.out.println( entry3.getTaxonomyIdentifier() );
4089                 return false;
4090             }
4091             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4092                 System.out.println( entry3.getSequenceSymbol() );
4093                 return false;
4094             }
4095             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4096                 return false;
4097             }
4098             if ( entry3.getCrossReferences().size() < 7 ) {
4099                 return false;
4100             }
4101             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4102             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4103                 return false;
4104             }
4105             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4106                 System.out.println( entry4.getTaxonomyScientificName() );
4107                 return false;
4108             }
4109             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4110                 System.out.println( entry4.getSequenceName() );
4111                 return false;
4112             }
4113             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4114                 System.out.println( entry4.getTaxonomyIdentifier() );
4115                 return false;
4116             }
4117             if ( !entry4.getGeneName().equals( "ras" ) ) {
4118                 System.out.println( entry4.getGeneName() );
4119                 return false;
4120             }
4121             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4122             //     System.out.println( entry4.getChromosome() );
4123             //     return false;
4124             // }
4125             // if ( !entry4.getMap().equals( "ras" ) ) {
4126             //     System.out.println( entry4.getMap() );
4127             //     return false;
4128             // }
4129             //TODO FIXME gi...
4130             //
4131             //TODO fails:
4132             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4133             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4134             //                return false;
4135             //            }
4136             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4137             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4138                 return false;
4139             }
4140             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4141                 System.out.println( entry5.getTaxonomyScientificName() );
4142                 return false;
4143             }
4144             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4145                 System.out.println( entry5.getSequenceName() );
4146                 return false;
4147             }
4148             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4149                 System.out.println( entry5.getTaxonomyIdentifier() );
4150                 return false;
4151             }
4152         }
4153         catch ( final IOException e ) {
4154             System.out.println();
4155             System.out.println( "the following might be due to absence internet connection:" );
4156             e.printStackTrace( System.out );
4157             return true;
4158         }
4159         catch ( final Exception e ) {
4160             e.printStackTrace();
4161             return false;
4162         }
4163         return true;
4164     }
4165
4166     private static boolean testExternalNodeRelatedMethods() {
4167         try {
4168             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4169             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4170             PhylogenyNode n = t1.getNode( "A" );
4171             n = n.getNextExternalNode();
4172             if ( !n.getName().equals( "B" ) ) {
4173                 return false;
4174             }
4175             n = n.getNextExternalNode();
4176             if ( !n.getName().equals( "C" ) ) {
4177                 return false;
4178             }
4179             n = n.getNextExternalNode();
4180             if ( !n.getName().equals( "D" ) ) {
4181                 return false;
4182             }
4183             n = t1.getNode( "B" );
4184             while ( !n.isLastExternalNode() ) {
4185                 n = n.getNextExternalNode();
4186             }
4187             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4188             n = t2.getNode( "A" );
4189             n = n.getNextExternalNode();
4190             if ( !n.getName().equals( "B" ) ) {
4191                 return false;
4192             }
4193             n = n.getNextExternalNode();
4194             if ( !n.getName().equals( "C" ) ) {
4195                 return false;
4196             }
4197             n = n.getNextExternalNode();
4198             if ( !n.getName().equals( "D" ) ) {
4199                 return false;
4200             }
4201             n = t2.getNode( "B" );
4202             while ( !n.isLastExternalNode() ) {
4203                 n = n.getNextExternalNode();
4204             }
4205             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4206             n = t3.getNode( "A" );
4207             n = n.getNextExternalNode();
4208             if ( !n.getName().equals( "B" ) ) {
4209                 return false;
4210             }
4211             n = n.getNextExternalNode();
4212             if ( !n.getName().equals( "C" ) ) {
4213                 return false;
4214             }
4215             n = n.getNextExternalNode();
4216             if ( !n.getName().equals( "D" ) ) {
4217                 return false;
4218             }
4219             n = n.getNextExternalNode();
4220             if ( !n.getName().equals( "E" ) ) {
4221                 return false;
4222             }
4223             n = n.getNextExternalNode();
4224             if ( !n.getName().equals( "F" ) ) {
4225                 return false;
4226             }
4227             n = n.getNextExternalNode();
4228             if ( !n.getName().equals( "G" ) ) {
4229                 return false;
4230             }
4231             n = n.getNextExternalNode();
4232             if ( !n.getName().equals( "H" ) ) {
4233                 return false;
4234             }
4235             n = t3.getNode( "B" );
4236             while ( !n.isLastExternalNode() ) {
4237                 n = n.getNextExternalNode();
4238             }
4239             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4240             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4241                 final PhylogenyNode node = iter.next();
4242             }
4243             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4244             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4245                 final PhylogenyNode node = iter.next();
4246             }
4247             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4248             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4249             if ( !iter.next().getName().equals( "A" ) ) {
4250                 return false;
4251             }
4252             if ( !iter.next().getName().equals( "B" ) ) {
4253                 return false;
4254             }
4255             if ( !iter.next().getName().equals( "C" ) ) {
4256                 return false;
4257             }
4258             if ( !iter.next().getName().equals( "D" ) ) {
4259                 return false;
4260             }
4261             if ( !iter.next().getName().equals( "E" ) ) {
4262                 return false;
4263             }
4264             if ( !iter.next().getName().equals( "F" ) ) {
4265                 return false;
4266             }
4267             if ( iter.hasNext() ) {
4268                 return false;
4269             }
4270         }
4271         catch ( final Exception e ) {
4272             e.printStackTrace( System.out );
4273             return false;
4274         }
4275         return true;
4276     }
4277
4278     private static boolean testExtractSNFromNodeName() {
4279         try {
4280             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4281                 return false;
4282             }
4283             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4284                 return false;
4285             }
4286             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4287                 return false;
4288             }
4289             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4290                     .equals( "Mus musculus musculus" ) ) {
4291                 return false;
4292             }
4293             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4294                     .equals( "Mus musculus musculus" ) ) {
4295                 return false;
4296             }
4297             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4298                     .equals( "Mus musculus musculus" ) ) {
4299                 return false;
4300             }
4301             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4302                     .equals( "Mus musculus musculus" ) ) {
4303                 return false;
4304             }
4305             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4309                     .equals( "Mus musculus musculus" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4313                     .equals( "Mus musculus musculus" ) ) {
4314                 return false;
4315             }
4316             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4317                 return false;
4318             }
4319             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4320                 return false;
4321             }
4322             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4323                 return false;
4324             }
4325             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4329                     .equals( "Mus musculus musculus" ) ) {
4330                 return false;
4331             }
4332             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4333                 return false;
4334             }
4335             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4336                 return false;
4337             }
4338             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4339                 return false;
4340             }
4341             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4342                 return false;
4343             }
4344             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4345                 return false;
4346             }
4347             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4348                 return false;
4349             }
4350             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4351                 return false;
4352             }
4353             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4354                 return false;
4355             }
4356             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4357                     .equals( "Mus musculus" ) ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4361                     .equals( "Mus musculus" ) ) {
4362                 return false;
4363             }
4364             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4365                 return false;
4366             }
4367             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4368                     .equals( "Mus musculus musculus" ) ) {
4369                 return false;
4370             }
4371             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4372                     .equals( "Mus musculus musculus" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4376                     .equals( "Mus musculus musculus" ) ) {
4377                 return false;
4378             }
4379             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4380                 return false;
4381             }
4382             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4383                     .equals( "Pilostyles mexicana" ) ) {
4384                 return false;
4385             }
4386             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4387                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4388                 return false;
4389             }
4390             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4391                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4392                 return false;
4393             }
4394             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4395                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4399                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4400                 return false;
4401             }
4402             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4403                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4404                 return false;
4405             }
4406             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4407                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4408                 return false;
4409             }
4410             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4411                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4412                 return false;
4413             }
4414             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4415                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4416                 return false;
4417             }
4418             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4419                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4420                 return false;
4421             }
4422             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4423                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4424                 return false;
4425             }
4426             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4427                     .equals( "Escherichia coli (strain K12)" ) ) {
4428                 return false;
4429             }
4430             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4431                     .equals( "Escherichia coli (strain K12)" ) ) {
4432                 return false;
4433             }
4434             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4435                     .equals( "Escherichia coli (str. K12)" ) ) {
4436                 return false;
4437             }
4438             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4439                     .equals( "Escherichia coli (str. K12)" ) ) {
4440                 return false;
4441             }
4442             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4443                     .equals( "Escherichia coli (str. K12)" ) ) {
4444                 return false;
4445             }
4446             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4447                     .equals( "Escherichia coli (var. K12)" ) ) {
4448                 return false;
4449             }
4450             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4451                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4455                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils
4459                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4460                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4461                 return false;
4462             }
4463             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4464                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4465                 return false;
4466             }
4467             if ( !ParserUtils
4468                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4469                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4470                 return false;
4471             }
4472             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4473                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4477                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4481                 return false;
4482             }
4483             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4484                 return false;
4485             }
4486             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4490                     .equals( "Macrocera sp." ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4494                 return false;
4495             }
4496             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4497                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4498                 return false;
4499             }
4500             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4501                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4502                 return false;
4503             }
4504             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4505                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4506                 return false;
4507             }
4508             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4509                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4510                 return false;
4511             }
4512         }
4513         catch ( final Exception e ) {
4514             e.printStackTrace( System.out );
4515             return false;
4516         }
4517         return true;
4518     }
4519
4520     private static boolean testExtractTaxonomyDataFromNodeName() {
4521         try {
4522             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4523             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4524                 return false;
4525             }
4526             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4527             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4528                 return false;
4529             }
4530             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4531             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4532                 return false;
4533             }
4534             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4535             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4536                 return false;
4537             }
4538             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4539             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4540                 return false;
4541             }
4542             n = new PhylogenyNode( "HNRPR_HUMAN" );
4543             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4544                 return false;
4545             }
4546             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4547             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4548                 return false;
4549             }
4550         }
4551         catch ( final Exception e ) {
4552             e.printStackTrace( System.out );
4553             return false;
4554         }
4555         return true;
4556     }
4557
4558     private static boolean testExtractTaxonomyCodeFromNodeName() {
4559         try {
4560             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4561                 return false;
4562             }
4563             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4564                     .equals( "SOYBN" ) ) {
4565                 return false;
4566             }
4567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4568                     .equals( "ARATH" ) ) {
4569                 return false;
4570             }
4571             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4572                     .equals( "ARATH" ) ) {
4573                 return false;
4574             }
4575             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4576                 return false;
4577             }
4578             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4579                 return false;
4580             }
4581             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4582                 return false;
4583             }
4584             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4585                     .equals( "SOYBN" ) ) {
4586                 return false;
4587             }
4588             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4589                     .equals( "SOYBN" ) ) {
4590                 return false;
4591             }
4592             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4593                     .equals( "SOYBN" ) ) {
4594                 return false;
4595             }
4596             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4597                     .equals( "SOYBN" ) ) {
4598                 return false;
4599             }
4600             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4601                     .equals( "SOYBN" ) ) {
4602                 return false;
4603             }
4604             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4605                     .equals( "SOYBN" ) ) {
4606                 return false;
4607             }
4608             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4609                     .equals( "SOYBN" ) ) {
4610                 return false;
4611             }
4612             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4613                     .equals( "SOYBN" ) ) {
4614                 return false;
4615             }
4616             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4617                 return false;
4618             }
4619             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4620                     .equals( "SOYBN" ) ) {
4621                 return false;
4622             }
4623             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4624                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4625                 return false;
4626             }
4627             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4628                     .equals( "9YX45" ) ) {
4629                 return false;
4630             }
4631             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4632                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4633                     .equals( "MOUSE" ) ) {
4634                 return false;
4635             }
4636             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4637                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4638                     .equals( "MOUSE" ) ) {
4639                 return false;
4640             }
4641             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4642                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4643                     .equals( "MOUSE" ) ) {
4644                 return false;
4645             }
4646             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4647                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4648                 return false;
4649             }
4650             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4651                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4652                 return false;
4653             }
4654             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4655                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4656                 return false;
4657             }
4658             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4659                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4660                 return false;
4661             }
4662             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4663                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4664                 return false;
4665             }
4666             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4667                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4668                 return false;
4669             }
4670             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4671                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4672                 return false;
4673             }
4674             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4675                     .equals( "RAT" ) ) {
4676                 return false;
4677             }
4678             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4679                     .equals( "PIG" ) ) {
4680                 return false;
4681             }
4682             if ( !ParserUtils
4683                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4684                     .equals( "MOUSE" ) ) {
4685                 return false;
4686             }
4687             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4688                     .equals( "MOUSE" ) ) {
4689                 return false;
4690             }
4691             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4692                 return false;
4693             }
4694         }
4695         catch ( final Exception e ) {
4696             e.printStackTrace( System.out );
4697             return false;
4698         }
4699         return true;
4700     }
4701
4702     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4703         try {
4704             PhylogenyNode n = new PhylogenyNode();
4705             n.setName( "tr|B3RJ64" );
4706             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4707                 return false;
4708             }
4709             n.setName( "tr.B3RJ64" );
4710             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4711                 return false;
4712             }
4713             n.setName( "tr=B3RJ64" );
4714             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4715                 return false;
4716             }
4717             n.setName( "tr-B3RJ64" );
4718             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4719                 return false;
4720             }
4721             n.setName( "tr/B3RJ64" );
4722             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4723                 return false;
4724             }
4725             n.setName( "tr\\B3RJ64" );
4726             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4727                 return false;
4728             }
4729             n.setName( "tr_B3RJ64" );
4730             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4731                 return false;
4732             }
4733             n.setName( " tr|B3RJ64 " );
4734             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4735                 return false;
4736             }
4737             n.setName( "-tr|B3RJ64-" );
4738             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4739                 return false;
4740             }
4741             n.setName( "-tr=B3RJ64-" );
4742             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4743                 return false;
4744             }
4745             n.setName( "_tr=B3RJ64_" );
4746             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4747                 return false;
4748             }
4749             n.setName( " tr_tr|B3RJ64_sp|123 " );
4750             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4751                 return false;
4752             }
4753             n.setName( "B3RJ64" );
4754             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4755                 return false;
4756             }
4757             n.setName( "sp|B3RJ64" );
4758             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4759                 return false;
4760             }
4761             n.setName( "sp|B3RJ64C" );
4762             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4763                 return false;
4764             }
4765             n.setName( "sp B3RJ64" );
4766             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4767                 return false;
4768             }
4769             n.setName( "sp|B3RJ6X" );
4770             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4771                 return false;
4772             }
4773             n.setName( "sp|B3RJ6" );
4774             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4775                 return false;
4776             }
4777             n.setName( "K1PYK7_CRAGI" );
4778             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4779                 return false;
4780             }
4781             n.setName( "K1PYK7_PEA" );
4782             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4783                 return false;
4784             }
4785             n.setName( "K1PYK7_RAT" );
4786             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4787                 return false;
4788             }
4789             n.setName( "K1PYK7_PIG" );
4790             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4791                 return false;
4792             }
4793             n.setName( "~K1PYK7_PIG~" );
4794             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4795                 return false;
4796             }
4797             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4798             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4799                 return false;
4800             }
4801             n.setName( "K1PYKX_CRAGI" );
4802             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4803                 return false;
4804             }
4805             n.setName( "XXXXX_CRAGI" );
4806             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4807                 return false;
4808             }
4809             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4810             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4811                 return false;
4812             }
4813             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4814             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4815                 return false;
4816             }
4817             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4818             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4819                 return false;
4820             }
4821             n = new PhylogenyNode();
4822             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4823             seq.setSymbol( "K1PYK7_CRAGI" );
4824             n.getNodeData().addSequence( seq );
4825             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4826                 return false;
4827             }
4828             seq.setSymbol( "tr|B3RJ64" );
4829             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4830                 return false;
4831             }
4832             n = new PhylogenyNode();
4833             seq = new org.forester.phylogeny.data.Sequence();
4834             seq.setName( "K1PYK7_CRAGI" );
4835             n.getNodeData().addSequence( seq );
4836             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4837                 return false;
4838             }
4839             seq.setName( "tr|B3RJ64" );
4840             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4841                 return false;
4842             }
4843             n = new PhylogenyNode();
4844             seq = new org.forester.phylogeny.data.Sequence();
4845             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4846             n.getNodeData().addSequence( seq );
4847             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4848                 return false;
4849             }
4850             n = new PhylogenyNode();
4851             seq = new org.forester.phylogeny.data.Sequence();
4852             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4853             n.getNodeData().addSequence( seq );
4854             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4855                 return false;
4856             }
4857             //
4858             n = new PhylogenyNode();
4859             n.setName( "ACP19736" );
4860             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4861                 return false;
4862             }
4863             n = new PhylogenyNode();
4864             n.setName( "|ACP19736|" );
4865             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4866                 return false;
4867             }
4868         }
4869         catch ( final Exception e ) {
4870             e.printStackTrace( System.out );
4871             return false;
4872         }
4873         return true;
4874     }
4875
4876     private static boolean testFastaParser() {
4877         try {
4878             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4879                 return false;
4880             }
4881             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4882                 return false;
4883             }
4884             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4885             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4886                 return false;
4887             }
4888             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4892                 return false;
4893             }
4894             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4895                 return false;
4896             }
4897             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4898                 return false;
4899             }
4900             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4901                 return false;
4902             }
4903         }
4904         catch ( final Exception e ) {
4905             e.printStackTrace();
4906             return false;
4907         }
4908         return true;
4909     }
4910
4911     private static boolean testGenbankAccessorParsing() {
4912         //The format for GenBank Accession numbers are:
4913         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4914         //Protein:    3 letters + 5 numerals
4915         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4916         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4917             return false;
4918         }
4919         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4920             return false;
4921         }
4922         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4923             return false;
4924         }
4925         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4926             return false;
4927         }
4928         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4929             return false;
4930         }
4931         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4932             return false;
4933         }
4934         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4935             return false;
4936         }
4937         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4938             return false;
4939         }
4940         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4941             return false;
4942         }
4943         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4944             return false;
4945         }
4946         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4947             return false;
4948         }
4949         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4950             return false;
4951         }
4952         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4953             return false;
4954         }
4955         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4956             return false;
4957         }
4958         return true;
4959     }
4960
4961     private static boolean testGeneralMsaParser() {
4962         try {
4963             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4964             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4965             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4966             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4967             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4968             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4969             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4970             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4971             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4972                 return false;
4973             }
4974             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4975                 return false;
4976             }
4977             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4978                 return false;
4979             }
4980             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4981                 return false;
4982             }
4983             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4984                 return false;
4985             }
4986             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4987                 return false;
4988             }
4989             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4990                 return false;
4991             }
4992             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4993                 return false;
4994             }
4995             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4996                 return false;
4997             }
4998             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4999                 return false;
5000             }
5001             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5002                 return false;
5003             }
5004             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5005                 return false;
5006             }
5007             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5008             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5009                 return false;
5010             }
5011             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5012                 return false;
5013             }
5014             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5015                 return false;
5016             }
5017             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5018             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5019                 return false;
5020             }
5021             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5022                 return false;
5023             }
5024             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5025                 return false;
5026             }
5027             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5028             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5029                 return false;
5030             }
5031             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5032                 return false;
5033             }
5034             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5035                 return false;
5036             }
5037         }
5038         catch ( final Exception e ) {
5039             e.printStackTrace();
5040             return false;
5041         }
5042         return true;
5043     }
5044
5045     private static boolean testGeneralTable() {
5046         try {
5047             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5048             t0.setValue( 3, 2, "23" );
5049             t0.setValue( 10, 1, "error" );
5050             t0.setValue( 10, 1, "110" );
5051             t0.setValue( 9, 1, "19" );
5052             t0.setValue( 1, 10, "101" );
5053             t0.setValue( 10, 10, "1010" );
5054             t0.setValue( 100, 10, "10100" );
5055             t0.setValue( 0, 0, "00" );
5056             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5057                 return false;
5058             }
5059             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5060                 return false;
5061             }
5062             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5063                 return false;
5064             }
5065             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5066                 return false;
5067             }
5068             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5069                 return false;
5070             }
5071             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5072                 return false;
5073             }
5074             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5075                 return false;
5076             }
5077             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5078                 return false;
5079             }
5080             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5081                 return false;
5082             }
5083             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5084             t1.setValue( "3", "2", "23" );
5085             t1.setValue( "10", "1", "error" );
5086             t1.setValue( "10", "1", "110" );
5087             t1.setValue( "9", "1", "19" );
5088             t1.setValue( "1", "10", "101" );
5089             t1.setValue( "10", "10", "1010" );
5090             t1.setValue( "100", "10", "10100" );
5091             t1.setValue( "0", "0", "00" );
5092             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5093             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5094                 return false;
5095             }
5096             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5097                 return false;
5098             }
5099             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5100                 return false;
5101             }
5102             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5103                 return false;
5104             }
5105             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5106                 return false;
5107             }
5108             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5109                 return false;
5110             }
5111             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5112                 return false;
5113             }
5114             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5115                 return false;
5116             }
5117             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5118                 return false;
5119             }
5120             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5121                 return false;
5122             }
5123         }
5124         catch ( final Exception e ) {
5125             e.printStackTrace( System.out );
5126             return false;
5127         }
5128         return true;
5129     }
5130
5131     private static boolean testGetDistance() {
5132         try {
5133             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5134             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",
5135                                                  new NHXParser() )[ 0 ];
5136             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5137                 return false;
5138             }
5139             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5140                 return false;
5141             }
5142             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5143                 return false;
5144             }
5145             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5146                 return false;
5147             }
5148             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5149                 return false;
5150             }
5151             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5152                 return false;
5153             }
5154             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5155                 return false;
5156             }
5157             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5158                 return false;
5159             }
5160             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5161                 return false;
5162             }
5163             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5164                 return false;
5165             }
5166             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5167                 return false;
5168             }
5169             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5170                 return false;
5171             }
5172             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5173                 return false;
5174             }
5175             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5176                 return false;
5177             }
5178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5179                 return false;
5180             }
5181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5182                 return false;
5183             }
5184             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5185                 return false;
5186             }
5187             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5188                 return false;
5189             }
5190             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5191                 return false;
5192             }
5193             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5194                 return false;
5195             }
5196             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5197                 return false;
5198             }
5199             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5200                 return false;
5201             }
5202             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5203                 return false;
5204             }
5205             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5206                 return false;
5207             }
5208             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5209                 return false;
5210             }
5211             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5212                 return false;
5213             }
5214             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5215                 return false;
5216             }
5217             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5218                 return false;
5219             }
5220             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5221                 return false;
5222             }
5223             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5224                 return false;
5225             }
5226             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5227                 return false;
5228             }
5229             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",
5230                                                  new NHXParser() )[ 0 ];
5231             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5232                 return false;
5233             }
5234             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5235                 return false;
5236             }
5237             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5238                 return false;
5239             }
5240             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5241                 return false;
5242             }
5243             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5244                 return false;
5245             }
5246             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5247                 return false;
5248             }
5249             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5250                 return false;
5251             }
5252             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5253                 return false;
5254             }
5255             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5256                 return false;
5257             }
5258             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5259                 return false;
5260             }
5261             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5262                 return false;
5263             }
5264         }
5265         catch ( final Exception e ) {
5266             e.printStackTrace( System.out );
5267             return false;
5268         }
5269         return true;
5270     }
5271
5272     private static boolean testGetLCA() {
5273         try {
5274             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5275             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5276                                                  new NHXParser() )[ 0 ];
5277             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5278             if ( !A.getName().equals( "A" ) ) {
5279                 return false;
5280             }
5281             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5282             if ( !gh.getName().equals( "gh" ) ) {
5283                 return false;
5284             }
5285             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5286             if ( !ab.getName().equals( "ab" ) ) {
5287                 return false;
5288             }
5289             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5290             if ( !ab2.getName().equals( "ab" ) ) {
5291                 return false;
5292             }
5293             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5294             if ( !gh2.getName().equals( "gh" ) ) {
5295                 return false;
5296             }
5297             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5298             if ( !gh3.getName().equals( "gh" ) ) {
5299                 return false;
5300             }
5301             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5302             if ( !abc.getName().equals( "abc" ) ) {
5303                 return false;
5304             }
5305             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5306             if ( !abc2.getName().equals( "abc" ) ) {
5307                 return false;
5308             }
5309             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5310             if ( !abcd.getName().equals( "abcd" ) ) {
5311                 return false;
5312             }
5313             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5314             if ( !abcd2.getName().equals( "abcd" ) ) {
5315                 return false;
5316             }
5317             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5318             if ( !abcdef.getName().equals( "abcdef" ) ) {
5319                 return false;
5320             }
5321             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5322             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5323                 return false;
5324             }
5325             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5326             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5327                 return false;
5328             }
5329             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5330             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5331                 return false;
5332             }
5333             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5334             if ( !abcde.getName().equals( "abcde" ) ) {
5335                 return false;
5336             }
5337             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5338             if ( !abcde2.getName().equals( "abcde" ) ) {
5339                 return false;
5340             }
5341             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5342             if ( !r.getName().equals( "abcdefgh" ) ) {
5343                 return false;
5344             }
5345             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5346             if ( !r2.getName().equals( "abcdefgh" ) ) {
5347                 return false;
5348             }
5349             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5350             if ( !r3.getName().equals( "abcdefgh" ) ) {
5351                 return false;
5352             }
5353             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5354             if ( !abcde3.getName().equals( "abcde" ) ) {
5355                 return false;
5356             }
5357             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5358             if ( !abcde4.getName().equals( "abcde" ) ) {
5359                 return false;
5360             }
5361             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5362             if ( !ab3.getName().equals( "ab" ) ) {
5363                 return false;
5364             }
5365             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5366             if ( !ab4.getName().equals( "ab" ) ) {
5367                 return false;
5368             }
5369             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5370             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5371             if ( !cd.getName().equals( "cd" ) ) {
5372                 return false;
5373             }
5374             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5375             if ( !cd2.getName().equals( "cd" ) ) {
5376                 return false;
5377             }
5378             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5379             if ( !cde.getName().equals( "cde" ) ) {
5380                 return false;
5381             }
5382             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5383             if ( !cde2.getName().equals( "cde" ) ) {
5384                 return false;
5385             }
5386             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5387             if ( !cdef.getName().equals( "cdef" ) ) {
5388                 return false;
5389             }
5390             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5391             if ( !cdef2.getName().equals( "cdef" ) ) {
5392                 return false;
5393             }
5394             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5395             if ( !cdef3.getName().equals( "cdef" ) ) {
5396                 return false;
5397             }
5398             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5399             if ( !rt.getName().equals( "r" ) ) {
5400                 return false;
5401             }
5402             final Phylogeny p3 = factory
5403                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5404                              new NHXParser() )[ 0 ];
5405             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5406             if ( !bc_3.getName().equals( "bc" ) ) {
5407                 return false;
5408             }
5409             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5410             if ( !ac_3.getName().equals( "abc" ) ) {
5411                 return false;
5412             }
5413             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5414             if ( !ad_3.getName().equals( "abcde" ) ) {
5415                 return false;
5416             }
5417             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5418             if ( !af_3.getName().equals( "abcdef" ) ) {
5419                 return false;
5420             }
5421             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5422             if ( !ag_3.getName().equals( "" ) ) {
5423                 return false;
5424             }
5425             if ( !ag_3.isRoot() ) {
5426                 return false;
5427             }
5428             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5429             if ( !al_3.getName().equals( "" ) ) {
5430                 return false;
5431             }
5432             if ( !al_3.isRoot() ) {
5433                 return false;
5434             }
5435             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5436             if ( !kl_3.getName().equals( "" ) ) {
5437                 return false;
5438             }
5439             if ( !kl_3.isRoot() ) {
5440                 return false;
5441             }
5442             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5443             if ( !fl_3.getName().equals( "" ) ) {
5444                 return false;
5445             }
5446             if ( !fl_3.isRoot() ) {
5447                 return false;
5448             }
5449             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5450             if ( !gk_3.getName().equals( "ghijk" ) ) {
5451                 return false;
5452             }
5453             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5454             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5455             if ( !r_4.getName().equals( "r" ) ) {
5456                 return false;
5457             }
5458             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5459             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5460             if ( !r_5.getName().equals( "root" ) ) {
5461                 return false;
5462             }
5463             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5464             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5465             if ( !r_6.getName().equals( "rot" ) ) {
5466                 return false;
5467             }
5468             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5469             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5470             if ( !r_7.getName().equals( "rott" ) ) {
5471                 return false;
5472             }
5473         }
5474         catch ( final Exception e ) {
5475             e.printStackTrace( System.out );
5476             return false;
5477         }
5478         return true;
5479     }
5480
5481     private static boolean testGetLCA2() {
5482         try {
5483             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5484             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5485             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5486             PhylogenyMethods.preOrderReId( p_a );
5487             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5488                                                                                               p_a.getNode( "a" ) );
5489             if ( !p_a_1.getName().equals( "a" ) ) {
5490                 return false;
5491             }
5492             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5493             PhylogenyMethods.preOrderReId( p_b );
5494             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5495                                                                                               p_b.getNode( "a" ) );
5496             if ( !p_b_1.getName().equals( "b" ) ) {
5497                 return false;
5498             }
5499             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5500                                                                                               p_b.getNode( "b" ) );
5501             if ( !p_b_2.getName().equals( "b" ) ) {
5502                 return false;
5503             }
5504             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5505             PhylogenyMethods.preOrderReId( p_c );
5506             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5507                                                                                               p_c.getNode( "a" ) );
5508             if ( !p_c_1.getName().equals( "b" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5512                                                                                               p_c.getNode( "c" ) );
5513             if ( !p_c_2.getName().equals( "c" ) ) {
5514                 System.out.println( p_c_2.getName() );
5515                 System.exit( -1 );
5516                 return false;
5517             }
5518             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5519                                                                                               p_c.getNode( "b" ) );
5520             if ( !p_c_3.getName().equals( "b" ) ) {
5521                 return false;
5522             }
5523             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5524                                                                                               p_c.getNode( "a" ) );
5525             if ( !p_c_4.getName().equals( "c" ) ) {
5526                 return false;
5527             }
5528             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5529                                                  new NHXParser() )[ 0 ];
5530             PhylogenyMethods.preOrderReId( p1 );
5531             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5532                                                                                           p1.getNode( "A" ) );
5533             if ( !A.getName().equals( "A" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5537                                                                                            p1.getNode( "gh" ) );
5538             if ( !gh.getName().equals( "gh" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5542                                                                                            p1.getNode( "B" ) );
5543             if ( !ab.getName().equals( "ab" ) ) {
5544                 return false;
5545             }
5546             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5547                                                                                             p1.getNode( "A" ) );
5548             if ( !ab2.getName().equals( "ab" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5552                                                                                             p1.getNode( "G" ) );
5553             if ( !gh2.getName().equals( "gh" ) ) {
5554                 return false;
5555             }
5556             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5557                                                                                             p1.getNode( "H" ) );
5558             if ( !gh3.getName().equals( "gh" ) ) {
5559                 return false;
5560             }
5561             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5562                                                                                             p1.getNode( "A" ) );
5563             if ( !abc.getName().equals( "abc" ) ) {
5564                 return false;
5565             }
5566             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5567                                                                                              p1.getNode( "C" ) );
5568             if ( !abc2.getName().equals( "abc" ) ) {
5569                 return false;
5570             }
5571             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5572                                                                                              p1.getNode( "D" ) );
5573             if ( !abcd.getName().equals( "abcd" ) ) {
5574                 return false;
5575             }
5576             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5577                                                                                               p1.getNode( "A" ) );
5578             if ( !abcd2.getName().equals( "abcd" ) ) {
5579                 return false;
5580             }
5581             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5582                                                                                                p1.getNode( "F" ) );
5583             if ( !abcdef.getName().equals( "abcdef" ) ) {
5584                 return false;
5585             }
5586             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5587                                                                                                 p1.getNode( "A" ) );
5588             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5589                 return false;
5590             }
5591             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5592                                                                                                 p1.getNode( "F" ) );
5593             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5594                 return false;
5595             }
5596             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5597                                                                                                 p1.getNode( "ab" ) );
5598             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5599                 return false;
5600             }
5601             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5602                                                                                               p1.getNode( "E" ) );
5603             if ( !abcde.getName().equals( "abcde" ) ) {
5604                 return false;
5605             }
5606             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5607                                                                                                p1.getNode( "A" ) );
5608             if ( !abcde2.getName().equals( "abcde" ) ) {
5609                 return false;
5610             }
5611             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5612                                                                                           p1.getNode( "abcdefgh" ) );
5613             if ( !r.getName().equals( "abcdefgh" ) ) {
5614                 return false;
5615             }
5616             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5617                                                                                            p1.getNode( "H" ) );
5618             if ( !r2.getName().equals( "abcdefgh" ) ) {
5619                 return false;
5620             }
5621             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5622                                                                                            p1.getNode( "A" ) );
5623             if ( !r3.getName().equals( "abcdefgh" ) ) {
5624                 return false;
5625             }
5626             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5627                                                                                                p1.getNode( "abcde" ) );
5628             if ( !abcde3.getName().equals( "abcde" ) ) {
5629                 return false;
5630             }
5631             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5632                                                                                                p1.getNode( "E" ) );
5633             if ( !abcde4.getName().equals( "abcde" ) ) {
5634                 return false;
5635             }
5636             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5637                                                                                             p1.getNode( "B" ) );
5638             if ( !ab3.getName().equals( "ab" ) ) {
5639                 return false;
5640             }
5641             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5642                                                                                             p1.getNode( "ab" ) );
5643             if ( !ab4.getName().equals( "ab" ) ) {
5644                 return false;
5645             }
5646             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5647             PhylogenyMethods.preOrderReId( p2 );
5648             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5649                                                                                            p2.getNode( "d" ) );
5650             if ( !cd.getName().equals( "cd" ) ) {
5651                 return false;
5652             }
5653             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5654                                                                                             p2.getNode( "c" ) );
5655             if ( !cd2.getName().equals( "cd" ) ) {
5656                 return false;
5657             }
5658             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5659                                                                                             p2.getNode( "e" ) );
5660             if ( !cde.getName().equals( "cde" ) ) {
5661                 return false;
5662             }
5663             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5664                                                                                              p2.getNode( "c" ) );
5665             if ( !cde2.getName().equals( "cde" ) ) {
5666                 return false;
5667             }
5668             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5669                                                                                              p2.getNode( "f" ) );
5670             if ( !cdef.getName().equals( "cdef" ) ) {
5671                 return false;
5672             }
5673             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5674                                                                                               p2.getNode( "f" ) );
5675             if ( !cdef2.getName().equals( "cdef" ) ) {
5676                 return false;
5677             }
5678             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5679                                                                                               p2.getNode( "d" ) );
5680             if ( !cdef3.getName().equals( "cdef" ) ) {
5681                 return false;
5682             }
5683             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5684                                                                                            p2.getNode( "a" ) );
5685             if ( !rt.getName().equals( "r" ) ) {
5686                 return false;
5687             }
5688             final Phylogeny p3 = factory
5689                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5690                              new NHXParser() )[ 0 ];
5691             PhylogenyMethods.preOrderReId( p3 );
5692             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5693                                                                                              p3.getNode( "c" ) );
5694             if ( !bc_3.getName().equals( "bc" ) ) {
5695                 return false;
5696             }
5697             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5698                                                                                              p3.getNode( "c" ) );
5699             if ( !ac_3.getName().equals( "abc" ) ) {
5700                 return false;
5701             }
5702             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5703                                                                                              p3.getNode( "d" ) );
5704             if ( !ad_3.getName().equals( "abcde" ) ) {
5705                 return false;
5706             }
5707             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5708                                                                                              p3.getNode( "f" ) );
5709             if ( !af_3.getName().equals( "abcdef" ) ) {
5710                 return false;
5711             }
5712             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5713                                                                                              p3.getNode( "g" ) );
5714             if ( !ag_3.getName().equals( "" ) ) {
5715                 return false;
5716             }
5717             if ( !ag_3.isRoot() ) {
5718                 return false;
5719             }
5720             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5721                                                                                              p3.getNode( "l" ) );
5722             if ( !al_3.getName().equals( "" ) ) {
5723                 return false;
5724             }
5725             if ( !al_3.isRoot() ) {
5726                 return false;
5727             }
5728             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5729                                                                                              p3.getNode( "l" ) );
5730             if ( !kl_3.getName().equals( "" ) ) {
5731                 return false;
5732             }
5733             if ( !kl_3.isRoot() ) {
5734                 return false;
5735             }
5736             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5737                                                                                              p3.getNode( "l" ) );
5738             if ( !fl_3.getName().equals( "" ) ) {
5739                 return false;
5740             }
5741             if ( !fl_3.isRoot() ) {
5742                 return false;
5743             }
5744             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5745                                                                                              p3.getNode( "k" ) );
5746             if ( !gk_3.getName().equals( "ghijk" ) ) {
5747                 return false;
5748             }
5749             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5750             PhylogenyMethods.preOrderReId( p4 );
5751             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5752                                                                                             p4.getNode( "c" ) );
5753             if ( !r_4.getName().equals( "r" ) ) {
5754                 return false;
5755             }
5756             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5757             PhylogenyMethods.preOrderReId( p5 );
5758             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5759                                                                                             p5.getNode( "c" ) );
5760             if ( !r_5.getName().equals( "root" ) ) {
5761                 return false;
5762             }
5763             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5764             PhylogenyMethods.preOrderReId( p6 );
5765             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5766                                                                                             p6.getNode( "a" ) );
5767             if ( !r_6.getName().equals( "rot" ) ) {
5768                 return false;
5769             }
5770             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5771             PhylogenyMethods.preOrderReId( p7 );
5772             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5773                                                                                             p7.getNode( "e" ) );
5774             if ( !r_7.getName().equals( "rott" ) ) {
5775                 return false;
5776             }
5777             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5778                                                                                              p7.getNode( "a" ) );
5779             if ( !r_71.getName().equals( "rott" ) ) {
5780                 return false;
5781             }
5782             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5783                                                                                              p7.getNode( "rott" ) );
5784             if ( !r_72.getName().equals( "rott" ) ) {
5785                 return false;
5786             }
5787             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5788                                                                                              p7.getNode( "a" ) );
5789             if ( !r_73.getName().equals( "rott" ) ) {
5790                 return false;
5791             }
5792             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5793                                                                                              p7.getNode( "rott" ) );
5794             if ( !r_74.getName().equals( "rott" ) ) {
5795                 return false;
5796             }
5797             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5798                                                                                              p7.getNode( "e" ) );
5799             if ( !r_75.getName().equals( "e" ) ) {
5800                 return false;
5801             }
5802         }
5803         catch ( final Exception e ) {
5804             e.printStackTrace( System.out );
5805             return false;
5806         }
5807         return true;
5808     }
5809
5810     private static boolean testHmmscanOutputParser() {
5811         final String test_dir = Test.PATH_TO_TEST_DATA;
5812         try {
5813             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5814                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5815             parser1.parse();
5816             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5817                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5818             final List<Protein> proteins = parser2.parse();
5819             if ( parser2.getProteinsEncountered() != 4 ) {
5820                 return false;
5821             }
5822             if ( proteins.size() != 4 ) {
5823                 return false;
5824             }
5825             if ( parser2.getDomainsEncountered() != 69 ) {
5826                 return false;
5827             }
5828             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5829                 return false;
5830             }
5831             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5832                 return false;
5833             }
5834             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5835                 return false;
5836             }
5837             final Protein p1 = proteins.get( 0 );
5838             if ( p1.getNumberOfProteinDomains() != 15 ) {
5839                 return false;
5840             }
5841             if ( p1.getLength() != 850 ) {
5842                 return false;
5843             }
5844             final Protein p2 = proteins.get( 1 );
5845             if ( p2.getNumberOfProteinDomains() != 51 ) {
5846                 return false;
5847             }
5848             if ( p2.getLength() != 1291 ) {
5849                 return false;
5850             }
5851             final Protein p3 = proteins.get( 2 );
5852             if ( p3.getNumberOfProteinDomains() != 2 ) {
5853                 return false;
5854             }
5855             final Protein p4 = proteins.get( 3 );
5856             if ( p4.getNumberOfProteinDomains() != 1 ) {
5857                 return false;
5858             }
5859             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5860                 return false;
5861             }
5862             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5863                 return false;
5864             }
5865             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5866                 return false;
5867             }
5868             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5869                 return false;
5870             }
5871             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5872                 return false;
5873             }
5874             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5875                 return false;
5876             }
5877             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5878                 return false;
5879             }
5880         }
5881         catch ( final Exception e ) {
5882             e.printStackTrace( System.out );
5883             return false;
5884         }
5885         return true;
5886     }
5887
5888     private static boolean testLastExternalNodeMethods() {
5889         try {
5890             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5891             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5892             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5893             final PhylogenyNode n1 = t0.getNode( "A" );
5894             if ( n1.isLastExternalNode() ) {
5895                 return false;
5896             }
5897             final PhylogenyNode n2 = t0.getNode( "B" );
5898             if ( n2.isLastExternalNode() ) {
5899                 return false;
5900             }
5901             final PhylogenyNode n3 = t0.getNode( "C" );
5902             if ( n3.isLastExternalNode() ) {
5903                 return false;
5904             }
5905             final PhylogenyNode n4 = t0.getNode( "D" );
5906             if ( !n4.isLastExternalNode() ) {
5907                 return false;
5908             }
5909         }
5910         catch ( final Exception e ) {
5911             e.printStackTrace( System.out );
5912             return false;
5913         }
5914         return true;
5915     }
5916
5917     private static boolean testLevelOrderIterator() {
5918         try {
5919             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5920             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5921             PhylogenyNodeIterator it0;
5922             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5923                 it0.next();
5924             }
5925             for( it0.reset(); it0.hasNext(); ) {
5926                 it0.next();
5927             }
5928             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5929             if ( !it.next().getName().equals( "r" ) ) {
5930                 return false;
5931             }
5932             if ( !it.next().getName().equals( "ab" ) ) {
5933                 return false;
5934             }
5935             if ( !it.next().getName().equals( "cd" ) ) {
5936                 return false;
5937             }
5938             if ( !it.next().getName().equals( "A" ) ) {
5939                 return false;
5940             }
5941             if ( !it.next().getName().equals( "B" ) ) {
5942                 return false;
5943             }
5944             if ( !it.next().getName().equals( "C" ) ) {
5945                 return false;
5946             }
5947             if ( !it.next().getName().equals( "D" ) ) {
5948                 return false;
5949             }
5950             if ( it.hasNext() ) {
5951                 return false;
5952             }
5953             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",
5954                                                  new NHXParser() )[ 0 ];
5955             PhylogenyNodeIterator it2;
5956             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5957                 it2.next();
5958             }
5959             for( it2.reset(); it2.hasNext(); ) {
5960                 it2.next();
5961             }
5962             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5963             if ( !it3.next().getName().equals( "r" ) ) {
5964                 return false;
5965             }
5966             if ( !it3.next().getName().equals( "abc" ) ) {
5967                 return false;
5968             }
5969             if ( !it3.next().getName().equals( "defg" ) ) {
5970                 return false;
5971             }
5972             if ( !it3.next().getName().equals( "A" ) ) {
5973                 return false;
5974             }
5975             if ( !it3.next().getName().equals( "B" ) ) {
5976                 return false;
5977             }
5978             if ( !it3.next().getName().equals( "C" ) ) {
5979                 return false;
5980             }
5981             if ( !it3.next().getName().equals( "D" ) ) {
5982                 return false;
5983             }
5984             if ( !it3.next().getName().equals( "E" ) ) {
5985                 return false;
5986             }
5987             if ( !it3.next().getName().equals( "F" ) ) {
5988                 return false;
5989             }
5990             if ( !it3.next().getName().equals( "G" ) ) {
5991                 return false;
5992             }
5993             if ( !it3.next().getName().equals( "1" ) ) {
5994                 return false;
5995             }
5996             if ( !it3.next().getName().equals( "2" ) ) {
5997                 return false;
5998             }
5999             if ( !it3.next().getName().equals( "3" ) ) {
6000                 return false;
6001             }
6002             if ( !it3.next().getName().equals( "4" ) ) {
6003                 return false;
6004             }
6005             if ( !it3.next().getName().equals( "5" ) ) {
6006                 return false;
6007             }
6008             if ( !it3.next().getName().equals( "6" ) ) {
6009                 return false;
6010             }
6011             if ( !it3.next().getName().equals( "f1" ) ) {
6012                 return false;
6013             }
6014             if ( !it3.next().getName().equals( "f2" ) ) {
6015                 return false;
6016             }
6017             if ( !it3.next().getName().equals( "f3" ) ) {
6018                 return false;
6019             }
6020             if ( !it3.next().getName().equals( "a" ) ) {
6021                 return false;
6022             }
6023             if ( !it3.next().getName().equals( "b" ) ) {
6024                 return false;
6025             }
6026             if ( !it3.next().getName().equals( "f21" ) ) {
6027                 return false;
6028             }
6029             if ( !it3.next().getName().equals( "X" ) ) {
6030                 return false;
6031             }
6032             if ( !it3.next().getName().equals( "Y" ) ) {
6033                 return false;
6034             }
6035             if ( !it3.next().getName().equals( "Z" ) ) {
6036                 return false;
6037             }
6038             if ( it3.hasNext() ) {
6039                 return false;
6040             }
6041             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6042             PhylogenyNodeIterator it4;
6043             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6044                 it4.next();
6045             }
6046             for( it4.reset(); it4.hasNext(); ) {
6047                 it4.next();
6048             }
6049             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6050             if ( !it5.next().getName().equals( "r" ) ) {
6051                 return false;
6052             }
6053             if ( !it5.next().getName().equals( "A" ) ) {
6054                 return false;
6055             }
6056             if ( !it5.next().getName().equals( "B" ) ) {
6057                 return false;
6058             }
6059             if ( !it5.next().getName().equals( "C" ) ) {
6060                 return false;
6061             }
6062             if ( !it5.next().getName().equals( "D" ) ) {
6063                 return false;
6064             }
6065             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6066             PhylogenyNodeIterator it6;
6067             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6068                 it6.next();
6069             }
6070             for( it6.reset(); it6.hasNext(); ) {
6071                 it6.next();
6072             }
6073             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6074             if ( !it7.next().getName().equals( "A" ) ) {
6075                 return false;
6076             }
6077             if ( it.hasNext() ) {
6078                 return false;
6079             }
6080         }
6081         catch ( final Exception e ) {
6082             e.printStackTrace( System.out );
6083             return false;
6084         }
6085         return true;
6086     }
6087
6088     private static boolean testMafft( final String path ) {
6089         try {
6090             final List<String> opts = new ArrayList<String>();
6091             opts.add( "--maxiterate" );
6092             opts.add( "1000" );
6093             opts.add( "--localpair" );
6094             opts.add( "--quiet" );
6095             Msa msa = null;
6096             final MsaInferrer mafft = Mafft.createInstance( path );
6097             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6098             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6099                 return false;
6100             }
6101             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6102                 return false;
6103             }
6104         }
6105         catch ( final Exception e ) {
6106             e.printStackTrace( System.out );
6107             return false;
6108         }
6109         return true;
6110     }
6111
6112     private static boolean testMidpointrooting() {
6113         try {
6114             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6115             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6116             PhylogenyMethods.midpointRoot( t0 );
6117             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6118                 return false;
6119             }
6120             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6121                 return false;
6122             }
6123             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6124                            1 ) ) {
6125                 return false;
6126             }
6127             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",
6128                                                  new NHXParser() )[ 0 ];
6129             if ( !t1.isRooted() ) {
6130                 return false;
6131             }
6132             PhylogenyMethods.midpointRoot( t1 );
6133             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6134                 return false;
6135             }
6136             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6137                 return false;
6138             }
6139             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6140                 return false;
6141             }
6142             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6143                 return false;
6144             }
6145             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6146                 return false;
6147             }
6148             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6149                 return false;
6150             }
6151             t1.reRoot( t1.getNode( "A" ) );
6152             PhylogenyMethods.midpointRoot( t1 );
6153             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6154                 return false;
6155             }
6156             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6157                 return false;
6158             }
6159             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6160                 return false;
6161             }
6162             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6163                 return false;
6164             }
6165             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6166                 System.exit( -1 );
6167                 return false;
6168             }
6169             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6170                 return false;
6171             }
6172         }
6173         catch ( final Exception e ) {
6174             e.printStackTrace( System.out );
6175             return false;
6176         }
6177         return true;
6178     }
6179
6180     private static boolean testMsaQualityMethod() {
6181         try {
6182             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6183             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6184             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6185             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6186             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6187             l.add( s0 );
6188             l.add( s1 );
6189             l.add( s2 );
6190             l.add( s3 );
6191             final Msa msa = BasicMsa.createInstance( l );
6192             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6193                 return false;
6194             }
6195             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6196                 return false;
6197             }
6198             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6199                 return false;
6200             }
6201             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6202                 return false;
6203             }
6204             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6205                 return false;
6206             }
6207             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6208                 return false;
6209             }
6210             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6211                 return false;
6212             }
6213         }
6214         catch ( final Exception e ) {
6215             e.printStackTrace( System.out );
6216             return false;
6217         }
6218         return true;
6219     }
6220
6221     private static boolean testMsaEntropy() {
6222         try {
6223             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6224             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6225             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6226             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6227             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6228             l.add( s0 );
6229             l.add( s1 );
6230             l.add( s2 );
6231             l.add( s3 );
6232             final Msa msa = BasicMsa.createInstance( l );
6233             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6234             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6235             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6236             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6237             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6238             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6239             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6240             System.out.println();
6241             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6242             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6243             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6244             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6245             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6246             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6247             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6248             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6249             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6250             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6251             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6252             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6253             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6254             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6255             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6256             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6257             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6258             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6259             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6260             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6261             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6262             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6263             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6264             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6265             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6266             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6267             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6268             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6269             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6270             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6271             final Msa msa2 = BasicMsa.createInstance( l2 );
6272             System.out.println();
6273             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6274             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6275             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6276         }
6277         catch ( final Exception e ) {
6278             e.printStackTrace( System.out );
6279             return false;
6280         }
6281         return true;
6282     }
6283
6284     private static boolean testDeleteableMsa() {
6285         try {
6286             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6287             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6288             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6289             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6290             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6291             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6292             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6293             l0.add( s0 );
6294             l0.add( s1 );
6295             l0.add( s2 );
6296             l0.add( s3 );
6297             l0.add( s4 );
6298             l0.add( s5 );
6299             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6300             dmsa0.deleteRow( "b", false );
6301             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6302                 return false;
6303             }
6304             dmsa0.deleteRow( "e", false );
6305             dmsa0.deleteRow( "a", false );
6306             dmsa0.deleteRow( "f", false );
6307             if ( dmsa0.getLength() != 4 ) {
6308                 return false;
6309             }
6310             if ( dmsa0.getNumberOfSequences() != 2 ) {
6311                 return false;
6312             }
6313             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6314                 return false;
6315             }
6316             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6317                 return false;
6318             }
6319             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6320                 return false;
6321             }
6322             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6323                 return false;
6324             }
6325             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6326                 return false;
6327             }
6328             dmsa0.deleteRow( "c", false );
6329             dmsa0.deleteRow( "d", false );
6330             if ( dmsa0.getNumberOfSequences() != 0 ) {
6331                 return false;
6332             }
6333             //
6334             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6335             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6336             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6337             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6338             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6339             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6340             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6341             l1.add( s_0 );
6342             l1.add( s_1 );
6343             l1.add( s_2 );
6344             l1.add( s_3 );
6345             l1.add( s_4 );
6346             l1.add( s_5 );
6347             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6348             dmsa1.deleteGapOnlyColumns();
6349             dmsa1.deleteRow( "a", false );
6350             dmsa1.deleteRow( "f", false );
6351             dmsa1.deleteRow( "d", false );
6352             dmsa1.deleteGapOnlyColumns();
6353             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6354                 return false;
6355             }
6356             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6357                 return false;
6358             }
6359             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6360                 return false;
6361             }
6362             dmsa1.deleteRow( "c", false );
6363             dmsa1.deleteGapOnlyColumns();
6364             final Writer w0 = new StringWriter();
6365             dmsa1.write( w0, MSA_FORMAT.FASTA );
6366             final Writer w1 = new StringWriter();
6367             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6368             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6369                 return false;
6370             }
6371             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6372                 return false;
6373             }
6374             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6375             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6376             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6377             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6378             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6379             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6380             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6381             l2.add( s__0 );
6382             l2.add( s__1 );
6383             l2.add( s__2 );
6384             l2.add( s__3 );
6385             l2.add( s__4 );
6386             l2.add( s__5 );
6387             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6388             dmsa2.deleteGapColumns( 0.5 );
6389             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6390                 return false;
6391             }
6392             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6393                 return false;
6394             }
6395             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6396                 return false;
6397             }
6398             dmsa2.deleteGapColumns( 0.2 );
6399             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6400                 return false;
6401             }
6402             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6403                 return false;
6404             }
6405             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6406                 return false;
6407             }
6408             dmsa2.deleteGapColumns( 0 );
6409             dmsa2.deleteRow( "a", false );
6410             dmsa2.deleteRow( "b", false );
6411             dmsa2.deleteRow( "f", false );
6412             dmsa2.deleteRow( "e", false );
6413             dmsa2.setIdentifier( 0, "new_c" );
6414             dmsa2.setIdentifier( 1, "new_d" );
6415             dmsa2.setResidueAt( 0, 0, 'x' );
6416             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6417             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6418                 return false;
6419             }
6420             final Writer w = new StringWriter();
6421             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6422             final String phylip = w.toString();
6423             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6424                 System.out.println( phylip );
6425                 return false;
6426             }
6427             final Writer w2 = new StringWriter();
6428             dmsa2.write( w2, MSA_FORMAT.FASTA );
6429             final String fasta = w2.toString();
6430             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6431                 System.out.println( fasta );
6432                 return false;
6433             }
6434         }
6435         catch ( final Exception e ) {
6436             e.printStackTrace( System.out );
6437             return false;
6438         }
6439         return true;
6440     }
6441
6442     private static boolean testNextNodeWithCollapsing() {
6443         try {
6444             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6445             PhylogenyNode n;
6446             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6447             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6448             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6449             t0.getNode( "cd" ).setCollapse( true );
6450             t0.getNode( "cde" ).setCollapse( true );
6451             n = t0.getFirstExternalNode();
6452             while ( n != null ) {
6453                 ext.add( n );
6454                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6455             }
6456             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6457                 return false;
6458             }
6459             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6460                 return false;
6461             }
6462             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6463                 return false;
6464             }
6465             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6466                 return false;
6467             }
6468             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6469                 return false;
6470             }
6471             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6472                 return false;
6473             }
6474             ext.clear();
6475             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6476             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6477             t1.getNode( "ab" ).setCollapse( true );
6478             t1.getNode( "cd" ).setCollapse( true );
6479             t1.getNode( "cde" ).setCollapse( true );
6480             n = t1.getNode( "ab" );
6481             ext = new ArrayList<PhylogenyNode>();
6482             while ( n != null ) {
6483                 ext.add( n );
6484                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6485             }
6486             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6490                 return false;
6491             }
6492             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6493                 return false;
6494             }
6495             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6496                 return false;
6497             }
6498             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6499                 return false;
6500             }
6501             ext.clear();
6502             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6503             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6504             t2.getNode( "ab" ).setCollapse( true );
6505             t2.getNode( "cd" ).setCollapse( true );
6506             t2.getNode( "cde" ).setCollapse( true );
6507             t2.getNode( "c" ).setCollapse( true );
6508             t2.getNode( "d" ).setCollapse( true );
6509             t2.getNode( "e" ).setCollapse( true );
6510             t2.getNode( "gh" ).setCollapse( true );
6511             n = t2.getNode( "ab" );
6512             ext = new ArrayList<PhylogenyNode>();
6513             while ( n != null ) {
6514                 ext.add( n );
6515                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6516             }
6517             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6518                 return false;
6519             }
6520             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6521                 return false;
6522             }
6523             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6524                 return false;
6525             }
6526             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6527                 return false;
6528             }
6529             ext.clear();
6530             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6531             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6532             t3.getNode( "ab" ).setCollapse( true );
6533             t3.getNode( "cd" ).setCollapse( true );
6534             t3.getNode( "cde" ).setCollapse( true );
6535             t3.getNode( "c" ).setCollapse( true );
6536             t3.getNode( "d" ).setCollapse( true );
6537             t3.getNode( "e" ).setCollapse( true );
6538             t3.getNode( "gh" ).setCollapse( true );
6539             t3.getNode( "fgh" ).setCollapse( true );
6540             n = t3.getNode( "ab" );
6541             ext = new ArrayList<PhylogenyNode>();
6542             while ( n != null ) {
6543                 ext.add( n );
6544                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6545             }
6546             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6547                 return false;
6548             }
6549             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6550                 return false;
6551             }
6552             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6553                 return false;
6554             }
6555             ext.clear();
6556             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6557             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6558             t4.getNode( "ab" ).setCollapse( true );
6559             t4.getNode( "cd" ).setCollapse( true );
6560             t4.getNode( "cde" ).setCollapse( true );
6561             t4.getNode( "c" ).setCollapse( true );
6562             t4.getNode( "d" ).setCollapse( true );
6563             t4.getNode( "e" ).setCollapse( true );
6564             t4.getNode( "gh" ).setCollapse( true );
6565             t4.getNode( "fgh" ).setCollapse( true );
6566             t4.getNode( "abcdefgh" ).setCollapse( true );
6567             n = t4.getNode( "abcdefgh" );
6568             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6569                 return false;
6570             }
6571             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6572             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6573             ext.clear();
6574             n = t5.getFirstExternalNode();
6575             while ( n != null ) {
6576                 ext.add( n );
6577                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6578             }
6579             if ( ext.size() != 8 ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6595                 return false;
6596             }
6597             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6598                 return false;
6599             }
6600             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6601                 return false;
6602             }
6603             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6604                 return false;
6605             }
6606             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6607             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6608             ext.clear();
6609             t6.getNode( "ab" ).setCollapse( true );
6610             n = t6.getNode( "ab" );
6611             while ( n != null ) {
6612                 ext.add( n );
6613                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6614             }
6615             if ( ext.size() != 7 ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6628                 return false;
6629             }
6630             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6631                 return false;
6632             }
6633             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6634                 return false;
6635             }
6636             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6637                 return false;
6638             }
6639             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6640             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6641             ext.clear();
6642             t7.getNode( "cd" ).setCollapse( true );
6643             n = t7.getNode( "a" );
6644             while ( n != null ) {
6645                 ext.add( n );
6646                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6647             }
6648             if ( ext.size() != 7 ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6661                 return false;
6662             }
6663             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6664                 return false;
6665             }
6666             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6667                 return false;
6668             }
6669             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6670                 return false;
6671             }
6672             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6673             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6674             ext.clear();
6675             t8.getNode( "cd" ).setCollapse( true );
6676             t8.getNode( "c" ).setCollapse( true );
6677             t8.getNode( "d" ).setCollapse( true );
6678             n = t8.getNode( "a" );
6679             while ( n != null ) {
6680                 ext.add( n );
6681                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6682             }
6683             if ( ext.size() != 7 ) {
6684                 return false;
6685             }
6686             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6687                 return false;
6688             }
6689             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6690                 return false;
6691             }
6692             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6693                 System.out.println( "2 fail" );
6694                 return false;
6695             }
6696             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6697                 return false;
6698             }
6699             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6700                 return false;
6701             }
6702             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6703                 return false;
6704             }
6705             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6706                 return false;
6707             }
6708             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6709             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6710             ext.clear();
6711             t9.getNode( "gh" ).setCollapse( true );
6712             n = t9.getNode( "a" );
6713             while ( n != null ) {
6714                 ext.add( n );
6715                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6716             }
6717             if ( ext.size() != 7 ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6724                 return false;
6725             }
6726             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6727                 return false;
6728             }
6729             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6730                 return false;
6731             }
6732             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6733                 return false;
6734             }
6735             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6736                 return false;
6737             }
6738             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6739                 return false;
6740             }
6741             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6742             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6743             ext.clear();
6744             t10.getNode( "gh" ).setCollapse( true );
6745             t10.getNode( "g" ).setCollapse( true );
6746             t10.getNode( "h" ).setCollapse( true );
6747             n = t10.getNode( "a" );
6748             while ( n != null ) {
6749                 ext.add( n );
6750                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6751             }
6752             if ( ext.size() != 7 ) {
6753                 return false;
6754             }
6755             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6756                 return false;
6757             }
6758             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6759                 return false;
6760             }
6761             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6762                 return false;
6763             }
6764             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6765                 return false;
6766             }
6767             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6768                 return false;
6769             }
6770             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6771                 return false;
6772             }
6773             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6774                 return false;
6775             }
6776             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6777             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6778             ext.clear();
6779             t11.getNode( "gh" ).setCollapse( true );
6780             t11.getNode( "fgh" ).setCollapse( true );
6781             n = t11.getNode( "a" );
6782             while ( n != null ) {
6783                 ext.add( n );
6784                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6785             }
6786             if ( ext.size() != 6 ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6796                 return false;
6797             }
6798             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6799                 return false;
6800             }
6801             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6802                 return false;
6803             }
6804             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6805                 return false;
6806             }
6807             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6808             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6809             ext.clear();
6810             t12.getNode( "gh" ).setCollapse( true );
6811             t12.getNode( "fgh" ).setCollapse( true );
6812             t12.getNode( "g" ).setCollapse( true );
6813             t12.getNode( "h" ).setCollapse( true );
6814             t12.getNode( "f" ).setCollapse( true );
6815             n = t12.getNode( "a" );
6816             while ( n != null ) {
6817                 ext.add( n );
6818                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6819             }
6820             if ( ext.size() != 6 ) {
6821                 return false;
6822             }
6823             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6824                 return false;
6825             }
6826             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6827                 return false;
6828             }
6829             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6830                 return false;
6831             }
6832             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6833                 return false;
6834             }
6835             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6836                 return false;
6837             }
6838             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6839                 return false;
6840             }
6841             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6842             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6843             ext.clear();
6844             t13.getNode( "ab" ).setCollapse( true );
6845             t13.getNode( "b" ).setCollapse( true );
6846             t13.getNode( "fgh" ).setCollapse( true );
6847             t13.getNode( "gh" ).setCollapse( true );
6848             n = t13.getNode( "ab" );
6849             while ( n != null ) {
6850                 ext.add( n );
6851                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6852             }
6853             if ( ext.size() != 5 ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6857                 return false;
6858             }
6859             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6860                 return false;
6861             }
6862             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6863                 return false;
6864             }
6865             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6866                 return false;
6867             }
6868             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6869                 return false;
6870             }
6871             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6872             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6873             ext.clear();
6874             t14.getNode( "ab" ).setCollapse( true );
6875             t14.getNode( "a" ).setCollapse( true );
6876             t14.getNode( "fgh" ).setCollapse( true );
6877             t14.getNode( "gh" ).setCollapse( true );
6878             n = t14.getNode( "ab" );
6879             while ( n != null ) {
6880                 ext.add( n );
6881                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6882             }
6883             if ( ext.size() != 5 ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6887                 return false;
6888             }
6889             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6890                 return false;
6891             }
6892             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6893                 return false;
6894             }
6895             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6896                 return false;
6897             }
6898             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6899                 return false;
6900             }
6901             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" );
6902             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6903             ext.clear();
6904             t15.getNode( "ab" ).setCollapse( true );
6905             t15.getNode( "a" ).setCollapse( true );
6906             t15.getNode( "fgh" ).setCollapse( true );
6907             t15.getNode( "gh" ).setCollapse( true );
6908             n = t15.getNode( "ab" );
6909             while ( n != null ) {
6910                 ext.add( n );
6911                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6912             }
6913             if ( ext.size() != 6 ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6920                 return false;
6921             }
6922             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6923                 return false;
6924             }
6925             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6926                 return false;
6927             }
6928             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6929                 return false;
6930             }
6931             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6932                 return false;
6933             }
6934             //
6935             //
6936             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" );
6937             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6938             ext.clear();
6939             t16.getNode( "ab" ).setCollapse( true );
6940             t16.getNode( "a" ).setCollapse( true );
6941             t16.getNode( "fgh" ).setCollapse( true );
6942             t16.getNode( "gh" ).setCollapse( true );
6943             t16.getNode( "cd" ).setCollapse( true );
6944             t16.getNode( "cde" ).setCollapse( true );
6945             t16.getNode( "d" ).setCollapse( true );
6946             t16.getNode( "x" ).setCollapse( true );
6947             n = t16.getNode( "ab" );
6948             while ( n != null ) {
6949                 ext.add( n );
6950                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6951             }
6952             if ( ext.size() != 4 ) {
6953                 return false;
6954             }
6955             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6956                 return false;
6957             }
6958             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6959                 return false;
6960             }
6961             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6962                 return false;
6963             }
6964             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6965                 return false;
6966             }
6967         }
6968         catch ( final Exception e ) {
6969             e.printStackTrace( System.out );
6970             return false;
6971         }
6972         return true;
6973     }
6974
6975     private static boolean testNexusCharactersParsing() {
6976         try {
6977             final NexusCharactersParser parser = new NexusCharactersParser();
6978             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6979             parser.parse();
6980             String[] labels = parser.getCharStateLabels();
6981             if ( labels.length != 7 ) {
6982                 return false;
6983             }
6984             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6985                 return false;
6986             }
6987             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6988                 return false;
6989             }
6990             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6991                 return false;
6992             }
6993             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6994                 return false;
6995             }
6996             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6997                 return false;
6998             }
6999             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7000                 return false;
7001             }
7002             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7003                 return false;
7004             }
7005             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7006             parser.parse();
7007             labels = parser.getCharStateLabels();
7008             if ( labels.length != 7 ) {
7009                 return false;
7010             }
7011             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7012                 return false;
7013             }
7014             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7015                 return false;
7016             }
7017             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7018                 return false;
7019             }
7020             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7021                 return false;
7022             }
7023             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7024                 return false;
7025             }
7026             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7027                 return false;
7028             }
7029             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7030                 return false;
7031             }
7032         }
7033         catch ( final Exception e ) {
7034             e.printStackTrace( System.out );
7035             return false;
7036         }
7037         return true;
7038     }
7039
7040     private static boolean testNexusMatrixParsing() {
7041         try {
7042             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7043             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7044             parser.parse();
7045             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7046             if ( m.getNumberOfCharacters() != 9 ) {
7047                 return false;
7048             }
7049             if ( m.getNumberOfIdentifiers() != 5 ) {
7050                 return false;
7051             }
7052             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7053                 return false;
7054             }
7055             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7056                 return false;
7057             }
7058             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7059                 return false;
7060             }
7061             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7062                 return false;
7063             }
7064             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7065                 return false;
7066             }
7067             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7068                 return false;
7069             }
7070             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7071                 return false;
7072             }
7073             //            if ( labels.length != 7 ) {
7074             //                return false;
7075             //            }
7076             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7077             //                return false;
7078             //            }
7079             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7080             //                return false;
7081             //            }
7082             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7083             //                return false;
7084             //            }
7085             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7086             //                return false;
7087             //            }
7088             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7089             //                return false;
7090             //            }
7091             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7092             //                return false;
7093             //            }
7094             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7095             //                return false;
7096             //            }
7097             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7098             //            parser.parse();
7099             //            labels = parser.getCharStateLabels();
7100             //            if ( labels.length != 7 ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7104             //                return false;
7105             //            }
7106             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7107             //                return false;
7108             //            }
7109             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7110             //                return false;
7111             //            }
7112             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7113             //                return false;
7114             //            }
7115             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7116             //                return false;
7117             //            }
7118             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7119             //                return false;
7120             //            }
7121             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7122             //                return false;
7123             //            }
7124         }
7125         catch ( final Exception e ) {
7126             e.printStackTrace( System.out );
7127             return false;
7128         }
7129         return true;
7130     }
7131
7132     private static boolean testNexusTreeParsing() {
7133         try {
7134             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7135             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7136             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7137             if ( phylogenies.length != 1 ) {
7138                 return false;
7139             }
7140             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7141                 return false;
7142             }
7143             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7144                 return false;
7145             }
7146             phylogenies = null;
7147             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7148             if ( phylogenies.length != 1 ) {
7149                 return false;
7150             }
7151             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7152                 return false;
7153             }
7154             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7155                 return false;
7156             }
7157             phylogenies = null;
7158             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7159             if ( phylogenies.length != 1 ) {
7160                 return false;
7161             }
7162             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7163                 return false;
7164             }
7165             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7166                 return false;
7167             }
7168             if ( phylogenies[ 0 ].isRooted() ) {
7169                 return false;
7170             }
7171             phylogenies = null;
7172             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7173             if ( phylogenies.length != 18 ) {
7174                 return false;
7175             }
7176             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7177                 return false;
7178             }
7179             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7180                 return false;
7181             }
7182             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7183                 return false;
7184             }
7185             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7186                 return false;
7187             }
7188             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7189                 return false;
7190             }
7191             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7192                 return false;
7193             }
7194             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7195                 return false;
7196             }
7197             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7198                 return false;
7199             }
7200             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7201                 return false;
7202             }
7203             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7204                 return false;
7205             }
7206             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7207                 return false;
7208             }
7209             if ( phylogenies[ 8 ].isRooted() ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7216                 return false;
7217             }
7218             if ( !phylogenies[ 9 ].isRooted() ) {
7219                 return false;
7220             }
7221             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7225                 return false;
7226             }
7227             if ( !phylogenies[ 10 ].isRooted() ) {
7228                 return false;
7229             }
7230             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7231                 return false;
7232             }
7233             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7234                 return false;
7235             }
7236             if ( phylogenies[ 11 ].isRooted() ) {
7237                 return false;
7238             }
7239             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 12 ].isRooted() ) {
7246                 return false;
7247             }
7248             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7249                 return false;
7250             }
7251             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7252                 return false;
7253             }
7254             if ( !phylogenies[ 13 ].isRooted() ) {
7255                 return false;
7256             }
7257             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7258                 return false;
7259             }
7260             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7261                 return false;
7262             }
7263             if ( !phylogenies[ 14 ].isRooted() ) {
7264                 return false;
7265             }
7266             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7270                 return false;
7271             }
7272             if ( phylogenies[ 15 ].isRooted() ) {
7273                 return false;
7274             }
7275             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7276                 return false;
7277             }
7278             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7279                 return false;
7280             }
7281             if ( !phylogenies[ 16 ].isRooted() ) {
7282                 return false;
7283             }
7284             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7285                 return false;
7286             }
7287             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7288                 return false;
7289             }
7290             if ( phylogenies[ 17 ].isRooted() ) {
7291                 return false;
7292             }
7293             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7294                 return false;
7295             }
7296             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7297             phylogenies = null;
7298             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7299             if ( phylogenies.length != 9 ) {
7300                 return false;
7301             }
7302             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7303                     .getDistanceToParent() ) ) {
7304                 return false;
7305             }
7306             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7307                     .getDistanceToParent() ) ) {
7308                 return false;
7309             }
7310             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7311                 return false;
7312             }
7313             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7314                 return false;
7315             }
7316             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7317                 return false;
7318             }
7319             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7320                 return false;
7321             }
7322             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7323                 return false;
7324             }
7325         }
7326         catch ( final Exception e ) {
7327             e.printStackTrace( System.out );
7328             return false;
7329         }
7330         return true;
7331     }
7332
7333     private static boolean testNexusTreeParsingIterating() {
7334         try {
7335             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7336             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7337             if ( !p.hasNext() ) {
7338                 return false;
7339             }
7340             Phylogeny phy = p.next();
7341             if ( phy == null ) {
7342                 return false;
7343             }
7344             if ( phy.getNumberOfExternalNodes() != 25 ) {
7345                 return false;
7346             }
7347             if ( !phy.getName().equals( "" ) ) {
7348                 return false;
7349             }
7350             if ( p.hasNext() ) {
7351                 return false;
7352             }
7353             phy = p.next();
7354             if ( phy != null ) {
7355                 return false;
7356             }
7357             p.reset();
7358             if ( !p.hasNext() ) {
7359                 return false;
7360             }
7361             phy = p.next();
7362             if ( phy == null ) {
7363                 return false;
7364             }
7365             if ( phy.getNumberOfExternalNodes() != 25 ) {
7366                 return false;
7367             }
7368             if ( !phy.getName().equals( "" ) ) {
7369                 return false;
7370             }
7371             if ( p.hasNext() ) {
7372                 return false;
7373             }
7374             phy = p.next();
7375             if ( phy != null ) {
7376                 return false;
7377             }
7378             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             phy = p.next();
7383             if ( phy == null ) {
7384                 return false;
7385             }
7386             if ( phy.getNumberOfExternalNodes() != 10 ) {
7387                 return false;
7388             }
7389             if ( !phy.getName().equals( "name" ) ) {
7390                 return false;
7391             }
7392             if ( p.hasNext() ) {
7393                 return false;
7394             }
7395             phy = p.next();
7396             if ( phy != null ) {
7397                 return false;
7398             }
7399             p.reset();
7400             if ( !p.hasNext() ) {
7401                 return false;
7402             }
7403             phy = p.next();
7404             if ( phy == null ) {
7405                 return false;
7406             }
7407             if ( phy.getNumberOfExternalNodes() != 10 ) {
7408                 return false;
7409             }
7410             if ( !phy.getName().equals( "name" ) ) {
7411                 return false;
7412             }
7413             if ( p.hasNext() ) {
7414                 return false;
7415             }
7416             phy = p.next();
7417             if ( phy != null ) {
7418                 return false;
7419             }
7420             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7421             if ( !p.hasNext() ) {
7422                 return false;
7423             }
7424             phy = p.next();
7425             if ( phy == null ) {
7426                 return false;
7427             }
7428             if ( phy.getNumberOfExternalNodes() != 3 ) {
7429                 return false;
7430             }
7431             if ( !phy.getName().equals( "" ) ) {
7432                 return false;
7433             }
7434             if ( phy.isRooted() ) {
7435                 return false;
7436             }
7437             if ( p.hasNext() ) {
7438                 return false;
7439             }
7440             phy = p.next();
7441             if ( phy != null ) {
7442                 return false;
7443             }
7444             //
7445             p.reset();
7446             if ( !p.hasNext() ) {
7447                 return false;
7448             }
7449             phy = p.next();
7450             if ( phy == null ) {
7451                 return false;
7452             }
7453             if ( phy.getNumberOfExternalNodes() != 3 ) {
7454                 return false;
7455             }
7456             if ( !phy.getName().equals( "" ) ) {
7457                 return false;
7458             }
7459             if ( p.hasNext() ) {
7460                 return false;
7461             }
7462             phy = p.next();
7463             if ( phy != null ) {
7464                 return false;
7465             }
7466             //
7467             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7468             if ( !p.hasNext() ) {
7469                 return false;
7470             }
7471             //0
7472             phy = p.next();
7473             if ( phy == null ) {
7474                 return false;
7475             }
7476             if ( phy.getNumberOfExternalNodes() != 10 ) {
7477                 return false;
7478             }
7479             if ( !phy.getName().equals( "tree 0" ) ) {
7480                 return false;
7481             }
7482             //1
7483             if ( !p.hasNext() ) {
7484                 return false;
7485             }
7486             phy = p.next();
7487             if ( phy == null ) {
7488                 return false;
7489             }
7490             if ( phy.getNumberOfExternalNodes() != 10 ) {
7491                 return false;
7492             }
7493             if ( !phy.getName().equals( "tree 1" ) ) {
7494                 return false;
7495             }
7496             //2
7497             if ( !p.hasNext() ) {
7498                 return false;
7499             }
7500             phy = p.next();
7501             if ( phy == null ) {
7502                 return false;
7503             }
7504             if ( phy.getNumberOfExternalNodes() != 3 ) {
7505                 System.out.println( phy.toString() );
7506                 return false;
7507             }
7508             if ( !phy.getName().equals( "" ) ) {
7509                 return false;
7510             }
7511             if ( phy.isRooted() ) {
7512                 return false;
7513             }
7514             //3
7515             if ( !p.hasNext() ) {
7516                 return false;
7517             }
7518             phy = p.next();
7519             if ( phy == null ) {
7520                 return false;
7521             }
7522             if ( phy.getNumberOfExternalNodes() != 4 ) {
7523                 return false;
7524             }
7525             if ( !phy.getName().equals( "" ) ) {
7526                 return false;
7527             }
7528             if ( !phy.isRooted() ) {
7529                 return false;
7530             }
7531             //4
7532             if ( !p.hasNext() ) {
7533                 return false;
7534             }
7535             phy = p.next();
7536             if ( phy == null ) {
7537                 return false;
7538             }
7539             if ( phy.getNumberOfExternalNodes() != 5 ) {
7540                 System.out.println( phy.getNumberOfExternalNodes() );
7541                 return false;
7542             }
7543             if ( !phy.getName().equals( "" ) ) {
7544                 return false;
7545             }
7546             if ( !phy.isRooted() ) {
7547                 return false;
7548             }
7549             //5
7550             if ( !p.hasNext() ) {
7551                 return false;
7552             }
7553             phy = p.next();
7554             if ( phy == null ) {
7555                 return false;
7556             }
7557             if ( phy.getNumberOfExternalNodes() != 3 ) {
7558                 return false;
7559             }
7560             if ( !phy.getName().equals( "" ) ) {
7561                 return false;
7562             }
7563             if ( phy.isRooted() ) {
7564                 return false;
7565             }
7566             //6
7567             if ( !p.hasNext() ) {
7568                 return false;
7569             }
7570             phy = p.next();
7571             if ( phy == null ) {
7572                 return false;
7573             }
7574             if ( phy.getNumberOfExternalNodes() != 2 ) {
7575                 return false;
7576             }
7577             if ( !phy.getName().equals( "" ) ) {
7578                 return false;
7579             }
7580             if ( !phy.isRooted() ) {
7581                 return false;
7582             }
7583             //7
7584             if ( !p.hasNext() ) {
7585                 return false;
7586             }
7587             phy = p.next();
7588             if ( phy.getNumberOfExternalNodes() != 3 ) {
7589                 return false;
7590             }
7591             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7592                 return false;
7593             }
7594             if ( !phy.isRooted() ) {
7595                 return false;
7596             }
7597             //8
7598             if ( !p.hasNext() ) {
7599                 return false;
7600             }
7601             phy = p.next();
7602             if ( phy.getNumberOfExternalNodes() != 3 ) {
7603                 return false;
7604             }
7605             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7606                 return false;
7607             }
7608             if ( !phy.getName().equals( "tree 8" ) ) {
7609                 return false;
7610             }
7611             //9
7612             if ( !p.hasNext() ) {
7613                 return false;
7614             }
7615             phy = p.next();
7616             if ( phy.getNumberOfExternalNodes() != 3 ) {
7617                 return false;
7618             }
7619             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7620                 return false;
7621             }
7622             if ( !phy.getName().equals( "tree 9" ) ) {
7623                 return false;
7624             }
7625             //10
7626             if ( !p.hasNext() ) {
7627                 return false;
7628             }
7629             phy = p.next();
7630             if ( phy.getNumberOfExternalNodes() != 3 ) {
7631                 return false;
7632             }
7633             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7634                 return false;
7635             }
7636             if ( !phy.getName().equals( "tree 10" ) ) {
7637                 return false;
7638             }
7639             if ( !phy.isRooted() ) {
7640                 return false;
7641             }
7642             //11
7643             if ( !p.hasNext() ) {
7644                 return false;
7645             }
7646             phy = p.next();
7647             if ( phy.getNumberOfExternalNodes() != 3 ) {
7648                 return false;
7649             }
7650             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7651                 return false;
7652             }
7653             if ( !phy.getName().equals( "tree 11" ) ) {
7654                 return false;
7655             }
7656             if ( phy.isRooted() ) {
7657                 return false;
7658             }
7659             //12
7660             if ( !p.hasNext() ) {
7661                 return false;
7662             }
7663             phy = p.next();
7664             if ( phy.getNumberOfExternalNodes() != 3 ) {
7665                 return false;
7666             }
7667             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7668                 return false;
7669             }
7670             if ( !phy.getName().equals( "tree 12" ) ) {
7671                 return false;
7672             }
7673             if ( !phy.isRooted() ) {
7674                 return false;
7675             }
7676             //13
7677             if ( !p.hasNext() ) {
7678                 return false;
7679             }
7680             phy = p.next();
7681             if ( phy.getNumberOfExternalNodes() != 3 ) {
7682                 return false;
7683             }
7684             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7685                 return false;
7686             }
7687             if ( !phy.getName().equals( "tree 13" ) ) {
7688                 return false;
7689             }
7690             if ( !phy.isRooted() ) {
7691                 return false;
7692             }
7693             //14
7694             if ( !p.hasNext() ) {
7695                 return false;
7696             }
7697             phy = p.next();
7698             if ( phy.getNumberOfExternalNodes() != 10 ) {
7699                 System.out.println( phy.getNumberOfExternalNodes() );
7700                 return false;
7701             }
7702             if ( !phy
7703                     .toNewHampshire()
7704                     .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;" ) ) {
7705                 System.out.println( phy.toNewHampshire() );
7706                 return false;
7707             }
7708             if ( !phy.getName().equals( "tree 14" ) ) {
7709                 return false;
7710             }
7711             if ( !phy.isRooted() ) {
7712                 return false;
7713             }
7714             //15
7715             if ( !p.hasNext() ) {
7716                 return false;
7717             }
7718             phy = p.next();
7719             if ( phy.getNumberOfExternalNodes() != 10 ) {
7720                 System.out.println( phy.getNumberOfExternalNodes() );
7721                 return false;
7722             }
7723             if ( !phy
7724                     .toNewHampshire()
7725                     .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;" ) ) {
7726                 System.out.println( phy.toNewHampshire() );
7727                 return false;
7728             }
7729             if ( !phy.getName().equals( "tree 15" ) ) {
7730                 return false;
7731             }
7732             if ( phy.isRooted() ) {
7733                 return false;
7734             }
7735             //16
7736             if ( !p.hasNext() ) {
7737                 return false;
7738             }
7739             phy = p.next();
7740             if ( phy.getNumberOfExternalNodes() != 10 ) {
7741                 System.out.println( phy.getNumberOfExternalNodes() );
7742                 return false;
7743             }
7744             if ( !phy
7745                     .toNewHampshire()
7746                     .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;" ) ) {
7747                 System.out.println( phy.toNewHampshire() );
7748                 return false;
7749             }
7750             if ( !phy.getName().equals( "tree 16" ) ) {
7751                 return false;
7752             }
7753             if ( !phy.isRooted() ) {
7754                 return false;
7755             }
7756             //17
7757             if ( !p.hasNext() ) {
7758                 return false;
7759             }
7760             phy = p.next();
7761             if ( phy.getNumberOfExternalNodes() != 10 ) {
7762                 System.out.println( phy.getNumberOfExternalNodes() );
7763                 return false;
7764             }
7765             if ( !phy
7766                     .toNewHampshire()
7767                     .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;" ) ) {
7768                 System.out.println( phy.toNewHampshire() );
7769                 return false;
7770             }
7771             if ( !phy.getName().equals( "tree 17" ) ) {
7772                 return false;
7773             }
7774             if ( phy.isRooted() ) {
7775                 return false;
7776             }
7777             //
7778             if ( p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy != null ) {
7783                 return false;
7784             }
7785             p.reset();
7786             //0
7787             if ( !p.hasNext() ) {
7788                 return false;
7789             }
7790             phy = p.next();
7791             if ( phy == null ) {
7792                 return false;
7793             }
7794             if ( phy.getNumberOfExternalNodes() != 10 ) {
7795                 return false;
7796             }
7797             if ( !phy.getName().equals( "tree 0" ) ) {
7798                 return false;
7799             }
7800             //1
7801             if ( !p.hasNext() ) {
7802                 return false;
7803             }
7804             phy = p.next();
7805             if ( phy == null ) {
7806                 return false;
7807             }
7808             if ( phy.getNumberOfExternalNodes() != 10 ) {
7809                 return false;
7810             }
7811             if ( !phy.getName().equals( "tree 1" ) ) {
7812                 return false;
7813             }
7814             //2
7815             if ( !p.hasNext() ) {
7816                 return false;
7817             }
7818             phy = p.next();
7819             if ( phy == null ) {
7820                 return false;
7821             }
7822             if ( phy.getNumberOfExternalNodes() != 3 ) {
7823                 return false;
7824             }
7825             if ( !phy.getName().equals( "" ) ) {
7826                 return false;
7827             }
7828             if ( phy.isRooted() ) {
7829                 return false;
7830             }
7831             //3
7832             if ( !p.hasNext() ) {
7833                 return false;
7834             }
7835             phy = p.next();
7836             if ( phy == null ) {
7837                 return false;
7838             }
7839             if ( phy.getNumberOfExternalNodes() != 4 ) {
7840                 return false;
7841             }
7842             if ( !phy.getName().equals( "" ) ) {
7843                 return false;
7844             }
7845             if ( !phy.isRooted() ) {
7846                 return false;
7847             }
7848             //4
7849             if ( !p.hasNext() ) {
7850                 return false;
7851             }
7852             phy = p.next();
7853             if ( phy == null ) {
7854                 return false;
7855             }
7856             if ( phy.getNumberOfExternalNodes() != 5 ) {
7857                 System.out.println( phy.getNumberOfExternalNodes() );
7858                 return false;
7859             }
7860             if ( !phy.getName().equals( "" ) ) {
7861                 return false;
7862             }
7863             if ( !phy.isRooted() ) {
7864                 return false;
7865             }
7866             //5
7867             if ( !p.hasNext() ) {
7868                 return false;
7869             }
7870             phy = p.next();
7871             if ( phy == null ) {
7872                 return false;
7873             }
7874             if ( phy.getNumberOfExternalNodes() != 3 ) {
7875                 return false;
7876             }
7877             if ( !phy.getName().equals( "" ) ) {
7878                 return false;
7879             }
7880             if ( phy.isRooted() ) {
7881                 return false;
7882             }
7883             //
7884             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7885             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7886             // 0
7887             if ( !p2.hasNext() ) {
7888                 return false;
7889             }
7890             phy = p2.next();
7891             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7892                 return false;
7893             }
7894             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7895                 return false;
7896             }
7897             // 1
7898             if ( !p2.hasNext() ) {
7899                 return false;
7900             }
7901             phy = p2.next();
7902             // 2
7903             if ( !p2.hasNext() ) {
7904                 return false;
7905             }
7906             phy = p2.next();
7907             // 3
7908             if ( !p2.hasNext() ) {
7909                 return false;
7910             }
7911             phy = p2.next();
7912             // 4
7913             if ( !p2.hasNext() ) {
7914                 return false;
7915             }
7916             phy = p2.next();
7917             // 5
7918             if ( !p2.hasNext() ) {
7919                 return false;
7920             }
7921             phy = p2.next();
7922             // 6
7923             if ( !p2.hasNext() ) {
7924                 return false;
7925             }
7926             phy = p2.next();
7927             // 7
7928             if ( !p2.hasNext() ) {
7929                 return false;
7930             }
7931             phy = p2.next();
7932             // 8
7933             if ( !p2.hasNext() ) {
7934                 return false;
7935             }
7936             phy = p2.next();
7937             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7938                 return false;
7939             }
7940             if ( p2.hasNext() ) {
7941                 return false;
7942             }
7943             phy = p2.next();
7944             if ( phy != null ) {
7945                 return false;
7946             }
7947             // 0
7948             p2.reset();
7949             if ( !p2.hasNext() ) {
7950                 return false;
7951             }
7952             phy = p2.next();
7953             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7954                 return false;
7955             }
7956             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7957                 return false;
7958             }
7959         }
7960         catch ( final Exception e ) {
7961             e.printStackTrace( System.out );
7962             return false;
7963         }
7964         return true;
7965     }
7966
7967     private static boolean testNexusTreeParsingTranslating() {
7968         try {
7969             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7970             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7971             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7972             if ( phylogenies.length != 1 ) {
7973                 return false;
7974             }
7975             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7976                 return false;
7977             }
7978             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7979                 return false;
7980             }
7981             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7982                 return false;
7983             }
7984             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7985                 return false;
7986             }
7987             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7988                     .equals( "Aranaeus" ) ) {
7989                 return false;
7990             }
7991             phylogenies = null;
7992             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7993             if ( phylogenies.length != 3 ) {
7994                 return false;
7995             }
7996             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7997                 return false;
7998             }
7999             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8000                 return false;
8001             }
8002             if ( phylogenies[ 0 ].isRooted() ) {
8003                 return false;
8004             }
8005             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8006                 return false;
8007             }
8008             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8009                 return false;
8010             }
8011             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8012                     .equals( "Aranaeus" ) ) {
8013                 return false;
8014             }
8015             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8016                 return false;
8017             }
8018             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8019                 return false;
8020             }
8021             if ( phylogenies[ 1 ].isRooted() ) {
8022                 return false;
8023             }
8024             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8025                 return false;
8026             }
8027             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8028                 return false;
8029             }
8030             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8031                     .equals( "Aranaeus" ) ) {
8032                 return false;
8033             }
8034             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8035                 return false;
8036             }
8037             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8038                 return false;
8039             }
8040             if ( !phylogenies[ 2 ].isRooted() ) {
8041                 return false;
8042             }
8043             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8044                 return false;
8045             }
8046             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8047                 return false;
8048             }
8049             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8050                     .equals( "Aranaeus" ) ) {
8051                 return false;
8052             }
8053             phylogenies = null;
8054             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8055             if ( phylogenies.length != 3 ) {
8056                 return false;
8057             }
8058             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8059                 return false;
8060             }
8061             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8062                 return false;
8063             }
8064             if ( phylogenies[ 0 ].isRooted() ) {
8065                 return false;
8066             }
8067             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8068                 return false;
8069             }
8070             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8071                 return false;
8072             }
8073             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8074                     .equals( "Aranaeus" ) ) {
8075                 return false;
8076             }
8077             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8078                 return false;
8079             }
8080             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8081                 return false;
8082             }
8083             if ( phylogenies[ 1 ].isRooted() ) {
8084                 return false;
8085             }
8086             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8087                 return false;
8088             }
8089             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8090                 return false;
8091             }
8092             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8093                     .equals( "Aranaeus" ) ) {
8094                 return false;
8095             }
8096             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8097                 return false;
8098             }
8099             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8100                 return false;
8101             }
8102             if ( !phylogenies[ 2 ].isRooted() ) {
8103                 return false;
8104             }
8105             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8106                 return false;
8107             }
8108             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8109                 return false;
8110             }
8111             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8112                     .equals( "Aranaeus" ) ) {
8113                 return false;
8114             }
8115             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8116             if ( phylogenies.length != 3 ) {
8117                 return false;
8118             }
8119             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8120                            0.00100049 ) ) {
8121                 return false;
8122             }
8123         }
8124         catch ( final Exception e ) {
8125             e.printStackTrace( System.out );
8126             return false;
8127         }
8128         return true;
8129     }
8130
8131     private static boolean testNHParsing() {
8132         try {
8133             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8134             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8135             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8136                 return false;
8137             }
8138             final NHXParser nhxp = new NHXParser();
8139             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8140             nhxp.setReplaceUnderscores( true );
8141             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8142             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8143                 return false;
8144             }
8145             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8146                 return false;
8147             }
8148             final Phylogeny p1b = factory
8149                     .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 ",
8150                              new NHXParser() )[ 0 ];
8151             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8152                 return false;
8153             }
8154             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8155                 return false;
8156             }
8157             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8158             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8159             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8160             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8161             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8162             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8163             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8164             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8165             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8166             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8167             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8168                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8169                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8170                                                     new NHXParser() );
8171             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8172                 return false;
8173             }
8174             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8175                 return false;
8176             }
8177             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8178                 return false;
8179             }
8180             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8181                 return false;
8182             }
8183             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8184             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8185             final String p16_S = "((A,B),C)";
8186             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8187             if ( p16.length != 1 ) {
8188                 return false;
8189             }
8190             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8191                 return false;
8192             }
8193             final String p17_S = "(C,(A,B))";
8194             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8195             if ( p17.length != 1 ) {
8196                 return false;
8197             }
8198             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8199                 return false;
8200             }
8201             final String p18_S = "((A,B),(C,D))";
8202             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8203             if ( p18.length != 1 ) {
8204                 return false;
8205             }
8206             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8207                 return false;
8208             }
8209             final String p19_S = "(((A,B),C),D)";
8210             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8211             if ( p19.length != 1 ) {
8212                 return false;
8213             }
8214             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8215                 return false;
8216             }
8217             final String p20_S = "(A,(B,(C,D)))";
8218             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8219             if ( p20.length != 1 ) {
8220                 return false;
8221             }
8222             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8223                 return false;
8224             }
8225             final String p21_S = "(A,(B,(C,(D,E))))";
8226             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8227             if ( p21.length != 1 ) {
8228                 return false;
8229             }
8230             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8231                 return false;
8232             }
8233             final String p22_S = "((((A,B),C),D),E)";
8234             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8235             if ( p22.length != 1 ) {
8236                 return false;
8237             }
8238             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8239                 return false;
8240             }
8241             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8242             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8243             if ( p23.length != 1 ) {
8244                 System.out.println( "xl=" + p23.length );
8245                 System.exit( -1 );
8246                 return false;
8247             }
8248             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8249                 return false;
8250             }
8251             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8252             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8253             if ( p24.length != 1 ) {
8254                 return false;
8255             }
8256             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8257                 return false;
8258             }
8259             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8260             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8261             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8262             if ( p241.length != 2 ) {
8263                 return false;
8264             }
8265             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8266                 return false;
8267             }
8268             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8269                 return false;
8270             }
8271             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8272                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8273                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8274                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8275                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8276                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8277                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8278                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8279             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8280             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8281                 return false;
8282             }
8283             final String p26_S = "(A,B)ab";
8284             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8285             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8286                 return false;
8287             }
8288             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8289             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8290             if ( p27s.length != 1 ) {
8291                 System.out.println( "xxl=" + p27s.length );
8292                 System.exit( -1 );
8293                 return false;
8294             }
8295             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8296                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8297                 System.exit( -1 );
8298                 return false;
8299             }
8300             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8301                                                     new NHXParser() );
8302             if ( p27.length != 1 ) {
8303                 System.out.println( "yl=" + p27.length );
8304                 System.exit( -1 );
8305                 return false;
8306             }
8307             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8308                 System.out.println( p27[ 0 ].toNewHampshireX() );
8309                 System.exit( -1 );
8310                 return false;
8311             }
8312             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8313             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8314             final String p28_S3 = "(A,B)ab";
8315             final String p28_S4 = "((((A,B),C),D),;E;)";
8316             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8317                                                     new NHXParser() );
8318             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8319                 return false;
8320             }
8321             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8322                 return false;
8323             }
8324             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8325                 return false;
8326             }
8327             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8328                 return false;
8329             }
8330             if ( p28.length != 4 ) {
8331                 return false;
8332             }
8333             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";
8334             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8335             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8336                 return false;
8337             }
8338             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";
8339             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8340             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8341                 return false;
8342             }
8343             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8344             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8345             if ( ( p32.length != 0 ) ) {
8346                 return false;
8347             }
8348             final String p33_S = "A";
8349             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8350             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8351                 return false;
8352             }
8353             final String p34_S = "B;";
8354             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8355             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8356                 return false;
8357             }
8358             final String p35_S = "B:0.2";
8359             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8360             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8361                 return false;
8362             }
8363             final String p36_S = "(A)";
8364             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8365             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8366                 return false;
8367             }
8368             final String p37_S = "((A))";
8369             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8370             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8371                 return false;
8372             }
8373             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8374             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8375             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8376                 return false;
8377             }
8378             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8379             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8380             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8381                 return false;
8382             }
8383             final String p40_S = "(A,B,C)";
8384             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8385             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8386                 return false;
8387             }
8388             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8389             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8390             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8391                 return false;
8392             }
8393             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8394             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8395             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8396                 return false;
8397             }
8398             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)";
8399             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8400             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8401                 return false;
8402             }
8403             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)))";
8404             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8405             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8406                 return false;
8407             }
8408             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8409             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8410             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8411                 return false;
8412             }
8413             final String p46_S = "";
8414             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8415             if ( p46.length != 0 ) {
8416                 return false;
8417             }
8418             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8419             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8420                 return false;
8421             }
8422             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8423             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8424                 return false;
8425             }
8426             final Phylogeny p49 = factory
8427                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8428                              new NHXParser() )[ 0 ];
8429             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8430                 return false;
8431             }
8432             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8433             if ( p50.getNode( "A" ) == null ) {
8434                 return false;
8435             }
8436             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8437                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8438                 return false;
8439             }
8440             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8441                 return false;
8442             }
8443             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8444                     .equals( "((A,B)88:2.0,C);" ) ) {
8445                 return false;
8446             }
8447             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8448             if ( p51.getNode( "A(A" ) == null ) {
8449                 return false;
8450             }
8451             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8452             if ( p52.getNode( "A(A" ) == null ) {
8453                 return false;
8454             }
8455             final Phylogeny p53 = factory
8456                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8457                              new NHXParser() )[ 0 ];
8458             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8459                 return false;
8460             }
8461             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8462             if ( p54.getNode( "A" ) == null ) {
8463                 return false;
8464             }
8465             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8466                 return false;
8467             }
8468             final Phylogeny p55 = factory
8469                     .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);" ),
8470                              new NHXParser() )[ 0 ];
8471             if ( !p55
8472                     .toNewHampshire()
8473                     .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);" ) ) {
8474                 System.out.println( p55.toNewHampshire() );
8475                 return false;
8476             }
8477             final Phylogeny p56 = factory
8478                     .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);" ),
8479                              new NHXParser() )[ 0 ];
8480             if ( !p56
8481                     .toNewHampshire()
8482                     .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);" ) ) {
8483                 System.out.println( p56.toNewHampshire() );
8484                 return false;
8485             }
8486             final Phylogeny p57 = factory
8487                     .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);" ),
8488                              new NHXParser() )[ 0 ];
8489             if ( !p57
8490                     .toNewHampshire()
8491                     .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);" ) ) {
8492                 System.out.println( p56.toNewHampshire() );
8493                 return false;
8494             }
8495             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8496             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8497             if ( !p58.toNewHampshire().equals( s58 ) ) {
8498                 System.out.println( p58.toNewHampshire() );
8499                 return false;
8500             }
8501             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8502             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8503             if ( !p59.toNewHampshire().equals( s59 ) ) {
8504                 System.out.println( p59.toNewHampshire() );
8505                 return false;
8506             }
8507             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8508             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8509             if ( !p60.toNewHampshire().equals( s60 ) ) {
8510                 System.out.println( p60.toNewHampshire() );
8511                 return false;
8512             }
8513             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8514             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8515             if ( !p61.toNewHampshire()
8516                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8517                 System.out.println( p61.toNewHampshire() );
8518                 return false;
8519             }
8520         }
8521         catch ( final Exception e ) {
8522             e.printStackTrace( System.out );
8523             return false;
8524         }
8525         return true;
8526     }
8527
8528     private static boolean testNHParsingIter() {
8529         try {
8530             final String p0_str = "(A,B);";
8531             final NHXParser p = new NHXParser();
8532             p.setSource( p0_str );
8533             if ( !p.hasNext() ) {
8534                 return false;
8535             }
8536             final Phylogeny p0 = p.next();
8537             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8538                 System.out.println( p0.toNewHampshire() );
8539                 return false;
8540             }
8541             if ( p.hasNext() ) {
8542                 return false;
8543             }
8544             if ( p.next() != null ) {
8545                 return false;
8546             }
8547             //
8548             final String p00_str = "(A,B)root;";
8549             p.setSource( p00_str );
8550             final Phylogeny p00 = p.next();
8551             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8552                 System.out.println( p00.toNewHampshire() );
8553                 return false;
8554             }
8555             //
8556             final String p000_str = "A;";
8557             p.setSource( p000_str );
8558             final Phylogeny p000 = p.next();
8559             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8560                 System.out.println( p000.toNewHampshire() );
8561                 return false;
8562             }
8563             //
8564             final String p0000_str = "A";
8565             p.setSource( p0000_str );
8566             final Phylogeny p0000 = p.next();
8567             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8568                 System.out.println( p0000.toNewHampshire() );
8569                 return false;
8570             }
8571             //
8572             p.setSource( "(A)" );
8573             final Phylogeny p00000 = p.next();
8574             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8575                 System.out.println( p00000.toNewHampshire() );
8576                 return false;
8577             }
8578             //
8579             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8580             p.setSource( p1_str );
8581             if ( !p.hasNext() ) {
8582                 return false;
8583             }
8584             final Phylogeny p1_0 = p.next();
8585             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8586                 System.out.println( p1_0.toNewHampshire() );
8587                 return false;
8588             }
8589             if ( !p.hasNext() ) {
8590                 return false;
8591             }
8592             final Phylogeny p1_1 = p.next();
8593             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8594                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8595                 return false;
8596             }
8597             if ( !p.hasNext() ) {
8598                 return false;
8599             }
8600             final Phylogeny p1_2 = p.next();
8601             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8602                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8603                 return false;
8604             }
8605             if ( !p.hasNext() ) {
8606                 return false;
8607             }
8608             final Phylogeny p1_3 = p.next();
8609             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8610                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8611                 return false;
8612             }
8613             if ( p.hasNext() ) {
8614                 return false;
8615             }
8616             if ( p.next() != null ) {
8617                 return false;
8618             }
8619             //
8620             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8621             p.setSource( p2_str );
8622             if ( !p.hasNext() ) {
8623                 return false;
8624             }
8625             Phylogeny p2_0 = p.next();
8626             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8627                 System.out.println( p2_0.toNewHampshire() );
8628                 return false;
8629             }
8630             if ( !p.hasNext() ) {
8631                 return false;
8632             }
8633             Phylogeny p2_1 = p.next();
8634             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8635                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8636                 return false;
8637             }
8638             if ( !p.hasNext() ) {
8639                 return false;
8640             }
8641             Phylogeny p2_2 = p.next();
8642             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8643                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8644                 return false;
8645             }
8646             if ( !p.hasNext() ) {
8647                 return false;
8648             }
8649             Phylogeny p2_3 = p.next();
8650             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8651                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8652                 return false;
8653             }
8654             if ( !p.hasNext() ) {
8655                 return false;
8656             }
8657             Phylogeny p2_4 = p.next();
8658             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8659                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8660                 return false;
8661             }
8662             if ( p.hasNext() ) {
8663                 return false;
8664             }
8665             if ( p.next() != null ) {
8666                 return false;
8667             }
8668             ////
8669             p.reset();
8670             if ( !p.hasNext() ) {
8671                 return false;
8672             }
8673             p2_0 = p.next();
8674             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8675                 System.out.println( p2_0.toNewHampshire() );
8676                 return false;
8677             }
8678             if ( !p.hasNext() ) {
8679                 return false;
8680             }
8681             p2_1 = p.next();
8682             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8683                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8684                 return false;
8685             }
8686             if ( !p.hasNext() ) {
8687                 return false;
8688             }
8689             p2_2 = p.next();
8690             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8691                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8692                 return false;
8693             }
8694             if ( !p.hasNext() ) {
8695                 return false;
8696             }
8697             p2_3 = p.next();
8698             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8699                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8700                 return false;
8701             }
8702             if ( !p.hasNext() ) {
8703                 return false;
8704             }
8705             p2_4 = p.next();
8706             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8707                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8708                 return false;
8709             }
8710             if ( p.hasNext() ) {
8711                 return false;
8712             }
8713             if ( p.next() != null ) {
8714                 return false;
8715             }
8716             //
8717             final String p3_str = "((A,B),C)abc";
8718             p.setSource( p3_str );
8719             if ( !p.hasNext() ) {
8720                 return false;
8721             }
8722             final Phylogeny p3_0 = p.next();
8723             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8724                 return false;
8725             }
8726             if ( p.hasNext() ) {
8727                 return false;
8728             }
8729             if ( p.next() != null ) {
8730                 return false;
8731             }
8732             //
8733             final String p4_str = "((A,B)ab,C)abc";
8734             p.setSource( p4_str );
8735             if ( !p.hasNext() ) {
8736                 return false;
8737             }
8738             final Phylogeny p4_0 = p.next();
8739             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8740                 return false;
8741             }
8742             if ( p.hasNext() ) {
8743                 return false;
8744             }
8745             if ( p.next() != null ) {
8746                 return false;
8747             }
8748             //
8749             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8750             p.setSource( p5_str );
8751             if ( !p.hasNext() ) {
8752                 return false;
8753             }
8754             final Phylogeny p5_0 = p.next();
8755             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8756                 return false;
8757             }
8758             if ( p.hasNext() ) {
8759                 return false;
8760             }
8761             if ( p.next() != null ) {
8762                 return false;
8763             }
8764             //
8765             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8766             p.setSource( p6_str );
8767             if ( !p.hasNext() ) {
8768                 return false;
8769             }
8770             Phylogeny p6_0 = p.next();
8771             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8772                 return false;
8773             }
8774             if ( p.hasNext() ) {
8775                 return false;
8776             }
8777             if ( p.next() != null ) {
8778                 return false;
8779             }
8780             p.reset();
8781             if ( !p.hasNext() ) {
8782                 return false;
8783             }
8784             p6_0 = p.next();
8785             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8786                 return false;
8787             }
8788             if ( p.hasNext() ) {
8789                 return false;
8790             }
8791             if ( p.next() != null ) {
8792                 return false;
8793             }
8794             //
8795             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8796             p.setSource( p7_str );
8797             if ( !p.hasNext() ) {
8798                 return false;
8799             }
8800             Phylogeny p7_0 = p.next();
8801             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8802                 return false;
8803             }
8804             if ( p.hasNext() ) {
8805                 return false;
8806             }
8807             if ( p.next() != null ) {
8808                 return false;
8809             }
8810             p.reset();
8811             if ( !p.hasNext() ) {
8812                 return false;
8813             }
8814             p7_0 = p.next();
8815             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8816                 return false;
8817             }
8818             if ( p.hasNext() ) {
8819                 return false;
8820             }
8821             if ( p.next() != null ) {
8822                 return false;
8823             }
8824             //
8825             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8826             p.setSource( p8_str );
8827             if ( !p.hasNext() ) {
8828                 return false;
8829             }
8830             Phylogeny p8_0 = p.next();
8831             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8832                 return false;
8833             }
8834             if ( !p.hasNext() ) {
8835                 return false;
8836             }
8837             if ( !p.hasNext() ) {
8838                 return false;
8839             }
8840             Phylogeny p8_1 = p.next();
8841             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8842                 return false;
8843             }
8844             if ( p.hasNext() ) {
8845                 return false;
8846             }
8847             if ( p.next() != null ) {
8848                 return false;
8849             }
8850             p.reset();
8851             if ( !p.hasNext() ) {
8852                 return false;
8853             }
8854             p8_0 = p.next();
8855             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8856                 return false;
8857             }
8858             if ( !p.hasNext() ) {
8859                 return false;
8860             }
8861             p8_1 = p.next();
8862             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8863                 return false;
8864             }
8865             if ( p.hasNext() ) {
8866                 return false;
8867             }
8868             if ( p.next() != null ) {
8869                 return false;
8870             }
8871             p.reset();
8872             //
8873             p.setSource( "" );
8874             if ( p.hasNext() ) {
8875                 return false;
8876             }
8877             //
8878             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8879             if ( !p.hasNext() ) {
8880                 return false;
8881             }
8882             Phylogeny p_27 = p.next();
8883             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8884                 System.out.println( p_27.toNewHampshireX() );
8885                 System.exit( -1 );
8886                 return false;
8887             }
8888             if ( p.hasNext() ) {
8889                 return false;
8890             }
8891             if ( p.next() != null ) {
8892                 return false;
8893             }
8894             p.reset();
8895             if ( !p.hasNext() ) {
8896                 return false;
8897             }
8898             p_27 = p.next();
8899             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8900                 System.out.println( p_27.toNewHampshireX() );
8901                 System.exit( -1 );
8902                 return false;
8903             }
8904             if ( p.hasNext() ) {
8905                 return false;
8906             }
8907             if ( p.next() != null ) {
8908                 return false;
8909             }
8910             //
8911             final String p30_str = "(A,B);(C,D)";
8912             final NHXParser p30 = new NHXParser();
8913             p30.setSource( p30_str );
8914             if ( !p30.hasNext() ) {
8915                 return false;
8916             }
8917             Phylogeny phy30 = p30.next();
8918             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8919                 System.out.println( phy30.toNewHampshire() );
8920                 return false;
8921             }
8922             if ( !p30.hasNext() ) {
8923                 return false;
8924             }
8925             Phylogeny phy301 = p30.next();
8926             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8927                 System.out.println( phy301.toNewHampshire() );
8928                 return false;
8929             }
8930             if ( p30.hasNext() ) {
8931                 return false;
8932             }
8933             if ( p30.hasNext() ) {
8934                 return false;
8935             }
8936             if ( p30.next() != null ) {
8937                 return false;
8938             }
8939             if ( p30.next() != null ) {
8940                 return false;
8941             }
8942             p30.reset();
8943             if ( !p30.hasNext() ) {
8944                 return false;
8945             }
8946             phy30 = p30.next();
8947             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8948                 System.out.println( phy30.toNewHampshire() );
8949                 return false;
8950             }
8951             if ( !p30.hasNext() ) {
8952                 return false;
8953             }
8954             phy301 = p30.next();
8955             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8956                 System.out.println( phy301.toNewHampshire() );
8957                 return false;
8958             }
8959             if ( p30.hasNext() ) {
8960                 return false;
8961             }
8962             if ( p30.hasNext() ) {
8963                 return false;
8964             }
8965             if ( p30.next() != null ) {
8966                 return false;
8967             }
8968             if ( p30.next() != null ) {
8969                 return false;
8970             }
8971         }
8972         catch ( final Exception e ) {
8973             e.printStackTrace( System.out );
8974             return false;
8975         }
8976         return true;
8977     }
8978
8979     private static boolean testNHXconversion() {
8980         try {
8981             final PhylogenyNode n1 = new PhylogenyNode();
8982             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8983             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8984             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8985             final PhylogenyNode n5 = PhylogenyNode
8986                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8987             final PhylogenyNode n6 = PhylogenyNode
8988                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8989             if ( !n1.toNewHampshireX().equals( "" ) ) {
8990                 return false;
8991             }
8992             if ( !n2.toNewHampshireX().equals( "" ) ) {
8993                 return false;
8994             }
8995             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8996                 return false;
8997             }
8998             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8999                 return false;
9000             }
9001             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9002                 return false;
9003             }
9004             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9005                 System.out.println( n6.toNewHampshireX() );
9006                 return false;
9007             }
9008             final PhylogenyNode n7 = new PhylogenyNode();
9009             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9010             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9011                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9012                 System.out.println( n7
9013                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9014                 return false;
9015             }
9016         }
9017         catch ( final Exception e ) {
9018             e.printStackTrace( System.out );
9019             return false;
9020         }
9021         return true;
9022     }
9023
9024     private static boolean testNHXNodeParsing() {
9025         try {
9026             final PhylogenyNode n1 = new PhylogenyNode();
9027             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9028             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9029             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9030             final PhylogenyNode n5 = PhylogenyNode
9031                     .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]" );
9032             if ( !n3.getName().equals( "n3" ) ) {
9033                 return false;
9034             }
9035             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9036                 return false;
9037             }
9038             if ( n3.isDuplication() ) {
9039                 return false;
9040             }
9041             if ( n3.isHasAssignedEvent() ) {
9042                 return false;
9043             }
9044             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9045                 return false;
9046             }
9047             if ( !n4.getName().equals( "n4" ) ) {
9048                 return false;
9049             }
9050             if ( n4.getDistanceToParent() != 0.01 ) {
9051                 return false;
9052             }
9053             if ( !n5.getName().equals( "n5" ) ) {
9054                 return false;
9055             }
9056             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9057                 return false;
9058             }
9059             if ( n5.getDistanceToParent() != 0.1 ) {
9060                 return false;
9061             }
9062             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9063                 return false;
9064             }
9065             if ( !n5.isDuplication() ) {
9066                 return false;
9067             }
9068             if ( !n5.isHasAssignedEvent() ) {
9069                 return false;
9070             }
9071             final PhylogenyNode n8 = PhylogenyNode
9072                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9073                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9074             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9075                 return false;
9076             }
9077             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9078                 return false;
9079             }
9080             final PhylogenyNode n9 = PhylogenyNode
9081                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9082                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9083             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9084                 return false;
9085             }
9086             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9087                 return false;
9088             }
9089             final PhylogenyNode n10 = PhylogenyNode
9090                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9091             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9092                 return false;
9093             }
9094             final PhylogenyNode n20 = PhylogenyNode
9095                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9096             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9097                 return false;
9098             }
9099             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9100                 return false;
9101             }
9102             final PhylogenyNode n20x = PhylogenyNode
9103                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9104             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9105                 return false;
9106             }
9107             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9108                 return false;
9109             }
9110             final PhylogenyNode n20xx = PhylogenyNode
9111                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9112             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9113                 return false;
9114             }
9115             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9116                 return false;
9117             }
9118             final PhylogenyNode n20xxx = PhylogenyNode
9119                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9120             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9121                 return false;
9122             }
9123             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9124                 return false;
9125             }
9126             final PhylogenyNode n20xxxx = PhylogenyNode
9127                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9128             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9129                 return false;
9130             }
9131             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9132                 return false;
9133             }
9134             final PhylogenyNode n21 = PhylogenyNode
9135                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9136             if ( !n21.getName().equals( "N21_PIG" ) ) {
9137                 return false;
9138             }
9139             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9140                 return false;
9141             }
9142             final PhylogenyNode n21x = PhylogenyNode
9143                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9144             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9145                 return false;
9146             }
9147             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9148                 return false;
9149             }
9150             final PhylogenyNode n22 = PhylogenyNode
9151                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9152             if ( !n22.getName().equals( "n22/PIG" ) ) {
9153                 return false;
9154             }
9155             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9156                 return false;
9157             }
9158             final PhylogenyNode n23 = PhylogenyNode
9159                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9160             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9161                 return false;
9162             }
9163             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9164                 return false;
9165             }
9166             final PhylogenyNode a = PhylogenyNode
9167                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9168             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9169                 return false;
9170             }
9171             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9172                 return false;
9173             }
9174             final PhylogenyNode c1 = PhylogenyNode
9175                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9176                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9177             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9178                 return false;
9179             }
9180             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9181                 return false;
9182             }
9183             final PhylogenyNode c2 = PhylogenyNode
9184                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9185                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9186             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9187                 return false;
9188             }
9189             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9190                 return false;
9191             }
9192             final PhylogenyNode e3 = PhylogenyNode
9193                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9194             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9195                 return false;
9196             }
9197             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9198                 return false;
9199             }
9200             final PhylogenyNode n11 = PhylogenyNode
9201                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9202                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9203             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9204                 return false;
9205             }
9206             if ( n11.getDistanceToParent() != 0.4 ) {
9207                 return false;
9208             }
9209             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9210                 return false;
9211             }
9212             final PhylogenyNode n12 = PhylogenyNode
9213                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9214                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9215             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9216                 return false;
9217             }
9218             if ( n12.getDistanceToParent() != 0.4 ) {
9219                 return false;
9220             }
9221             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9222                 return false;
9223             }
9224             final PhylogenyNode o = PhylogenyNode
9225                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9226             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9227                 return false;
9228             }
9229             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9230                 return false;
9231             }
9232             if ( n1.getName().compareTo( "" ) != 0 ) {
9233                 return false;
9234             }
9235             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9236                 return false;
9237             }
9238             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9239                 return false;
9240             }
9241             if ( n2.getName().compareTo( "" ) != 0 ) {
9242                 return false;
9243             }
9244             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9245                 return false;
9246             }
9247             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9248                 return false;
9249             }
9250             final PhylogenyNode n00 = PhylogenyNode
9251                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9252             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9253                 return false;
9254             }
9255             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9256                 return false;
9257             }
9258             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9259             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9260                 return false;
9261             }
9262             final PhylogenyNode n13 = PhylogenyNode
9263                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9264             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9265                 return false;
9266             }
9267             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9268                 return false;
9269             }
9270             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9271                 return false;
9272             }
9273             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9274                 return false;
9275             }
9276             final PhylogenyNode n14 = PhylogenyNode
9277                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9278             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9279                 return false;
9280             }
9281             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9282                 return false;
9283             }
9284             final PhylogenyNode n15 = PhylogenyNode
9285                     .createInstanceFromNhxString( "something_wicked[123]",
9286                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9287             if ( !n15.getName().equals( "something_wicked" ) ) {
9288                 return false;
9289             }
9290             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9291                 return false;
9292             }
9293             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9294                 return false;
9295             }
9296             final PhylogenyNode n16 = PhylogenyNode
9297                     .createInstanceFromNhxString( "something_wicked2[9]",
9298                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9299             if ( !n16.getName().equals( "something_wicked2" ) ) {
9300                 return false;
9301             }
9302             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9303                 return false;
9304             }
9305             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9306                 return false;
9307             }
9308             final PhylogenyNode n17 = PhylogenyNode
9309                     .createInstanceFromNhxString( "something_wicked3[a]",
9310                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9311             if ( !n17.getName().equals( "something_wicked3" ) ) {
9312                 return false;
9313             }
9314             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9315                 return false;
9316             }
9317             final PhylogenyNode n18 = PhylogenyNode
9318                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9319             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9320                 return false;
9321             }
9322             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9323                 return false;
9324             }
9325             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9326                 return false;
9327             }
9328             final PhylogenyNode n19 = PhylogenyNode
9329                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9330             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9331                 return false;
9332             }
9333             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9334                 return false;
9335             }
9336             final PhylogenyNode n30 = PhylogenyNode
9337                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9338                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9339             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9340                 return false;
9341             }
9342             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9343                 return false;
9344             }
9345             final PhylogenyNode n31 = PhylogenyNode
9346                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9347                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9348             if ( n31.getNodeData().isHasTaxonomy() ) {
9349                 return false;
9350             }
9351             final PhylogenyNode n32 = PhylogenyNode
9352                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9353             if ( n32.getNodeData().isHasTaxonomy() ) {
9354                 return false;
9355             }
9356             final PhylogenyNode n40 = PhylogenyNode
9357                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9358             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9359                 return false;
9360             }
9361             final PhylogenyNode n41 = PhylogenyNode
9362                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9363             if ( n41.getNodeData().isHasTaxonomy() ) {
9364                 return false;
9365             }
9366             final PhylogenyNode n42 = PhylogenyNode
9367                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9368             if ( n42.getNodeData().isHasTaxonomy() ) {
9369                 return false;
9370             }
9371             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9372                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9373             if ( n43.getNodeData().isHasTaxonomy() ) {
9374                 return false;
9375             }
9376             final PhylogenyNode n44 = PhylogenyNode
9377                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9378             if ( n44.getNodeData().isHasTaxonomy() ) {
9379                 return false;
9380             }
9381         }
9382         catch ( final Exception e ) {
9383             e.printStackTrace( System.out );
9384             return false;
9385         }
9386         return true;
9387     }
9388
9389     private static boolean testNHXParsing() {
9390         try {
9391             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9392             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9393             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9394                 return false;
9395             }
9396             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]";
9397             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9398             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9399                 return false;
9400             }
9401             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]";
9402             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9403             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9404                 return false;
9405             }
9406             final Phylogeny[] p3 = factory
9407                     .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]",
9408                              new NHXParser() );
9409             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9410                 return false;
9411             }
9412             final Phylogeny[] p4 = factory
9413                     .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(]",
9414                              new NHXParser() );
9415             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9416                 return false;
9417             }
9418             final Phylogeny[] p5 = factory
9419                     .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(((]",
9420                              new NHXParser() );
9421             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9422                 return false;
9423             }
9424             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)";
9425             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)";
9426             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9427             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9428                 return false;
9429             }
9430             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)))";
9431             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)))";
9432             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9433             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9434                 return false;
9435             }
9436             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])   ))[,,, ])))))))";
9437             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9438             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9439             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9440                 return false;
9441             }
9442             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9443             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9444                 return false;
9445             }
9446             final Phylogeny p10 = factory
9447                     .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]",
9448                              new NHXParser() )[ 0 ];
9449             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9450                 return false;
9451             }
9452             final Phylogeny p11 = factory
9453                     .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]",
9454                              new NHXParser() )[ 0 ];
9455             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9456                 return false;
9457             }
9458         }
9459         catch ( final Exception e ) {
9460             e.printStackTrace( System.out );
9461             return false;
9462         }
9463         return true;
9464     }
9465
9466     private static boolean testNHXParsingMB() {
9467         try {
9468             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9469             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9470                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9471                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9472                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9473                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9474                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9475                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9476                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9477                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9478             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9479                 return false;
9480             }
9481             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9482                 return false;
9483             }
9484             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9485                            0.1100000000000000e+00 ) ) {
9486                 return false;
9487             }
9488             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9489                 return false;
9490             }
9491             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9492                 return false;
9493             }
9494             final Phylogeny p2 = factory
9495                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9496                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9497                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9498                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9499                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9500                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9501                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9502                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9503                                      + "7.369400000000000e-02}])",
9504                              new NHXParser() )[ 0 ];
9505             if ( p2.getNode( "1" ) == null ) {
9506                 return false;
9507             }
9508             if ( p2.getNode( "2" ) == null ) {
9509                 return false;
9510             }
9511         }
9512         catch ( final Exception e ) {
9513             e.printStackTrace( System.out );
9514             System.exit( -1 );
9515             return false;
9516         }
9517         return true;
9518     }
9519
9520     private static boolean testNHXParsingQuotes() {
9521         try {
9522             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9523             final NHXParser p = new NHXParser();
9524             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9525             if ( phylogenies_0.length != 5 ) {
9526                 return false;
9527             }
9528             final Phylogeny phy = phylogenies_0[ 4 ];
9529             if ( phy.getNumberOfExternalNodes() != 7 ) {
9530                 return false;
9531             }
9532             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9533                 return false;
9534             }
9535             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9536                 return false;
9537             }
9538             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9539                     .getScientificName().equals( "hsapiens" ) ) {
9540                 return false;
9541             }
9542             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9543                 return false;
9544             }
9545             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9546                 return false;
9547             }
9548             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9549                 return false;
9550             }
9551             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9552                 return false;
9553             }
9554             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9555                 return false;
9556             }
9557             final NHXParser p1p = new NHXParser();
9558             p1p.setIgnoreQuotes( true );
9559             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9560             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9561                 return false;
9562             }
9563             final NHXParser p2p = new NHXParser();
9564             p1p.setIgnoreQuotes( false );
9565             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9566             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9567                 return false;
9568             }
9569             final NHXParser p3p = new NHXParser();
9570             p3p.setIgnoreQuotes( false );
9571             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9572             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9573                 return false;
9574             }
9575             final NHXParser p4p = new NHXParser();
9576             p4p.setIgnoreQuotes( false );
9577             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9578             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9579                 return false;
9580             }
9581             final Phylogeny p10 = factory
9582                     .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]",
9583                              new NHXParser() )[ 0 ];
9584             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]";
9585             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9586                 return false;
9587             }
9588             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9589             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9590                 return false;
9591             }
9592             final Phylogeny p12 = factory
9593                     .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]",
9594                              new NHXParser() )[ 0 ];
9595             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]";
9596             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9597                 return false;
9598             }
9599             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9600             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9601                 return false;
9602             }
9603             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;";
9604             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9605                 return false;
9606             }
9607             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9608             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9609                 return false;
9610             }
9611         }
9612         catch ( final Exception e ) {
9613             e.printStackTrace( System.out );
9614             return false;
9615         }
9616         return true;
9617     }
9618
9619     private static boolean testNodeRemoval() {
9620         try {
9621             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9622             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9623             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9624             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9625                 return false;
9626             }
9627             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9628             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9629             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9630                 return false;
9631             }
9632             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9633             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9634             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9635                 return false;
9636             }
9637         }
9638         catch ( final Exception e ) {
9639             e.printStackTrace( System.out );
9640             return false;
9641         }
9642         return true;
9643     }
9644
9645     private static boolean testPhylogenyBranch() {
9646         try {
9647             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9648             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9649             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9650             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9651             if ( !a1b1.equals( a1b1 ) ) {
9652                 return false;
9653             }
9654             if ( !a1b1.equals( b1a1 ) ) {
9655                 return false;
9656             }
9657             if ( !b1a1.equals( a1b1 ) ) {
9658                 return false;
9659             }
9660             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9661             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9662             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9663             if ( a1_b1.equals( b1_a1 ) ) {
9664                 return false;
9665             }
9666             if ( a1_b1.equals( a1_b1_ ) ) {
9667                 return false;
9668             }
9669             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9670             if ( !a1_b1.equals( b1_a1_ ) ) {
9671                 return false;
9672             }
9673             if ( a1_b1_.equals( b1_a1_ ) ) {
9674                 return false;
9675             }
9676             if ( !a1_b1_.equals( b1_a1 ) ) {
9677                 return false;
9678             }
9679         }
9680         catch ( final Exception e ) {
9681             e.printStackTrace( System.out );
9682             return false;
9683         }
9684         return true;
9685     }
9686
9687     private static boolean testPhyloXMLparsingOfDistributionElement() {
9688         try {
9689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9690             PhyloXmlParser xml_parser = null;
9691             try {
9692                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9693             }
9694             catch ( final Exception e ) {
9695                 // Do nothing -- means were not running from jar.
9696             }
9697             if ( xml_parser == null ) {
9698                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9699                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9700                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9701                 }
9702                 else {
9703                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9704                 }
9705             }
9706             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9707                                                               xml_parser );
9708             if ( xml_parser.getErrorCount() > 0 ) {
9709                 System.out.println( xml_parser.getErrorMessages().toString() );
9710                 return false;
9711             }
9712             if ( phylogenies_0.length != 1 ) {
9713                 return false;
9714             }
9715             final Phylogeny t1 = phylogenies_0[ 0 ];
9716             PhylogenyNode n = null;
9717             Distribution d = null;
9718             n = t1.getNode( "root node" );
9719             if ( !n.getNodeData().isHasDistribution() ) {
9720                 return false;
9721             }
9722             if ( n.getNodeData().getDistributions().size() != 1 ) {
9723                 return false;
9724             }
9725             d = n.getNodeData().getDistribution();
9726             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9727                 return false;
9728             }
9729             if ( d.getPoints().size() != 1 ) {
9730                 return false;
9731             }
9732             if ( d.getPolygons() != null ) {
9733                 return false;
9734             }
9735             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9736                 return false;
9737             }
9738             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9739                 return false;
9740             }
9741             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9742                 return false;
9743             }
9744             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9745                 return false;
9746             }
9747             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9748                 return false;
9749             }
9750             n = t1.getNode( "node a" );
9751             if ( !n.getNodeData().isHasDistribution() ) {
9752                 return false;
9753             }
9754             if ( n.getNodeData().getDistributions().size() != 2 ) {
9755                 return false;
9756             }
9757             d = n.getNodeData().getDistribution( 1 );
9758             if ( !d.getDesc().equals( "San Diego" ) ) {
9759                 return false;
9760             }
9761             if ( d.getPoints().size() != 1 ) {
9762                 return false;
9763             }
9764             if ( d.getPolygons() != null ) {
9765                 return false;
9766             }
9767             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9768                 return false;
9769             }
9770             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9771                 return false;
9772             }
9773             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9774                 return false;
9775             }
9776             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9777                 return false;
9778             }
9779             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9780                 return false;
9781             }
9782             n = t1.getNode( "node bb" );
9783             if ( !n.getNodeData().isHasDistribution() ) {
9784                 return false;
9785             }
9786             if ( n.getNodeData().getDistributions().size() != 1 ) {
9787                 return false;
9788             }
9789             d = n.getNodeData().getDistribution( 0 );
9790             if ( d.getPoints().size() != 3 ) {
9791                 return false;
9792             }
9793             if ( d.getPolygons().size() != 2 ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9797                 return false;
9798             }
9799             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9800                 return false;
9801             }
9802             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9803                 return false;
9804             }
9805             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9806                 return false;
9807             }
9808             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9809                 return false;
9810             }
9811             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9812                 return false;
9813             }
9814             Polygon p = d.getPolygons().get( 0 );
9815             if ( p.getPoints().size() != 3 ) {
9816                 return false;
9817             }
9818             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9819                 return false;
9820             }
9821             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9822                 return false;
9823             }
9824             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9825                 return false;
9826             }
9827             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9828                 return false;
9829             }
9830             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9831                 return false;
9832             }
9833             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9834                 return false;
9835             }
9836             p = d.getPolygons().get( 1 );
9837             if ( p.getPoints().size() != 3 ) {
9838                 return false;
9839             }
9840             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9841                 return false;
9842             }
9843             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9844                 return false;
9845             }
9846             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9847                 return false;
9848             }
9849             // Roundtrip:
9850             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9851             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9852             if ( rt.length != 1 ) {
9853                 return false;
9854             }
9855             final Phylogeny t1_rt = rt[ 0 ];
9856             n = t1_rt.getNode( "root node" );
9857             if ( !n.getNodeData().isHasDistribution() ) {
9858                 return false;
9859             }
9860             if ( n.getNodeData().getDistributions().size() != 1 ) {
9861                 return false;
9862             }
9863             d = n.getNodeData().getDistribution();
9864             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9865                 return false;
9866             }
9867             if ( d.getPoints().size() != 1 ) {
9868                 return false;
9869             }
9870             if ( d.getPolygons() != null ) {
9871                 return false;
9872             }
9873             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9874                 return false;
9875             }
9876             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9877                 return false;
9878             }
9879             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9880                 return false;
9881             }
9882             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9883                 return false;
9884             }
9885             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9886                 return false;
9887             }
9888             n = t1_rt.getNode( "node a" );
9889             if ( !n.getNodeData().isHasDistribution() ) {
9890                 return false;
9891             }
9892             if ( n.getNodeData().getDistributions().size() != 2 ) {
9893                 return false;
9894             }
9895             d = n.getNodeData().getDistribution( 1 );
9896             if ( !d.getDesc().equals( "San Diego" ) ) {
9897                 return false;
9898             }
9899             if ( d.getPoints().size() != 1 ) {
9900                 return false;
9901             }
9902             if ( d.getPolygons() != null ) {
9903                 return false;
9904             }
9905             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9906                 return false;
9907             }
9908             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9909                 return false;
9910             }
9911             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9912                 return false;
9913             }
9914             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9915                 return false;
9916             }
9917             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9918                 return false;
9919             }
9920             n = t1_rt.getNode( "node bb" );
9921             if ( !n.getNodeData().isHasDistribution() ) {
9922                 return false;
9923             }
9924             if ( n.getNodeData().getDistributions().size() != 1 ) {
9925                 return false;
9926             }
9927             d = n.getNodeData().getDistribution( 0 );
9928             if ( d.getPoints().size() != 3 ) {
9929                 return false;
9930             }
9931             if ( d.getPolygons().size() != 2 ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9935                 return false;
9936             }
9937             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9938                 return false;
9939             }
9940             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9941                 return false;
9942             }
9943             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9944                 return false;
9945             }
9946             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9947                 return false;
9948             }
9949             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9950                 return false;
9951             }
9952             p = d.getPolygons().get( 0 );
9953             if ( p.getPoints().size() != 3 ) {
9954                 return false;
9955             }
9956             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9957                 return false;
9958             }
9959             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9960                 return false;
9961             }
9962             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9963                 return false;
9964             }
9965             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9966                 return false;
9967             }
9968             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9969                 return false;
9970             }
9971             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9972                 return false;
9973             }
9974             p = d.getPolygons().get( 1 );
9975             if ( p.getPoints().size() != 3 ) {
9976                 return false;
9977             }
9978             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9979                 return false;
9980             }
9981             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9982                 return false;
9983             }
9984             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9985                 return false;
9986             }
9987         }
9988         catch ( final Exception e ) {
9989             e.printStackTrace( System.out );
9990             return false;
9991         }
9992         return true;
9993     }
9994
9995     private static boolean testPostOrderIterator() {
9996         try {
9997             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9998             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9999             PhylogenyNodeIterator it0;
10000             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10001                 it0.next();
10002             }
10003             for( it0.reset(); it0.hasNext(); ) {
10004                 it0.next();
10005             }
10006             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10007             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10008             if ( !it.next().getName().equals( "A" ) ) {
10009                 return false;
10010             }
10011             if ( !it.next().getName().equals( "B" ) ) {
10012                 return false;
10013             }
10014             if ( !it.next().getName().equals( "ab" ) ) {
10015                 return false;
10016             }
10017             if ( !it.next().getName().equals( "C" ) ) {
10018                 return false;
10019             }
10020             if ( !it.next().getName().equals( "D" ) ) {
10021                 return false;
10022             }
10023             if ( !it.next().getName().equals( "cd" ) ) {
10024                 return false;
10025             }
10026             if ( !it.next().getName().equals( "abcd" ) ) {
10027                 return false;
10028             }
10029             if ( !it.next().getName().equals( "E" ) ) {
10030                 return false;
10031             }
10032             if ( !it.next().getName().equals( "F" ) ) {
10033                 return false;
10034             }
10035             if ( !it.next().getName().equals( "ef" ) ) {
10036                 return false;
10037             }
10038             if ( !it.next().getName().equals( "G" ) ) {
10039                 return false;
10040             }
10041             if ( !it.next().getName().equals( "H" ) ) {
10042                 return false;
10043             }
10044             if ( !it.next().getName().equals( "gh" ) ) {
10045                 return false;
10046             }
10047             if ( !it.next().getName().equals( "efgh" ) ) {
10048                 return false;
10049             }
10050             if ( !it.next().getName().equals( "r" ) ) {
10051                 return false;
10052             }
10053             if ( it.hasNext() ) {
10054                 return false;
10055             }
10056         }
10057         catch ( final Exception e ) {
10058             e.printStackTrace( System.out );
10059             return false;
10060         }
10061         return true;
10062     }
10063
10064     private static boolean testPreOrderIterator() {
10065         try {
10066             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10067             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10068             PhylogenyNodeIterator it0;
10069             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10070                 it0.next();
10071             }
10072             for( it0.reset(); it0.hasNext(); ) {
10073                 it0.next();
10074             }
10075             PhylogenyNodeIterator it = t0.iteratorPreorder();
10076             if ( !it.next().getName().equals( "r" ) ) {
10077                 return false;
10078             }
10079             if ( !it.next().getName().equals( "ab" ) ) {
10080                 return false;
10081             }
10082             if ( !it.next().getName().equals( "A" ) ) {
10083                 return false;
10084             }
10085             if ( !it.next().getName().equals( "B" ) ) {
10086                 return false;
10087             }
10088             if ( !it.next().getName().equals( "cd" ) ) {
10089                 return false;
10090             }
10091             if ( !it.next().getName().equals( "C" ) ) {
10092                 return false;
10093             }
10094             if ( !it.next().getName().equals( "D" ) ) {
10095                 return false;
10096             }
10097             if ( it.hasNext() ) {
10098                 return false;
10099             }
10100             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10101             it = t1.iteratorPreorder();
10102             if ( !it.next().getName().equals( "r" ) ) {
10103                 return false;
10104             }
10105             if ( !it.next().getName().equals( "abcd" ) ) {
10106                 return false;
10107             }
10108             if ( !it.next().getName().equals( "ab" ) ) {
10109                 return false;
10110             }
10111             if ( !it.next().getName().equals( "A" ) ) {
10112                 return false;
10113             }
10114             if ( !it.next().getName().equals( "B" ) ) {
10115                 return false;
10116             }
10117             if ( !it.next().getName().equals( "cd" ) ) {
10118                 return false;
10119             }
10120             if ( !it.next().getName().equals( "C" ) ) {
10121                 return false;
10122             }
10123             if ( !it.next().getName().equals( "D" ) ) {
10124                 return false;
10125             }
10126             if ( !it.next().getName().equals( "efgh" ) ) {
10127                 return false;
10128             }
10129             if ( !it.next().getName().equals( "ef" ) ) {
10130                 return false;
10131             }
10132             if ( !it.next().getName().equals( "E" ) ) {
10133                 return false;
10134             }
10135             if ( !it.next().getName().equals( "F" ) ) {
10136                 return false;
10137             }
10138             if ( !it.next().getName().equals( "gh" ) ) {
10139                 return false;
10140             }
10141             if ( !it.next().getName().equals( "G" ) ) {
10142                 return false;
10143             }
10144             if ( !it.next().getName().equals( "H" ) ) {
10145                 return false;
10146             }
10147             if ( it.hasNext() ) {
10148                 return false;
10149             }
10150         }
10151         catch ( final Exception e ) {
10152             e.printStackTrace( System.out );
10153             return false;
10154         }
10155         return true;
10156     }
10157
10158     private static boolean testPropertiesMap() {
10159         try {
10160             final PropertiesMap pm = new PropertiesMap();
10161             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10162             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10163             final Property p2 = new Property( "something:else",
10164                                               "?",
10165                                               "improbable:research",
10166                                               "xsd:decimal",
10167                                               AppliesTo.NODE );
10168             pm.addProperty( p0 );
10169             pm.addProperty( p1 );
10170             pm.addProperty( p2 );
10171             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10172                 return false;
10173             }
10174             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10175                 return false;
10176             }
10177             if ( pm.getProperties().size() != 3 ) {
10178                 return false;
10179             }
10180             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10181                 return false;
10182             }
10183             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10184                 return false;
10185             }
10186             if ( pm.getProperties().size() != 3 ) {
10187                 return false;
10188             }
10189             pm.removeProperty( "dimensions:diameter" );
10190             if ( pm.getProperties().size() != 2 ) {
10191                 return false;
10192             }
10193             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10194                 return false;
10195             }
10196             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10197                 return false;
10198             }
10199         }
10200         catch ( final Exception e ) {
10201             e.printStackTrace( System.out );
10202             return false;
10203         }
10204         return true;
10205     }
10206
10207     private static boolean testProteinId() {
10208         try {
10209             final ProteinId id1 = new ProteinId( "a" );
10210             final ProteinId id2 = new ProteinId( "a" );
10211             final ProteinId id3 = new ProteinId( "A" );
10212             final ProteinId id4 = new ProteinId( "b" );
10213             if ( !id1.equals( id1 ) ) {
10214                 return false;
10215             }
10216             if ( id1.getId().equals( "x" ) ) {
10217                 return false;
10218             }
10219             if ( id1.getId().equals( null ) ) {
10220                 return false;
10221             }
10222             if ( !id1.equals( id2 ) ) {
10223                 return false;
10224             }
10225             if ( id1.equals( id3 ) ) {
10226                 return false;
10227             }
10228             if ( id1.hashCode() != id1.hashCode() ) {
10229                 return false;
10230             }
10231             if ( id1.hashCode() != id2.hashCode() ) {
10232                 return false;
10233             }
10234             if ( id1.hashCode() == id3.hashCode() ) {
10235                 return false;
10236             }
10237             if ( id1.compareTo( id1 ) != 0 ) {
10238                 return false;
10239             }
10240             if ( id1.compareTo( id2 ) != 0 ) {
10241                 return false;
10242             }
10243             if ( id1.compareTo( id3 ) != 0 ) {
10244                 return false;
10245             }
10246             if ( id1.compareTo( id4 ) >= 0 ) {
10247                 return false;
10248             }
10249             if ( id4.compareTo( id1 ) <= 0 ) {
10250                 return false;
10251             }
10252             if ( !id4.getId().equals( "b" ) ) {
10253                 return false;
10254             }
10255             final ProteinId id5 = new ProteinId( " C " );
10256             if ( !id5.getId().equals( "C" ) ) {
10257                 return false;
10258             }
10259             if ( id5.equals( id1 ) ) {
10260                 return false;
10261             }
10262         }
10263         catch ( final Exception e ) {
10264             e.printStackTrace( System.out );
10265             return false;
10266         }
10267         return true;
10268     }
10269
10270     private static boolean testReIdMethods() {
10271         try {
10272             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10273             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10274             final long count = PhylogenyNode.getNodeCount();
10275             p.levelOrderReID();
10276             if ( p.getNode( "r" ).getId() != count ) {
10277                 return false;
10278             }
10279             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10280                 return false;
10281             }
10282             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10283                 return false;
10284             }
10285             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10286                 return false;
10287             }
10288             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10289                 return false;
10290             }
10291             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10292                 return false;
10293             }
10294             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10295                 return false;
10296             }
10297             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10298                 return false;
10299             }
10300             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10301                 return false;
10302             }
10303             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10304                 return false;
10305             }
10306             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10307                 return false;
10308             }
10309             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10310                 return false;
10311             }
10312             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10313                 return false;
10314             }
10315             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10316                 return false;
10317             }
10318             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
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 testRerooting() {
10330         try {
10331             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10332             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",
10333                                                  new NHXParser() )[ 0 ];
10334             if ( !t1.isRooted() ) {
10335                 return false;
10336             }
10337             t1.reRoot( t1.getNode( "D" ) );
10338             t1.reRoot( t1.getNode( "CD" ) );
10339             t1.reRoot( t1.getNode( "A" ) );
10340             t1.reRoot( t1.getNode( "B" ) );
10341             t1.reRoot( t1.getNode( "AB" ) );
10342             t1.reRoot( t1.getNode( "D" ) );
10343             t1.reRoot( t1.getNode( "C" ) );
10344             t1.reRoot( t1.getNode( "CD" ) );
10345             t1.reRoot( t1.getNode( "A" ) );
10346             t1.reRoot( t1.getNode( "B" ) );
10347             t1.reRoot( t1.getNode( "AB" ) );
10348             t1.reRoot( t1.getNode( "D" ) );
10349             t1.reRoot( t1.getNode( "D" ) );
10350             t1.reRoot( t1.getNode( "C" ) );
10351             t1.reRoot( t1.getNode( "A" ) );
10352             t1.reRoot( t1.getNode( "B" ) );
10353             t1.reRoot( t1.getNode( "AB" ) );
10354             t1.reRoot( t1.getNode( "C" ) );
10355             t1.reRoot( t1.getNode( "D" ) );
10356             t1.reRoot( t1.getNode( "CD" ) );
10357             t1.reRoot( t1.getNode( "D" ) );
10358             t1.reRoot( t1.getNode( "A" ) );
10359             t1.reRoot( t1.getNode( "B" ) );
10360             t1.reRoot( t1.getNode( "AB" ) );
10361             t1.reRoot( t1.getNode( "C" ) );
10362             t1.reRoot( t1.getNode( "D" ) );
10363             t1.reRoot( t1.getNode( "CD" ) );
10364             t1.reRoot( t1.getNode( "D" ) );
10365             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10366                 return false;
10367             }
10368             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10369                 return false;
10370             }
10371             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10372                 return false;
10373             }
10374             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10375                 return false;
10376             }
10377             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10378                 return false;
10379             }
10380             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10381                 return false;
10382             }
10383             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",
10384                                                  new NHXParser() )[ 0 ];
10385             t2.reRoot( t2.getNode( "A" ) );
10386             t2.reRoot( t2.getNode( "D" ) );
10387             t2.reRoot( t2.getNode( "ABC" ) );
10388             t2.reRoot( t2.getNode( "A" ) );
10389             t2.reRoot( t2.getNode( "B" ) );
10390             t2.reRoot( t2.getNode( "D" ) );
10391             t2.reRoot( t2.getNode( "C" ) );
10392             t2.reRoot( t2.getNode( "ABC" ) );
10393             t2.reRoot( t2.getNode( "A" ) );
10394             t2.reRoot( t2.getNode( "B" ) );
10395             t2.reRoot( t2.getNode( "AB" ) );
10396             t2.reRoot( t2.getNode( "AB" ) );
10397             t2.reRoot( t2.getNode( "D" ) );
10398             t2.reRoot( t2.getNode( "C" ) );
10399             t2.reRoot( t2.getNode( "B" ) );
10400             t2.reRoot( t2.getNode( "AB" ) );
10401             t2.reRoot( t2.getNode( "D" ) );
10402             t2.reRoot( t2.getNode( "D" ) );
10403             t2.reRoot( t2.getNode( "ABC" ) );
10404             t2.reRoot( t2.getNode( "A" ) );
10405             t2.reRoot( t2.getNode( "B" ) );
10406             t2.reRoot( t2.getNode( "AB" ) );
10407             t2.reRoot( t2.getNode( "D" ) );
10408             t2.reRoot( t2.getNode( "C" ) );
10409             t2.reRoot( t2.getNode( "ABC" ) );
10410             t2.reRoot( t2.getNode( "A" ) );
10411             t2.reRoot( t2.getNode( "B" ) );
10412             t2.reRoot( t2.getNode( "AB" ) );
10413             t2.reRoot( t2.getNode( "D" ) );
10414             t2.reRoot( t2.getNode( "D" ) );
10415             t2.reRoot( t2.getNode( "C" ) );
10416             t2.reRoot( t2.getNode( "A" ) );
10417             t2.reRoot( t2.getNode( "B" ) );
10418             t2.reRoot( t2.getNode( "AB" ) );
10419             t2.reRoot( t2.getNode( "C" ) );
10420             t2.reRoot( t2.getNode( "D" ) );
10421             t2.reRoot( t2.getNode( "ABC" ) );
10422             t2.reRoot( t2.getNode( "D" ) );
10423             t2.reRoot( t2.getNode( "A" ) );
10424             t2.reRoot( t2.getNode( "B" ) );
10425             t2.reRoot( t2.getNode( "AB" ) );
10426             t2.reRoot( t2.getNode( "C" ) );
10427             t2.reRoot( t2.getNode( "D" ) );
10428             t2.reRoot( t2.getNode( "ABC" ) );
10429             t2.reRoot( t2.getNode( "D" ) );
10430             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10431                 return false;
10432             }
10433             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10434                 return false;
10435             }
10436             t2.reRoot( t2.getNode( "ABC" ) );
10437             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10438                 return false;
10439             }
10440             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10441                 return false;
10442             }
10443             t2.reRoot( t2.getNode( "AB" ) );
10444             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10445                 return false;
10446             }
10447             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10448                 return false;
10449             }
10450             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10451                 return false;
10452             }
10453             t2.reRoot( t2.getNode( "AB" ) );
10454             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10455                 return false;
10456             }
10457             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10458                 return false;
10459             }
10460             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10461                 return false;
10462             }
10463             t2.reRoot( t2.getNode( "D" ) );
10464             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10465                 return false;
10466             }
10467             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10468                 return false;
10469             }
10470             t2.reRoot( t2.getNode( "ABC" ) );
10471             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10472                 return false;
10473             }
10474             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10475                 return false;
10476             }
10477             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10478                                                  new NHXParser() )[ 0 ];
10479             t3.reRoot( t3.getNode( "B" ) );
10480             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10481                 return false;
10482             }
10483             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10484                 return false;
10485             }
10486             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10487                 return false;
10488             }
10489             t3.reRoot( t3.getNode( "B" ) );
10490             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10491                 return false;
10492             }
10493             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10494                 return false;
10495             }
10496             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10497                 return false;
10498             }
10499             t3.reRoot( t3.getRoot() );
10500             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10501                 return false;
10502             }
10503             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10504                 return false;
10505             }
10506             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10507                 return false;
10508             }
10509         }
10510         catch ( final Exception e ) {
10511             e.printStackTrace( System.out );
10512             return false;
10513         }
10514         return true;
10515     }
10516
10517     private static boolean testSDIse() {
10518         try {
10519             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10520             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10521             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10522             gene1.setRooted( true );
10523             species1.setRooted( true );
10524             final SDI sdi = new SDI( gene1, species1 );
10525             if ( !gene1.getRoot().isDuplication() ) {
10526                 return false;
10527             }
10528             final Phylogeny species2 = factory
10529                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10530                              new NHXParser() )[ 0 ];
10531             final Phylogeny gene2 = factory
10532                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10533                              new NHXParser() )[ 0 ];
10534             species2.setRooted( true );
10535             gene2.setRooted( true );
10536             final SDI sdi2 = new SDI( gene2, species2 );
10537             if ( sdi2.getDuplicationsSum() != 0 ) {
10538                 return false;
10539             }
10540             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10541                 return false;
10542             }
10543             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10544                 return false;
10545             }
10546             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10547                 return false;
10548             }
10549             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10550                 return false;
10551             }
10552             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10553                 return false;
10554             }
10555             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10556                 return false;
10557             }
10558             final Phylogeny species3 = factory
10559                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10560                              new NHXParser() )[ 0 ];
10561             final Phylogeny gene3 = factory
10562                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10563                              new NHXParser() )[ 0 ];
10564             species3.setRooted( true );
10565             gene3.setRooted( true );
10566             final SDI sdi3 = new SDI( gene3, species3 );
10567             if ( sdi3.getDuplicationsSum() != 1 ) {
10568                 return false;
10569             }
10570             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10571                 return false;
10572             }
10573             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10574                 return false;
10575             }
10576             final Phylogeny species4 = factory
10577                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10578                              new NHXParser() )[ 0 ];
10579             final Phylogeny gene4 = factory
10580                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10581                              new NHXParser() )[ 0 ];
10582             species4.setRooted( true );
10583             gene4.setRooted( true );
10584             final SDI sdi4 = new SDI( gene4, species4 );
10585             if ( sdi4.getDuplicationsSum() != 1 ) {
10586                 return false;
10587             }
10588             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10589                 return false;
10590             }
10591             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10592                 return false;
10593             }
10594             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10595                 return false;
10596             }
10597             if ( species4.getNumberOfExternalNodes() != 6 ) {
10598                 return false;
10599             }
10600             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10601                 return false;
10602             }
10603             final Phylogeny species5 = factory
10604                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10605                              new NHXParser() )[ 0 ];
10606             final Phylogeny gene5 = factory
10607                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10608                              new NHXParser() )[ 0 ];
10609             species5.setRooted( true );
10610             gene5.setRooted( true );
10611             final SDI sdi5 = new SDI( gene5, species5 );
10612             if ( sdi5.getDuplicationsSum() != 2 ) {
10613                 return false;
10614             }
10615             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10616                 return false;
10617             }
10618             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10619                 return false;
10620             }
10621             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10622                 return false;
10623             }
10624             if ( species5.getNumberOfExternalNodes() != 6 ) {
10625                 return false;
10626             }
10627             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10628                 return false;
10629             }
10630             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10631             // Conjecture for Comparing Molecular Phylogenies"
10632             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10633             final Phylogeny species6 = factory
10634                     .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,"
10635                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10636                              new NHXParser() )[ 0 ];
10637             final Phylogeny gene6 = factory
10638                     .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,"
10639                                      + "((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,"
10640                                      + "(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;",
10641                              new NHXParser() )[ 0 ];
10642             species6.setRooted( true );
10643             gene6.setRooted( true );
10644             final SDI sdi6 = new SDI( gene6, species6 );
10645             if ( sdi6.getDuplicationsSum() != 3 ) {
10646                 return false;
10647             }
10648             if ( !gene6.getNode( "r" ).isDuplication() ) {
10649                 return false;
10650             }
10651             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10652                 return false;
10653             }
10654             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10655                 return false;
10656             }
10657             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10658                 return false;
10659             }
10660             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10661                 return false;
10662             }
10663             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10664                 return false;
10665             }
10666             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10667                 return false;
10668             }
10669             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10670                 return false;
10671             }
10672             sdi6.computeMappingCostL();
10673             if ( sdi6.computeMappingCostL() != 17 ) {
10674                 return false;
10675             }
10676             if ( species6.getNumberOfExternalNodes() != 9 ) {
10677                 return false;
10678             }
10679             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10680                 return false;
10681             }
10682             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10683                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10684                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10685                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10686                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10687             species7.setRooted( true );
10688             final Phylogeny gene7_1 = Test
10689                     .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])" );
10690             gene7_1.setRooted( true );
10691             final SDI sdi7 = new SDI( gene7_1, species7 );
10692             if ( sdi7.getDuplicationsSum() != 0 ) {
10693                 return false;
10694             }
10695             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10696                 return false;
10697             }
10698             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10699                 return false;
10700             }
10701             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10702                 return false;
10703             }
10704             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10705                 return false;
10706             }
10707             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10708                 return false;
10709             }
10710             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10711                 return false;
10712             }
10713             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10714                 return false;
10715             }
10716             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10717                 return false;
10718             }
10719             final Phylogeny gene7_2 = Test
10720                     .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])" );
10721             gene7_2.setRooted( true );
10722             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10723             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10724                 return false;
10725             }
10726             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10727                 return false;
10728             }
10729             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10730                 return false;
10731             }
10732             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10733                 return false;
10734             }
10735             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10736                 return false;
10737             }
10738             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10739                 return false;
10740             }
10741             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10742                 return false;
10743             }
10744             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10745                 return false;
10746             }
10747             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10748                 return false;
10749             }
10750             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10751                 return false;
10752             }
10753         }
10754         catch ( final Exception e ) {
10755             return false;
10756         }
10757         return true;
10758     }
10759
10760     private static boolean testSDIunrooted() {
10761         try {
10762             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10763             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10764             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10765             final Iterator<PhylogenyBranch> iter = l.iterator();
10766             PhylogenyBranch br = iter.next();
10767             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10768                 return false;
10769             }
10770             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10771                 return false;
10772             }
10773             br = iter.next();
10774             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10775                 return false;
10776             }
10777             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10778                 return false;
10779             }
10780             br = iter.next();
10781             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10782                 return false;
10783             }
10784             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10785                 return false;
10786             }
10787             br = iter.next();
10788             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10789                 return false;
10790             }
10791             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10792                 return false;
10793             }
10794             br = iter.next();
10795             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10796                 return false;
10797             }
10798             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10799                 return false;
10800             }
10801             br = iter.next();
10802             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10803                 return false;
10804             }
10805             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10806                 return false;
10807             }
10808             br = iter.next();
10809             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10810                 return false;
10811             }
10812             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10813                 return false;
10814             }
10815             br = iter.next();
10816             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10817                 return false;
10818             }
10819             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10820                 return false;
10821             }
10822             br = iter.next();
10823             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10824                 return false;
10825             }
10826             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10827                 return false;
10828             }
10829             br = iter.next();
10830             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10831                 return false;
10832             }
10833             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10834                 return false;
10835             }
10836             br = iter.next();
10837             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10838                 return false;
10839             }
10840             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10841                 return false;
10842             }
10843             br = iter.next();
10844             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10845                 return false;
10846             }
10847             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10848                 return false;
10849             }
10850             br = iter.next();
10851             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10852                 return false;
10853             }
10854             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10855                 return false;
10856             }
10857             br = iter.next();
10858             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10859                 return false;
10860             }
10861             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10862                 return false;
10863             }
10864             br = iter.next();
10865             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10866                 return false;
10867             }
10868             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10869                 return false;
10870             }
10871             if ( iter.hasNext() ) {
10872                 return false;
10873             }
10874             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10875             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10876             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10877             br = iter1.next();
10878             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10879                 return false;
10880             }
10881             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10882                 return false;
10883             }
10884             br = iter1.next();
10885             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10886                 return false;
10887             }
10888             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10889                 return false;
10890             }
10891             br = iter1.next();
10892             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10893                 return false;
10894             }
10895             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10896                 return false;
10897             }
10898             if ( iter1.hasNext() ) {
10899                 return false;
10900             }
10901             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10902             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10903             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10904             br = iter2.next();
10905             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10906                 return false;
10907             }
10908             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10909                 return false;
10910             }
10911             br = iter2.next();
10912             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10913                 return false;
10914             }
10915             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10916                 return false;
10917             }
10918             br = iter2.next();
10919             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10920                 return false;
10921             }
10922             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10923                 return false;
10924             }
10925             if ( iter2.hasNext() ) {
10926                 return false;
10927             }
10928             final Phylogeny species0 = factory
10929                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10930                              new NHXParser() )[ 0 ];
10931             final Phylogeny gene1 = factory
10932                     .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])",
10933                              new NHXParser() )[ 0 ];
10934             species0.setRooted( true );
10935             gene1.setRooted( true );
10936             final SDIR sdi_unrooted = new SDIR();
10937             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10938             if ( sdi_unrooted.getCount() != 1 ) {
10939                 return false;
10940             }
10941             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10942                 return false;
10943             }
10944             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10945                 return false;
10946             }
10947             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10948                 return false;
10949             }
10950             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10951                 return false;
10952             }
10953             final Phylogeny gene2 = factory
10954                     .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])",
10955                              new NHXParser() )[ 0 ];
10956             gene2.setRooted( true );
10957             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10958             if ( sdi_unrooted.getCount() != 1 ) {
10959                 return false;
10960             }
10961             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10962                 return false;
10963             }
10964             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10965                 return false;
10966             }
10967             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10968                 return false;
10969             }
10970             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10971                 return false;
10972             }
10973             final Phylogeny species6 = factory
10974                     .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,"
10975                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10976                              new NHXParser() )[ 0 ];
10977             final Phylogeny gene6 = factory
10978                     .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],"
10979                                      + "(((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],"
10980                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10981                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10982                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10983                              new NHXParser() )[ 0 ];
10984             species6.setRooted( true );
10985             gene6.setRooted( true );
10986             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10987             if ( sdi_unrooted.getCount() != 1 ) {
10988                 return false;
10989             }
10990             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10991                 return false;
10992             }
10993             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10994                 return false;
10995             }
10996             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10997                 return false;
10998             }
10999             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11000                 return false;
11001             }
11002             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11003                 return false;
11004             }
11005             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11006                 return false;
11007             }
11008             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11009                 return false;
11010             }
11011             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11012                 return false;
11013             }
11014             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11015                 return false;
11016             }
11017             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11018                 return false;
11019             }
11020             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11021                 return false;
11022             }
11023             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11024                 return false;
11025             }
11026             p6 = null;
11027             final Phylogeny species7 = factory
11028                     .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,"
11029                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11030                              new NHXParser() )[ 0 ];
11031             final Phylogeny gene7 = factory
11032                     .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],"
11033                                      + "(((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],"
11034                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11035                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11036                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11037                              new NHXParser() )[ 0 ];
11038             species7.setRooted( true );
11039             gene7.setRooted( true );
11040             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11041             if ( sdi_unrooted.getCount() != 1 ) {
11042                 return false;
11043             }
11044             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11045                 return false;
11046             }
11047             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11048                 return false;
11049             }
11050             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11051                 return false;
11052             }
11053             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11054                 return false;
11055             }
11056             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11057                 return false;
11058             }
11059             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11060                 return false;
11061             }
11062             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11063                 return false;
11064             }
11065             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11066                 return false;
11067             }
11068             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11069                 return false;
11070             }
11071             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11072                 return false;
11073             }
11074             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11075                 return false;
11076             }
11077             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11078                 return false;
11079             }
11080             p7 = null;
11081             final Phylogeny species8 = factory
11082                     .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,"
11083                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11084                              new NHXParser() )[ 0 ];
11085             final Phylogeny gene8 = factory
11086                     .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],"
11087                                      + "(((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],"
11088                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11089                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11090                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11091                              new NHXParser() )[ 0 ];
11092             species8.setRooted( true );
11093             gene8.setRooted( true );
11094             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11095             if ( sdi_unrooted.getCount() != 1 ) {
11096                 return false;
11097             }
11098             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11099                 return false;
11100             }
11101             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11102                 return false;
11103             }
11104             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11105                 return false;
11106             }
11107             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11108                 return false;
11109             }
11110             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11111                 return false;
11112             }
11113             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11114                 return false;
11115             }
11116             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11117                 return false;
11118             }
11119             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11120                 return false;
11121             }
11122             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11123                 return false;
11124             }
11125             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11126                 return false;
11127             }
11128             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11129                 return false;
11130             }
11131             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11132                 return false;
11133             }
11134             p8 = null;
11135         }
11136         catch ( final Exception e ) {
11137             e.printStackTrace( System.out );
11138             return false;
11139         }
11140         return true;
11141     }
11142
11143     private static boolean testSequenceDbWsTools1() {
11144         try {
11145             final PhylogenyNode n = new PhylogenyNode();
11146             n.setName( "NP_001025424" );
11147             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11148             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11149                     || !acc.getValue().equals( "NP_001025424" ) ) {
11150                 return false;
11151             }
11152             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11153             acc = SequenceDbWsTools.obtainSeqAccession( n );
11154             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11155                     || !acc.getValue().equals( "NP_001025424" ) ) {
11156                 return false;
11157             }
11158             n.setName( "NP_001025424.1" );
11159             acc = SequenceDbWsTools.obtainSeqAccession( n );
11160             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11161                     || !acc.getValue().equals( "NP_001025424" ) ) {
11162                 return false;
11163             }
11164             n.setName( "NM_001030253" );
11165             acc = SequenceDbWsTools.obtainSeqAccession( n );
11166             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11167                     || !acc.getValue().equals( "NM_001030253" ) ) {
11168                 return false;
11169             }
11170             n.setName( "BCL2_HUMAN" );
11171             acc = SequenceDbWsTools.obtainSeqAccession( n );
11172             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11173                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11174                 System.out.println( acc.toString() );
11175                 return false;
11176             }
11177             n.setName( "P10415" );
11178             acc = SequenceDbWsTools.obtainSeqAccession( n );
11179             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11180                     || !acc.getValue().equals( "P10415" ) ) {
11181                 System.out.println( acc.toString() );
11182                 return false;
11183             }
11184             n.setName( " P10415 " );
11185             acc = SequenceDbWsTools.obtainSeqAccession( n );
11186             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11187                     || !acc.getValue().equals( "P10415" ) ) {
11188                 System.out.println( acc.toString() );
11189                 return false;
11190             }
11191             n.setName( "_P10415|" );
11192             acc = SequenceDbWsTools.obtainSeqAccession( n );
11193             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11194                     || !acc.getValue().equals( "P10415" ) ) {
11195                 System.out.println( acc.toString() );
11196                 return false;
11197             }
11198             n.setName( "AY695820" );
11199             acc = SequenceDbWsTools.obtainSeqAccession( n );
11200             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11201                     || !acc.getValue().equals( "AY695820" ) ) {
11202                 System.out.println( acc.toString() );
11203                 return false;
11204             }
11205             n.setName( "_AY695820_" );
11206             acc = SequenceDbWsTools.obtainSeqAccession( n );
11207             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11208                     || !acc.getValue().equals( "AY695820" ) ) {
11209                 System.out.println( acc.toString() );
11210                 return false;
11211             }
11212             n.setName( "AAA59452" );
11213             acc = SequenceDbWsTools.obtainSeqAccession( n );
11214             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11215                     || !acc.getValue().equals( "AAA59452" ) ) {
11216                 System.out.println( acc.toString() );
11217                 return false;
11218             }
11219             n.setName( "_AAA59452_" );
11220             acc = SequenceDbWsTools.obtainSeqAccession( n );
11221             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11222                     || !acc.getValue().equals( "AAA59452" ) ) {
11223                 System.out.println( acc.toString() );
11224                 return false;
11225             }
11226             n.setName( "AAA59452.1" );
11227             acc = SequenceDbWsTools.obtainSeqAccession( n );
11228             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11229                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11230                 System.out.println( acc.toString() );
11231                 return false;
11232             }
11233             n.setName( "_AAA59452.1_" );
11234             acc = SequenceDbWsTools.obtainSeqAccession( n );
11235             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11236                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11237                 System.out.println( acc.toString() );
11238                 return false;
11239             }
11240             n.setName( "GI:94894583" );
11241             acc = SequenceDbWsTools.obtainSeqAccession( n );
11242             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11243                     || !acc.getValue().equals( "94894583" ) ) {
11244                 System.out.println( acc.toString() );
11245                 return false;
11246             }
11247             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11248             acc = SequenceDbWsTools.obtainSeqAccession( n );
11249             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11250                     || !acc.getValue().equals( "71845847" ) ) {
11251                 System.out.println( acc.toString() );
11252                 return false;
11253             }
11254             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11255             acc = SequenceDbWsTools.obtainSeqAccession( n );
11256             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11257                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11258                 System.out.println( acc.toString() );
11259                 return false;
11260             }
11261         }
11262         catch ( final Exception e ) {
11263             return false;
11264         }
11265         return true;
11266     }
11267
11268     private static boolean testSequenceDbWsTools2() {
11269         try {
11270             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11271             SequenceDbWsTools.obtainSeqInformation( n1 );
11272             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11273                 return false;
11274             }
11275             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11276                 return false;
11277             }
11278             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11279                 return false;
11280             }
11281             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11282                 return false;
11283             }
11284             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11285             SequenceDbWsTools.obtainSeqInformation( n2 );
11286             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11287                 return false;
11288             }
11289             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11290                 return false;
11291             }
11292             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11293                 return false;
11294             }
11295             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11296                 return false;
11297             }
11298             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11299             SequenceDbWsTools.obtainSeqInformation( n3 );
11300             if ( !n3.getNodeData().getSequence().getName()
11301                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11302                 return false;
11303             }
11304             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11305                 return false;
11306             }
11307             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11308                 return false;
11309             }
11310             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11311                 return false;
11312             }
11313         }
11314         catch ( final IOException e ) {
11315             System.out.println();
11316             System.out.println( "the following might be due to absence internet connection:" );
11317             e.printStackTrace( System.out );
11318             return true;
11319         }
11320         catch ( final Exception e ) {
11321             e.printStackTrace();
11322             return false;
11323         }
11324         return true;
11325     }
11326
11327     private static boolean testSequenceIdParsing() {
11328         try {
11329             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11330             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11331                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11332                 if ( id != null ) {
11333                     System.out.println( "value   =" + id.getValue() );
11334                     System.out.println( "provider=" + id.getSource() );
11335                 }
11336                 return false;
11337             }
11338             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11339             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11340                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11341                 if ( id != null ) {
11342                     System.out.println( "value   =" + id.getValue() );
11343                     System.out.println( "provider=" + id.getSource() );
11344                 }
11345                 return false;
11346             }
11347             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11348             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11349                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11350                 if ( id != null ) {
11351                     System.out.println( "value   =" + id.getValue() );
11352                     System.out.println( "provider=" + id.getSource() );
11353                 }
11354                 return false;
11355             }
11356             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11357             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11358                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11359                 if ( id != null ) {
11360                     System.out.println( "value   =" + id.getValue() );
11361                     System.out.println( "provider=" + id.getSource() );
11362                 }
11363                 return false;
11364             }
11365             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11366             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11367                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11368                 if ( id != null ) {
11369                     System.out.println( "value   =" + id.getValue() );
11370                     System.out.println( "provider=" + id.getSource() );
11371                 }
11372                 return false;
11373             }
11374             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11375             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11376                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11377                 if ( id != null ) {
11378                     System.out.println( "value   =" + id.getValue() );
11379                     System.out.println( "provider=" + id.getSource() );
11380                 }
11381                 return false;
11382             }
11383             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11384             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11385                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11386                 if ( id != null ) {
11387                     System.out.println( "value   =" + id.getValue() );
11388                     System.out.println( "provider=" + id.getSource() );
11389                 }
11390                 return false;
11391             }
11392             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11393             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11394                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11395                 if ( id != null ) {
11396                     System.out.println( "value   =" + id.getValue() );
11397                     System.out.println( "provider=" + id.getSource() );
11398                 }
11399                 return false;
11400             }
11401             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11402             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11403                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11404                 if ( id != null ) {
11405                     System.out.println( "value   =" + id.getValue() );
11406                     System.out.println( "provider=" + id.getSource() );
11407                 }
11408                 return false;
11409             }
11410             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11411             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11412                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11413                 if ( id != null ) {
11414                     System.out.println( "value   =" + id.getValue() );
11415                     System.out.println( "provider=" + id.getSource() );
11416                 }
11417                 return false;
11418             }
11419             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11420             if ( id != null ) {
11421                 System.out.println( "value   =" + id.getValue() );
11422                 System.out.println( "provider=" + id.getSource() );
11423                 return false;
11424             }
11425             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11426             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11427                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11428                 if ( id != null ) {
11429                     System.out.println( "value   =" + id.getValue() );
11430                     System.out.println( "provider=" + id.getSource() );
11431                 }
11432                 return false;
11433             }
11434             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11435             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11436                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11437                 if ( id != null ) {
11438                     System.out.println( "value   =" + id.getValue() );
11439                     System.out.println( "provider=" + id.getSource() );
11440                 }
11441                 return false;
11442             }
11443             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11444             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11445                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11446                 if ( id != null ) {
11447                     System.out.println( "value   =" + id.getValue() );
11448                     System.out.println( "provider=" + id.getSource() );
11449                 }
11450                 return false;
11451             }
11452             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11453             if ( id != null ) {
11454                 System.out.println( "value   =" + id.getValue() );
11455                 System.out.println( "provider=" + id.getSource() );
11456                 return false;
11457             }
11458         }
11459         catch ( final Exception e ) {
11460             e.printStackTrace( System.out );
11461             return false;
11462         }
11463         return true;
11464     }
11465
11466     private static boolean testSequenceWriter() {
11467         try {
11468             final String n = ForesterUtil.LINE_SEPARATOR;
11469             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11470                 return false;
11471             }
11472             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11473                 return false;
11474             }
11475             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11476                 return false;
11477             }
11478             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11479                 return false;
11480             }
11481             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11482                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11483                 return false;
11484             }
11485             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11486                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11487                 return false;
11488             }
11489         }
11490         catch ( final Exception e ) {
11491             e.printStackTrace();
11492             return false;
11493         }
11494         return true;
11495     }
11496
11497     private static boolean testSpecies() {
11498         try {
11499             final Species s1 = new BasicSpecies( "a" );
11500             final Species s2 = new BasicSpecies( "a" );
11501             final Species s3 = new BasicSpecies( "A" );
11502             final Species s4 = new BasicSpecies( "b" );
11503             if ( !s1.equals( s1 ) ) {
11504                 return false;
11505             }
11506             if ( s1.getSpeciesId().equals( "x" ) ) {
11507                 return false;
11508             }
11509             if ( s1.getSpeciesId().equals( null ) ) {
11510                 return false;
11511             }
11512             if ( !s1.equals( s2 ) ) {
11513                 return false;
11514             }
11515             if ( s1.equals( s3 ) ) {
11516                 return false;
11517             }
11518             if ( s1.hashCode() != s1.hashCode() ) {
11519                 return false;
11520             }
11521             if ( s1.hashCode() != s2.hashCode() ) {
11522                 return false;
11523             }
11524             if ( s1.hashCode() == s3.hashCode() ) {
11525                 return false;
11526             }
11527             if ( s1.compareTo( s1 ) != 0 ) {
11528                 return false;
11529             }
11530             if ( s1.compareTo( s2 ) != 0 ) {
11531                 return false;
11532             }
11533             if ( s1.compareTo( s3 ) != 0 ) {
11534                 return false;
11535             }
11536             if ( s1.compareTo( s4 ) >= 0 ) {
11537                 return false;
11538             }
11539             if ( s4.compareTo( s1 ) <= 0 ) {
11540                 return false;
11541             }
11542             if ( !s4.getSpeciesId().equals( "b" ) ) {
11543                 return false;
11544             }
11545             final Species s5 = new BasicSpecies( " C " );
11546             if ( !s5.getSpeciesId().equals( "C" ) ) {
11547                 return false;
11548             }
11549             if ( s5.equals( s1 ) ) {
11550                 return false;
11551             }
11552         }
11553         catch ( final Exception e ) {
11554             e.printStackTrace( System.out );
11555             return false;
11556         }
11557         return true;
11558     }
11559
11560     private static boolean testSplit() {
11561         try {
11562             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11563             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11564             //Archaeopteryx.createApplication( p0 );
11565             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11566             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11567             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11568             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11569             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11570             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11571             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11572             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11573             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11574             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11575             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11576             // System.out.println( s0.toString() );
11577             //
11578             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11581             if ( s0.match( query_nodes ) ) {
11582                 return false;
11583             }
11584             query_nodes = new HashSet<PhylogenyNode>();
11585             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11592             if ( !s0.match( query_nodes ) ) {
11593                 return false;
11594             }
11595             //
11596             query_nodes = new HashSet<PhylogenyNode>();
11597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11599             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11600             if ( !s0.match( query_nodes ) ) {
11601                 return false;
11602             }
11603             //
11604             query_nodes = new HashSet<PhylogenyNode>();
11605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11609             if ( !s0.match( query_nodes ) ) {
11610                 return false;
11611             }
11612             //
11613             query_nodes = new HashSet<PhylogenyNode>();
11614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11618             if ( !s0.match( query_nodes ) ) {
11619                 return false;
11620             }
11621             //
11622             query_nodes = new HashSet<PhylogenyNode>();
11623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11626             if ( !s0.match( query_nodes ) ) {
11627                 return false;
11628             }
11629             query_nodes = new HashSet<PhylogenyNode>();
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11632             if ( !s0.match( query_nodes ) ) {
11633                 return false;
11634             }
11635             query_nodes = new HashSet<PhylogenyNode>();
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11641             if ( !s0.match( query_nodes ) ) {
11642                 return false;
11643             }
11644             query_nodes = new HashSet<PhylogenyNode>();
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11648             if ( !s0.match( query_nodes ) ) {
11649                 return false;
11650             }
11651             query_nodes = new HashSet<PhylogenyNode>();
11652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11656             if ( !s0.match( query_nodes ) ) {
11657                 return false;
11658             }
11659             query_nodes = new HashSet<PhylogenyNode>();
11660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11662             if ( s0.match( query_nodes ) ) {
11663                 return false;
11664             }
11665             query_nodes = new HashSet<PhylogenyNode>();
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11670             if ( s0.match( query_nodes ) ) {
11671                 return false;
11672             }
11673             query_nodes = new HashSet<PhylogenyNode>();
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11679             if ( s0.match( query_nodes ) ) {
11680                 return false;
11681             }
11682             query_nodes = new HashSet<PhylogenyNode>();
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11686             if ( s0.match( query_nodes ) ) {
11687                 return false;
11688             }
11689             query_nodes = new HashSet<PhylogenyNode>();
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11692             if ( s0.match( query_nodes ) ) {
11693                 return false;
11694             }
11695             query_nodes = new HashSet<PhylogenyNode>();
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11698             if ( s0.match( query_nodes ) ) {
11699                 return false;
11700             }
11701             query_nodes = new HashSet<PhylogenyNode>();
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11704             if ( s0.match( query_nodes ) ) {
11705                 return false;
11706             }
11707             query_nodes = new HashSet<PhylogenyNode>();
11708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11710             if ( s0.match( query_nodes ) ) {
11711                 return false;
11712             }
11713             query_nodes = new HashSet<PhylogenyNode>();
11714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11716             if ( s0.match( query_nodes ) ) {
11717                 return false;
11718             }
11719             query_nodes = new HashSet<PhylogenyNode>();
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11722             if ( s0.match( query_nodes ) ) {
11723                 return false;
11724             }
11725             query_nodes = new HashSet<PhylogenyNode>();
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11729             if ( s0.match( query_nodes ) ) {
11730                 return false;
11731             }
11732             query_nodes = new HashSet<PhylogenyNode>();
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11736             if ( s0.match( query_nodes ) ) {
11737                 return false;
11738             }
11739             query_nodes = new HashSet<PhylogenyNode>();
11740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11743             if ( s0.match( query_nodes ) ) {
11744                 return false;
11745             }
11746             query_nodes = new HashSet<PhylogenyNode>();
11747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11751             if ( s0.match( query_nodes ) ) {
11752                 return false;
11753             }
11754             /////////
11755             //            query_nodes = new HashSet<PhylogenyNode>();
11756             //            query_nodes.add( new PhylogenyNode( "X" ) );
11757             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11758             //            query_nodes.add( new PhylogenyNode( "A" ) );
11759             //            query_nodes.add( new PhylogenyNode( "B" ) );
11760             //            query_nodes.add( new PhylogenyNode( "C" ) );
11761             //            query_nodes.add( new PhylogenyNode( "D" ) );
11762             //            query_nodes.add( new PhylogenyNode( "E" ) );
11763             //            query_nodes.add( new PhylogenyNode( "F" ) );
11764             //            query_nodes.add( new PhylogenyNode( "G" ) );
11765             //            if ( !s0.match( query_nodes ) ) {
11766             //                return false;
11767             //            }
11768             //            query_nodes = new HashSet<PhylogenyNode>();
11769             //            query_nodes.add( new PhylogenyNode( "X" ) );
11770             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11771             //            query_nodes.add( new PhylogenyNode( "A" ) );
11772             //            query_nodes.add( new PhylogenyNode( "B" ) );
11773             //            query_nodes.add( new PhylogenyNode( "C" ) );
11774             //            if ( !s0.match( query_nodes ) ) {
11775             //                return false;
11776             //            }
11777             //            //
11778             //            query_nodes = new HashSet<PhylogenyNode>();
11779             //            query_nodes.add( new PhylogenyNode( "X" ) );
11780             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11781             //            query_nodes.add( new PhylogenyNode( "D" ) );
11782             //            query_nodes.add( new PhylogenyNode( "E" ) );
11783             //            query_nodes.add( new PhylogenyNode( "F" ) );
11784             //            query_nodes.add( new PhylogenyNode( "G" ) );
11785             //            if ( !s0.match( query_nodes ) ) {
11786             //                return false;
11787             //            }
11788             //            //
11789             //            query_nodes = new HashSet<PhylogenyNode>();
11790             //            query_nodes.add( new PhylogenyNode( "X" ) );
11791             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11792             //            query_nodes.add( new PhylogenyNode( "A" ) );
11793             //            query_nodes.add( new PhylogenyNode( "B" ) );
11794             //            query_nodes.add( new PhylogenyNode( "C" ) );
11795             //            query_nodes.add( new PhylogenyNode( "D" ) );
11796             //            if ( !s0.match( query_nodes ) ) {
11797             //                return false;
11798             //            }
11799             //            //
11800             //            query_nodes = new HashSet<PhylogenyNode>();
11801             //            query_nodes.add( new PhylogenyNode( "X" ) );
11802             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11803             //            query_nodes.add( new PhylogenyNode( "E" ) );
11804             //            query_nodes.add( new PhylogenyNode( "F" ) );
11805             //            query_nodes.add( new PhylogenyNode( "G" ) );
11806             //            if ( !s0.match( query_nodes ) ) {
11807             //                return false;
11808             //            }
11809             //            //
11810             //            query_nodes = new HashSet<PhylogenyNode>();
11811             //            query_nodes.add( new PhylogenyNode( "X" ) );
11812             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11813             //            query_nodes.add( new PhylogenyNode( "F" ) );
11814             //            query_nodes.add( new PhylogenyNode( "G" ) );
11815             //            if ( !s0.match( query_nodes ) ) {
11816             //                return false;
11817             //            }
11818             //
11819             query_nodes = new HashSet<PhylogenyNode>();
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11824             if ( s0.match( query_nodes ) ) {
11825                 return false;
11826             }
11827             //
11828             query_nodes = new HashSet<PhylogenyNode>();
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11833             if ( s0.match( query_nodes ) ) {
11834                 return false;
11835             }
11836             ///////////////////////////
11837             //
11838             query_nodes = new HashSet<PhylogenyNode>();
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11843             if ( s0.match( query_nodes ) ) {
11844                 return false;
11845             }
11846             //
11847             query_nodes = new HashSet<PhylogenyNode>();
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11852             if ( s0.match( query_nodes ) ) {
11853                 return false;
11854             }
11855             //
11856             query_nodes = new HashSet<PhylogenyNode>();
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11861             if ( s0.match( query_nodes ) ) {
11862                 return false;
11863             }
11864             //
11865             query_nodes = new HashSet<PhylogenyNode>();
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11870             if ( s0.match( query_nodes ) ) {
11871                 return false;
11872             }
11873             //
11874             query_nodes = new HashSet<PhylogenyNode>();
11875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11879             if ( s0.match( query_nodes ) ) {
11880                 return false;
11881             }
11882             //
11883             query_nodes = new HashSet<PhylogenyNode>();
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11887             if ( s0.match( query_nodes ) ) {
11888                 return false;
11889             }
11890             //
11891             query_nodes = new HashSet<PhylogenyNode>();
11892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11897             if ( s0.match( query_nodes ) ) {
11898                 return false;
11899             }
11900             //
11901             query_nodes = new HashSet<PhylogenyNode>();
11902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11907             if ( s0.match( query_nodes ) ) {
11908                 return false;
11909             }
11910             //
11911             query_nodes = new HashSet<PhylogenyNode>();
11912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11917             if ( s0.match( query_nodes ) ) {
11918                 return false;
11919             }
11920             //
11921             query_nodes = new HashSet<PhylogenyNode>();
11922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11928             if ( s0.match( query_nodes ) ) {
11929                 return false;
11930             }
11931         }
11932         catch ( final Exception e ) {
11933             e.printStackTrace();
11934             return false;
11935         }
11936         return true;
11937     }
11938
11939     private static boolean testSplitStrict() {
11940         try {
11941             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11942             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11943             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11944             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11945             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11946             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11947             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11948             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11949             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11950             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11951             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11952             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11955             if ( s0.match( query_nodes ) ) {
11956                 return false;
11957             }
11958             query_nodes = new HashSet<PhylogenyNode>();
11959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11966             if ( !s0.match( query_nodes ) ) {
11967                 return false;
11968             }
11969             //
11970             query_nodes = new HashSet<PhylogenyNode>();
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11974             if ( !s0.match( query_nodes ) ) {
11975                 return false;
11976             }
11977             //
11978             query_nodes = new HashSet<PhylogenyNode>();
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11983             if ( !s0.match( query_nodes ) ) {
11984                 return false;
11985             }
11986             //
11987             query_nodes = new HashSet<PhylogenyNode>();
11988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11992             if ( !s0.match( query_nodes ) ) {
11993                 return false;
11994             }
11995             //
11996             query_nodes = new HashSet<PhylogenyNode>();
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12000             if ( !s0.match( query_nodes ) ) {
12001                 return false;
12002             }
12003             //
12004             query_nodes = new HashSet<PhylogenyNode>();
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12007             if ( !s0.match( query_nodes ) ) {
12008                 return false;
12009             }
12010             //
12011             query_nodes = new HashSet<PhylogenyNode>();
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12017             if ( !s0.match( query_nodes ) ) {
12018                 return false;
12019             }
12020             //
12021             query_nodes = new HashSet<PhylogenyNode>();
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12025             if ( !s0.match( query_nodes ) ) {
12026                 return false;
12027             }
12028             //
12029             query_nodes = new HashSet<PhylogenyNode>();
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12034             if ( !s0.match( query_nodes ) ) {
12035                 return false;
12036             }
12037             //
12038             query_nodes = new HashSet<PhylogenyNode>();
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12041             if ( s0.match( query_nodes ) ) {
12042                 return false;
12043             }
12044             //
12045             query_nodes = new HashSet<PhylogenyNode>();
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12050             if ( s0.match( query_nodes ) ) {
12051                 return false;
12052             }
12053             //
12054             query_nodes = new HashSet<PhylogenyNode>();
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12060             if ( s0.match( query_nodes ) ) {
12061                 return false;
12062             }
12063             //
12064             query_nodes = new HashSet<PhylogenyNode>();
12065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12068             if ( s0.match( query_nodes ) ) {
12069                 return false;
12070             }
12071             //
12072             query_nodes = new HashSet<PhylogenyNode>();
12073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12075             if ( s0.match( query_nodes ) ) {
12076                 return false;
12077             }
12078             //
12079             query_nodes = new HashSet<PhylogenyNode>();
12080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12082             if ( s0.match( query_nodes ) ) {
12083                 return false;
12084             }
12085             //
12086             query_nodes = new HashSet<PhylogenyNode>();
12087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12089             if ( s0.match( query_nodes ) ) {
12090                 return false;
12091             }
12092             //
12093             query_nodes = new HashSet<PhylogenyNode>();
12094             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12095             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12096             if ( s0.match( query_nodes ) ) {
12097                 return false;
12098             }
12099             //
12100             query_nodes = new HashSet<PhylogenyNode>();
12101             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12102             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12103             if ( s0.match( query_nodes ) ) {
12104                 return false;
12105             }
12106             //
12107             query_nodes = new HashSet<PhylogenyNode>();
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12110             if ( s0.match( query_nodes ) ) {
12111                 return false;
12112             }
12113             //
12114             query_nodes = new HashSet<PhylogenyNode>();
12115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12118             if ( s0.match( query_nodes ) ) {
12119                 return false;
12120             }
12121             //
12122             query_nodes = new HashSet<PhylogenyNode>();
12123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12126             if ( s0.match( query_nodes ) ) {
12127                 return false;
12128             }
12129             //
12130             query_nodes = new HashSet<PhylogenyNode>();
12131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12134             if ( s0.match( query_nodes ) ) {
12135                 return false;
12136             }
12137             //
12138             query_nodes = new HashSet<PhylogenyNode>();
12139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12143             if ( s0.match( query_nodes ) ) {
12144                 return false;
12145             }
12146         }
12147         catch ( final Exception e ) {
12148             e.printStackTrace();
12149             return false;
12150         }
12151         return true;
12152     }
12153
12154     private static boolean testSubtreeDeletion() {
12155         try {
12156             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12157             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12158             t1.deleteSubtree( t1.getNode( "A" ), false );
12159             if ( t1.getNumberOfExternalNodes() != 5 ) {
12160                 return false;
12161             }
12162             t1.toNewHampshireX();
12163             t1.deleteSubtree( t1.getNode( "E" ), false );
12164             if ( t1.getNumberOfExternalNodes() != 4 ) {
12165                 return false;
12166             }
12167             t1.toNewHampshireX();
12168             t1.deleteSubtree( t1.getNode( "F" ), false );
12169             if ( t1.getNumberOfExternalNodes() != 3 ) {
12170                 return false;
12171             }
12172             t1.toNewHampshireX();
12173             t1.deleteSubtree( t1.getNode( "D" ), false );
12174             t1.toNewHampshireX();
12175             if ( t1.getNumberOfExternalNodes() != 3 ) {
12176                 return false;
12177             }
12178             t1.deleteSubtree( t1.getNode( "def" ), false );
12179             t1.toNewHampshireX();
12180             if ( t1.getNumberOfExternalNodes() != 2 ) {
12181                 return false;
12182             }
12183             t1.deleteSubtree( t1.getNode( "B" ), false );
12184             t1.toNewHampshireX();
12185             if ( t1.getNumberOfExternalNodes() != 1 ) {
12186                 return false;
12187             }
12188             t1.deleteSubtree( t1.getNode( "C" ), false );
12189             t1.toNewHampshireX();
12190             if ( t1.getNumberOfExternalNodes() != 1 ) {
12191                 return false;
12192             }
12193             t1.deleteSubtree( t1.getNode( "abc" ), false );
12194             t1.toNewHampshireX();
12195             if ( t1.getNumberOfExternalNodes() != 1 ) {
12196                 return false;
12197             }
12198             t1.deleteSubtree( t1.getNode( "r" ), false );
12199             if ( t1.getNumberOfExternalNodes() != 0 ) {
12200                 return false;
12201             }
12202             if ( !t1.isEmpty() ) {
12203                 return false;
12204             }
12205             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12206             t2.deleteSubtree( t2.getNode( "A" ), false );
12207             t2.toNewHampshireX();
12208             if ( t2.getNumberOfExternalNodes() != 5 ) {
12209                 return false;
12210             }
12211             t2.deleteSubtree( t2.getNode( "abc" ), false );
12212             t2.toNewHampshireX();
12213             if ( t2.getNumberOfExternalNodes() != 3 ) {
12214                 return false;
12215             }
12216             t2.deleteSubtree( t2.getNode( "def" ), false );
12217             t2.toNewHampshireX();
12218             if ( t2.getNumberOfExternalNodes() != 1 ) {
12219                 return false;
12220             }
12221         }
12222         catch ( final Exception e ) {
12223             e.printStackTrace( System.out );
12224             return false;
12225         }
12226         return true;
12227     }
12228
12229     private static boolean testSupportCount() {
12230         try {
12231             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12232             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12233             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12234                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12235                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12236                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12237                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12238                                                               new NHXParser() );
12239             SupportCount.count( t0_1, phylogenies_1, true, false );
12240             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12241             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12242                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12243                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12244                                                                       + "(((((A,B),C),D),E),(F,G))"
12245                                                                       + "(((((A,B),C),D),E),(F,G))"
12246                                                                       + "(((((A,B),C),D),E),(F,G))"
12247                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12248                                                                       + "(((((A,B),C),D),E),(F,G))"
12249                                                                       + "((((((A,B),C),D),E),F),G)"
12250                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12251                                                               new NHXParser() );
12252             SupportCount.count( t0_2, phylogenies_2, true, false );
12253             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12254             while ( it.hasNext() ) {
12255                 final PhylogenyNode n = it.next();
12256                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12257                     return false;
12258                 }
12259             }
12260             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12261             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12262                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12263             SupportCount.count( t0_3, phylogenies_3, true, false );
12264             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12265             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12266                 return false;
12267             }
12268             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12269                 return false;
12270             }
12271             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12272                 return false;
12273             }
12274             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12275                 return false;
12276             }
12277             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12278                 return false;
12279             }
12280             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12281                 return false;
12282             }
12283             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12284                 return false;
12285             }
12286             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12287                 return false;
12288             }
12289             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12290                 return false;
12291             }
12292             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12293                 return false;
12294             }
12295             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12296             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12297                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12298             SupportCount.count( t0_4, phylogenies_4, true, false );
12299             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12300             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12301                 return false;
12302             }
12303             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12304                 return false;
12305             }
12306             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12307                 return false;
12308             }
12309             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12310                 return false;
12311             }
12312             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12313                 return false;
12314             }
12315             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12316                 return false;
12317             }
12318             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12319                 return false;
12320             }
12321             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12322                 return false;
12323             }
12324             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12325                 return false;
12326             }
12327             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12328                 return false;
12329             }
12330             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12331             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12332             double d = SupportCount.compare( b1, a, true, true, true );
12333             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12334                 return false;
12335             }
12336             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12337             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12338             d = SupportCount.compare( b2, a, true, true, true );
12339             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12340                 return false;
12341             }
12342             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12343             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12344             d = SupportCount.compare( b3, a, true, true, true );
12345             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12346                 return false;
12347             }
12348             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12349             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12350             d = SupportCount.compare( b4, a, true, true, false );
12351             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12352                 return false;
12353             }
12354         }
12355         catch ( final Exception e ) {
12356             e.printStackTrace( System.out );
12357             return false;
12358         }
12359         return true;
12360     }
12361
12362     private static boolean testSupportTransfer() {
12363         try {
12364             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12365             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)",
12366                                                  new NHXParser() )[ 0 ];
12367             final Phylogeny p2 = factory
12368                     .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 ];
12369             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12370                 return false;
12371             }
12372             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12373                 return false;
12374             }
12375             support_transfer.moveBranchLengthsToBootstrap( p1 );
12376             support_transfer.transferSupportValues( p1, p2 );
12377             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12378                 return false;
12379             }
12380             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12381                 return false;
12382             }
12383             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12384                 return false;
12385             }
12386             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12387                 return false;
12388             }
12389             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12390                 return false;
12391             }
12392             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12393                 return false;
12394             }
12395             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12396                 return false;
12397             }
12398             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12399                 return false;
12400             }
12401         }
12402         catch ( final Exception e ) {
12403             e.printStackTrace( System.out );
12404             return false;
12405         }
12406         return true;
12407     }
12408
12409     private static boolean testTaxonomyExtraction() {
12410         try {
12411             final PhylogenyNode n0 = PhylogenyNode
12412                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12413             if ( n0.getNodeData().isHasTaxonomy() ) {
12414                 return false;
12415             }
12416             final PhylogenyNode n1 = PhylogenyNode
12417                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12418             if ( n1.getNodeData().isHasTaxonomy() ) {
12419                 System.out.println( n1.toString() );
12420                 return false;
12421             }
12422             final PhylogenyNode n2x = PhylogenyNode
12423                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12424             if ( n2x.getNodeData().isHasTaxonomy() ) {
12425                 return false;
12426             }
12427             final PhylogenyNode n3 = PhylogenyNode
12428                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12429             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12430                 System.out.println( n3.toString() );
12431                 return false;
12432             }
12433             final PhylogenyNode n4 = PhylogenyNode
12434                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12435             if ( n4.getNodeData().isHasTaxonomy() ) {
12436                 System.out.println( n4.toString() );
12437                 return false;
12438             }
12439             final PhylogenyNode n5 = PhylogenyNode
12440                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12441             if ( n5.getNodeData().isHasTaxonomy() ) {
12442                 System.out.println( n5.toString() );
12443                 return false;
12444             }
12445             final PhylogenyNode n6 = PhylogenyNode
12446                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12447             if ( n6.getNodeData().isHasTaxonomy() ) {
12448                 System.out.println( n6.toString() );
12449                 return false;
12450             }
12451             final PhylogenyNode n7 = PhylogenyNode
12452                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12453             if ( n7.getNodeData().isHasTaxonomy() ) {
12454                 System.out.println( n7.toString() );
12455                 return false;
12456             }
12457             final PhylogenyNode n8 = PhylogenyNode
12458                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12459             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12460                 System.out.println( n8.toString() );
12461                 return false;
12462             }
12463             final PhylogenyNode n9 = PhylogenyNode
12464                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12465             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12466                 System.out.println( n9.toString() );
12467                 return false;
12468             }
12469             final PhylogenyNode n10x = PhylogenyNode
12470                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12471             if ( n10x.getNodeData().isHasTaxonomy() ) {
12472                 System.out.println( n10x.toString() );
12473                 return false;
12474             }
12475             final PhylogenyNode n10xx = PhylogenyNode
12476                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12477             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12478                 System.out.println( n10xx.toString() );
12479                 return false;
12480             }
12481             final PhylogenyNode n10 = PhylogenyNode
12482                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12483             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12484                 System.out.println( n10.toString() );
12485                 return false;
12486             }
12487             final PhylogenyNode n11 = PhylogenyNode
12488                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12489             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12490                 System.out.println( n11.toString() );
12491                 return false;
12492             }
12493             final PhylogenyNode n12 = PhylogenyNode
12494                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12495                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12496             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12497                 System.out.println( n12.toString() );
12498                 return false;
12499             }
12500             final PhylogenyNode n13 = PhylogenyNode
12501                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12502             if ( n13.getNodeData().isHasTaxonomy() ) {
12503                 System.out.println( n13.toString() );
12504                 return false;
12505             }
12506             final PhylogenyNode n14 = PhylogenyNode
12507                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12508             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12509                 System.out.println( n14.toString() );
12510                 return false;
12511             }
12512             final PhylogenyNode n15 = PhylogenyNode
12513                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12514             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12515                 System.out.println( n15.toString() );
12516                 return false;
12517             }
12518             final PhylogenyNode n16 = PhylogenyNode
12519                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12520             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12521                 System.out.println( n16.toString() );
12522                 return false;
12523             }
12524             final PhylogenyNode n17 = PhylogenyNode
12525                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12526             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12527                 System.out.println( n17.toString() );
12528                 return false;
12529             }
12530             final PhylogenyNode n18 = PhylogenyNode
12531                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12532             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12533                 System.out.println( n18.toString() );
12534                 return false;
12535             }
12536             final PhylogenyNode n19 = PhylogenyNode
12537                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12538                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12539             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12540                 System.out.println( n19.toString() );
12541                 return false;
12542             }
12543             final PhylogenyNode n20 = PhylogenyNode
12544                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12545             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12546                 System.out.println( n20.toString() );
12547                 return false;
12548             }
12549             final PhylogenyNode n21 = PhylogenyNode
12550                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12551                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12552             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12553                 System.out.println( n21.toString() );
12554                 return false;
12555             }
12556             final PhylogenyNode n23 = PhylogenyNode
12557                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12558                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12559             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12560                 System.out.println( n23.toString() );
12561                 return false;
12562             }
12563             final PhylogenyNode n24 = PhylogenyNode
12564                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12565             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12566                 System.out.println( n24.toString() );
12567                 return false;
12568             }
12569             //
12570             final PhylogenyNode n25 = PhylogenyNode
12571                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12572                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12573             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12574                 System.out.println( n25.toString() );
12575                 return false;
12576             }
12577             final PhylogenyNode n26 = PhylogenyNode
12578                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12579                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12580             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12581                 System.out.println( n26.toString() );
12582                 return false;
12583             }
12584             final PhylogenyNode n27 = PhylogenyNode
12585                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12586             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12587                 System.out.println( n27.toString() );
12588                 return false;
12589             }
12590         }
12591         catch ( final Exception e ) {
12592             e.printStackTrace( System.out );
12593             return false;
12594         }
12595         return true;
12596     }
12597
12598     private static boolean testTreeCopy() {
12599         try {
12600             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12601             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12602             final Phylogeny t1 = t0.copy();
12603             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12604                 return false;
12605             }
12606             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12607                 return false;
12608             }
12609             t0.deleteSubtree( t0.getNode( "c" ), true );
12610             t0.deleteSubtree( t0.getNode( "a" ), true );
12611             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12612             t0.getNode( "b" ).setName( "Bee" );
12613             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12614                 return false;
12615             }
12616             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12617                 return false;
12618             }
12619             t0.deleteSubtree( t0.getNode( "e" ), true );
12620             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12621             t0.deleteSubtree( t0.getNode( "d" ), true );
12622             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12623                 return false;
12624             }
12625         }
12626         catch ( final Exception e ) {
12627             e.printStackTrace();
12628             return false;
12629         }
12630         return true;
12631     }
12632
12633     private static boolean testTreeMethods() {
12634         try {
12635             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12636             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12637             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12638             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12639                 System.out.println( t0.toNewHampshireX() );
12640                 return false;
12641             }
12642             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12643             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12644             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12645                 return false;
12646             }
12647             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12648                 return false;
12649             }
12650             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12651                 return false;
12652             }
12653         }
12654         catch ( final Exception e ) {
12655             e.printStackTrace( System.out );
12656             return false;
12657         }
12658         return true;
12659     }
12660
12661     private static boolean testUniprotEntryRetrieval() {
12662         try {
12663             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12664             if ( !entry.getAccession().equals( "P12345" ) ) {
12665                 return false;
12666             }
12667             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12668                 return false;
12669             }
12670             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12671                 return false;
12672             }
12673             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12674                 return false;
12675             }
12676             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12677                 return false;
12678             }
12679             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12680                 return false;
12681             }
12682             if ( !entry
12683                     .getMolecularSequence()
12684                     .getMolecularSequenceAsString()
12685                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12686                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12687                 System.out.println( entry.getMolecularSequence().getMolecularSequenceAsString() );
12688                 return false;
12689             }
12690         }
12691         catch ( final IOException e ) {
12692             System.out.println();
12693             System.out.println( "the following might be due to absence internet connection:" );
12694             e.printStackTrace( System.out );
12695             return true;
12696         }
12697         catch ( final Exception e ) {
12698             return false;
12699         }
12700         return true;
12701     }
12702
12703     private static boolean testUniprotTaxonomySearch() {
12704         try {
12705             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12706                                                                                                  10 );
12707             if ( results.size() != 1 ) {
12708                 return false;
12709             }
12710             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12711                 return false;
12712             }
12713             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12714                 return false;
12715             }
12716             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12717                 return false;
12718             }
12719             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12720                 return false;
12721             }
12722             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12723                 return false;
12724             }
12725             results = null;
12726             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12727             if ( results.size() != 1 ) {
12728                 return false;
12729             }
12730             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12731                 return false;
12732             }
12733             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12734                 return false;
12735             }
12736             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12737                 return false;
12738             }
12739             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12740                 return false;
12741             }
12742             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12743                 return false;
12744             }
12745             results = null;
12746             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12747             if ( results.size() != 1 ) {
12748                 return false;
12749             }
12750             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12751                 return false;
12752             }
12753             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12754                 return false;
12755             }
12756             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12757                 return false;
12758             }
12759             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12760                 return false;
12761             }
12762             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12763                 return false;
12764             }
12765             results = null;
12766             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12767             if ( results.size() != 1 ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12771                 return false;
12772             }
12773             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12774                 return false;
12775             }
12776             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12777                 return false;
12778             }
12779             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12780                 return false;
12781             }
12782             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12783                 return false;
12784             }
12785             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12786                 return false;
12787             }
12788             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12789                 return false;
12790             }
12791             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12792                     .equals( "Nematostella vectensis" ) ) {
12793                 System.out.println( results.get( 0 ).getLineage() );
12794                 return false;
12795             }
12796             //
12797             results = null;
12798             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12799             if ( results.size() != 1 ) {
12800                 return false;
12801             }
12802             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12803                 return false;
12804             }
12805             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12806                 return false;
12807             }
12808             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12809                 return false;
12810             }
12811             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12812                 return false;
12813             }
12814             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12815                 return false;
12816             }
12817             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12818                     .equals( "Xenopus tropicalis" ) ) {
12819                 System.out.println( results.get( 0 ).getLineage() );
12820                 return false;
12821             }
12822             //
12823             results = null;
12824             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12825             if ( results.size() != 1 ) {
12826                 return false;
12827             }
12828             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12829                 return false;
12830             }
12831             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12832                 return false;
12833             }
12834             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12835                 return false;
12836             }
12837             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12838                 return false;
12839             }
12840             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12841                 return false;
12842             }
12843             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12844                     .equals( "Xenopus tropicalis" ) ) {
12845                 System.out.println( results.get( 0 ).getLineage() );
12846                 return false;
12847             }
12848             //
12849             results = null;
12850             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12851             if ( results.size() != 1 ) {
12852                 return false;
12853             }
12854             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12855                 return false;
12856             }
12857             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12858                 return false;
12859             }
12860             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12861                 return false;
12862             }
12863             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12864                 return false;
12865             }
12866             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12867                 return false;
12868             }
12869             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12870                     .equals( "Xenopus tropicalis" ) ) {
12871                 System.out.println( results.get( 0 ).getLineage() );
12872                 return false;
12873             }
12874         }
12875         catch ( final IOException e ) {
12876             System.out.println();
12877             System.out.println( "the following might be due to absence internet connection:" );
12878             e.printStackTrace( System.out );
12879             return true;
12880         }
12881         catch ( final Exception e ) {
12882             return false;
12883         }
12884         return true;
12885     }
12886
12887     private static boolean testWabiTxSearch() {
12888         try {
12889             String result = "";
12890             result = TxSearch.searchSimple( "nematostella" );
12891             result = TxSearch.getTxId( "nematostella" );
12892             if ( !result.equals( "45350" ) ) {
12893                 return false;
12894             }
12895             result = TxSearch.getTxName( "45350" );
12896             if ( !result.equals( "Nematostella" ) ) {
12897                 return false;
12898             }
12899             result = TxSearch.getTxId( "nematostella vectensis" );
12900             if ( !result.equals( "45351" ) ) {
12901                 return false;
12902             }
12903             result = TxSearch.getTxName( "45351" );
12904             if ( !result.equals( "Nematostella vectensis" ) ) {
12905                 return false;
12906             }
12907             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12908             if ( !result.equals( "536089" ) ) {
12909                 return false;
12910             }
12911             result = TxSearch.getTxName( "536089" );
12912             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12913                 return false;
12914             }
12915             final List<String> queries = new ArrayList<String>();
12916             queries.add( "Campylobacter coli" );
12917             queries.add( "Escherichia coli" );
12918             queries.add( "Arabidopsis" );
12919             queries.add( "Trichoplax" );
12920             queries.add( "Samanea saman" );
12921             queries.add( "Kluyveromyces marxianus" );
12922             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12923             queries.add( "Bornavirus parrot/PDD/2008" );
12924             final List<RANKS> ranks = new ArrayList<RANKS>();
12925             ranks.add( RANKS.SUPERKINGDOM );
12926             ranks.add( RANKS.KINGDOM );
12927             ranks.add( RANKS.FAMILY );
12928             ranks.add( RANKS.GENUS );
12929             ranks.add( RANKS.TRIBE );
12930             result = TxSearch.searchLineage( queries, ranks );
12931             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12932             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12933         }
12934         catch ( final Exception e ) {
12935             System.out.println();
12936             System.out.println( "the following might be due to absence internet connection:" );
12937             e.printStackTrace( System.out );
12938             return false;
12939         }
12940         return true;
12941     }
12942 }