fixed some minor issues
[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          = true;
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         System.out.print( "Basic node methods: " );
185         if ( Test.testBasicNodeMethods() ) {
186             System.out.println( "OK." );
187             succeeded++;
188         }
189         else {
190             System.out.println( "failed." );
191             failed++;
192         }
193         System.out.print( "Protein id: " );
194         if ( !testProteinId() ) {
195             System.out.println( "failed." );
196             failed++;
197         }
198         else {
199             succeeded++;
200         }
201         System.out.println( "OK." );
202         System.out.print( "Species: " );
203         if ( !testSpecies() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Basic domain: " );
212         if ( !testBasicDomain() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Basic protein: " );
221         if ( !testBasicProtein() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Sequence writer: " );
230         if ( testSequenceWriter() ) {
231             System.out.println( "OK." );
232             succeeded++;
233         }
234         else {
235             System.out.println( "failed." );
236             failed++;
237         }
238         System.out.print( "Sequence id parsing: " );
239         if ( testSequenceIdParsing() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "UniProtKB id extraction: " );
248         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "Sequence DB tools 1: " );
257         if ( testSequenceDbWsTools1() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Hmmscan output parser: " );
266         if ( testHmmscanOutputParser() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Overlap removal: " );
275         if ( !org.forester.test.Test.testOverlapRemoval() ) {
276             System.out.println( "failed." );
277             failed++;
278         }
279         else {
280             succeeded++;
281         }
282         System.out.println( "OK." );
283         System.out.print( "Engulfing overlap removal: " );
284         if ( !Test.testEngulfingOverlapRemoval() ) {
285             System.out.println( "failed." );
286             failed++;
287         }
288         else {
289             succeeded++;
290         }
291         System.out.println( "OK." );
292         System.out.print( "Taxonomy data extraction: " );
293         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
294             System.out.println( "OK." );
295             succeeded++;
296         }
297         else {
298             System.out.println( "failed." );
299             failed++;
300         }
301         System.out.print( "Taxonomy code extraction: " );
302         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "SN extraction: " );
311         if ( Test.testExtractSNFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy extraction (general): " );
320         if ( Test.testTaxonomyExtraction() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Uri for Aptx web sequence accession: " );
329         if ( Test.testCreateUriForSeqWeb() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Basic node construction and parsing of NHX (node level): " );
338         if ( Test.testNHXNodeParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing iterating: " );
347         if ( Test.testNHParsingIter() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NH parsing: " );
356         if ( Test.testNHParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Conversion to NHX (node level): " );
365         if ( Test.testNHXconversion() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NHX parsing: " );
374         if ( Test.testNHXParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing with quotes: " );
383         if ( Test.testNHXParsingQuotes() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing (MrBayes): " );
392         if ( Test.testNHXParsingMB() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus characters parsing: " );
401         if ( Test.testNexusCharactersParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus tree parsing iterating: " );
410         if ( Test.testNexusTreeParsingIterating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus tree parsing: " );
419         if ( Test.testNexusTreeParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing (translating): " );
428         if ( Test.testNexusTreeParsingTranslating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus matrix parsing: " );
437         if ( Test.testNexusMatrixParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Basic phyloXML parsing: " );
446         if ( Test.testBasicPhyloXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic phyloXML parsing (validating against schema): " );
455         if ( testBasicPhyloXMLparsingValidating() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
464         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "phyloXML Distribution Element: " );
473         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Tol XML parsing: " );
482         if ( Test.testBasicTolXMLparsing() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Copying of node data: " );
491         if ( Test.testCopyOfNodeData() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tree copy: " );
500         if ( Test.testTreeCopy() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Basic tree methods: " );
509         if ( Test.testBasicTreeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree methods: " );
518         if ( Test.testTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Postorder Iterator: " );
527         if ( Test.testPostOrderIterator() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Preorder Iterator: " );
536         if ( Test.testPreOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Levelorder Iterator: " );
545         if ( Test.testLevelOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Re-id methods: " );
554         if ( Test.testReIdMethods() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Methods on last external nodes: " );
563         if ( Test.testLastExternalNodeMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on external nodes: " );
572         if ( Test.testExternalNodeRelatedMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Deletion of external nodes: " );
581         if ( Test.testDeletionOfExternalNodes() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Subtree deletion: " );
590         if ( Test.testSubtreeDeletion() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Phylogeny branch: " );
599         if ( Test.testPhylogenyBranch() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Rerooting: " );
608         if ( Test.testRerooting() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Mipoint rooting: " );
617         if ( Test.testMidpointrooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Node removal: " );
626         if ( Test.testNodeRemoval() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Support count: " );
635         if ( Test.testSupportCount() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support transfer: " );
644         if ( Test.testSupportTransfer() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Finding of LCA: " );
653         if ( Test.testGetLCA() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Finding of LCA 2: " );
662         if ( Test.testGetLCA2() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Calculation of distance between nodes: " );
671         if ( Test.testGetDistance() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Descriptive statistics: " );
680         if ( Test.testDescriptiveStatistics() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Data objects and methods: " );
689         if ( Test.testDataObjects() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Properties map: " );
698         if ( Test.testPropertiesMap() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "SDIse: " );
707         if ( Test.testSDIse() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIunrooted: " );
716         if ( Test.testSDIunrooted() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "GSDI: " );
725         if ( TestGSDI.test() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "RIO: " );
734         if ( TestRIO.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Phylogeny reconstruction:" );
743         System.out.println();
744         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "Analysis of domain architectures: " );
753         System.out.println();
754         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "GO: " );
763         System.out.println();
764         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Modeling tools: " );
773         if ( TestPccx.test() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Split Matrix strict: " );
782         if ( Test.testSplitStrict() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix: " );
791         if ( Test.testSplit() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Confidence Assessor: " );
800         if ( Test.testConfidenceAssessor() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Basic table: " );
809         if ( Test.testBasicTable() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "General table: " );
818         if ( Test.testGeneralTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Amino acid sequence: " );
827         if ( Test.testAminoAcidSequence() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General MSA parser: " );
836         if ( Test.testGeneralMsaParser() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Fasta parser for msa: " );
845         if ( Test.testFastaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Creation of balanced phylogeny: " );
854         if ( Test.testCreateBalancedPhylogeny() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Genbank accessor parsing: " );
863         if ( Test.testGenbankAccessorParsing() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         String path = "";
872         final String os = ForesterUtil.OS_NAME.toLowerCase();
873         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
874             path = "/usr/local/bin/mafft";
875         }
876         else if ( os.indexOf( "win" ) >= 0 ) {
877             path = "C:\\Program Files\\mafft-win\\mafft.bat";
878         }
879         else {
880             path = "mafft";
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/bin/mafft";
883             }
884             if ( !MsaInferrer.isInstalled( path ) ) {
885                 path = "/usr/local/bin/mafft";
886             }
887         }
888         if ( MsaInferrer.isInstalled( path ) ) {
889             System.out.print( "MAFFT (external program): " );
890             if ( Test.testMafft( path ) ) {
891                 System.out.println( "OK." );
892                 succeeded++;
893             }
894             else {
895                 System.out.println( "failed [will not count towards failed tests]" );
896             }
897         }
898         System.out.print( "Next nodes with collapsed: " );
899         if ( Test.testNextNodeWithCollapsing() ) {
900             System.out.println( "OK." );
901             succeeded++;
902         }
903         else {
904             System.out.println( "failed." );
905             failed++;
906         }
907         System.out.print( "Simple MSA quality: " );
908         if ( Test.testMsaQualityMethod() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Deleteable MSA: " );
917         if ( Test.testDeleteableMsa() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         System.out.print( "MSA entropy: " );
926         if ( Test.testMsaEntropy() ) {
927             System.out.println( "OK." );
928             succeeded++;
929         }
930         else {
931             System.out.println( "failed." );
932             failed++;
933         }
934         if ( PERFORM_DB_TESTS ) {
935             System.out.print( "Uniprot Entry Retrieval: " );
936             if ( Test.testUniprotEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Ebi Entry Retrieval: " );
945             if ( Test.testEbiEntryRetrieval() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953             System.out.print( "Sequence DB tools 2: " );
954             if ( testSequenceDbWsTools2() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961                 System.exit( -1 );
962             }
963             System.out.print( "Uniprot Taxonomy Search: " );
964             if ( Test.testUniprotTaxonomySearch() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972         }
973         if ( PERFORM_WEB_TREE_ACCESS ) {
974             System.out.print( "NHX parsing from URL: " );
975             if ( Test.testNHXparsingFromURL() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "NHX parsing from URL 2: " );
984             if ( Test.testNHXparsingFromURL2() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             System.out.print( "phyloXML parsing from URL: " );
993             if ( Test.testPhyloXMLparsingFromURL() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             System.out.print( "TreeBase acccess: " );
1002             if ( Test.testTreeBaseReading() ) {
1003                 System.out.println( "OK." );
1004                 succeeded++;
1005             }
1006             else {
1007                 System.out.println( "failed." );
1008                 failed++;
1009             }
1010             //
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             //
1021             System.out.print( "TreeFam access: " );
1022             if ( Test.testTreeFamReading() ) {
1023                 System.out.println( "OK." );
1024                 succeeded++;
1025             }
1026             else {
1027                 System.out.println( "failed." );
1028                 failed++;
1029             }
1030             //
1031             //
1032             System.out.print( "Pfam tree access: " );
1033             if ( Test.testPfamTreeReading() ) {
1034                 System.out.println( "OK." );
1035                 succeeded++;
1036             }
1037             else {
1038                 System.out.println( "failed." );
1039                 failed++;
1040             }
1041         }
1042         System.out.println();
1043         final Runtime rt = java.lang.Runtime.getRuntime();
1044         final long free_memory = rt.freeMemory() / 1000000;
1045         final long total_memory = rt.totalMemory() / 1000000;
1046         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1047                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1048         System.out.println();
1049         System.out.println( "Successful tests: " + succeeded );
1050         System.out.println( "Failed     tests: " + failed );
1051         System.out.println();
1052         if ( failed < 1 ) {
1053             System.out.println( "OK." );
1054         }
1055         else {
1056             System.out.println( "Not OK." );
1057         }
1058     }
1059
1060     public static boolean testEngulfingOverlapRemoval() {
1061         try {
1062             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1063             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1064             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1065             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1067             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1068             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1069             final List<Boolean> covered = new ArrayList<Boolean>();
1070             covered.add( true ); // 0
1071             covered.add( false ); // 1
1072             covered.add( true ); // 2
1073             covered.add( false ); // 3
1074             covered.add( true ); // 4
1075             covered.add( true ); // 5
1076             covered.add( false ); // 6
1077             covered.add( true ); // 7
1078             covered.add( true ); // 8
1079             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1086                 return false;
1087             }
1088             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1089                 return false;
1090             }
1091             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1092                 return false;
1093             }
1094             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1095                 return false;
1096             }
1097             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1098                 return false;
1099             }
1100             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1101             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1102             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1103             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1104             abc.addProteinDomain( a );
1105             abc.addProteinDomain( b );
1106             abc.addProteinDomain( c );
1107             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1108             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1109             if ( abc.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1113                 return false;
1114             }
1115             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1116                 return false;
1117             }
1118             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1119                 return false;
1120             }
1121             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1122                 return false;
1123             }
1124             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1126             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1127             final Protein def = new BasicProtein( "def", "nemve", 0 );
1128             def.addProteinDomain( d );
1129             def.addProteinDomain( e );
1130             def.addProteinDomain( f );
1131             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1132             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1133             if ( def.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1140                 return false;
1141             }
1142             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1146                 return false;
1147             }
1148             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1149                 return false;
1150             }
1151         }
1152         catch ( final Exception e ) {
1153             e.printStackTrace( System.out );
1154             return false;
1155         }
1156         return true;
1157     }
1158
1159     public static final boolean testNHXparsingFromURL2() {
1160         try {
1161             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1162             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1163                                                                       false,
1164                                                                       false,
1165                                                                       false,
1166                                                                       TAXONOMY_EXTRACTION.NO,
1167                                                                       false );
1168             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1169                 return false;
1170             }
1171             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1172                 System.out.println( phys[ 0 ].toNewHampshire() );
1173                 return false;
1174             }
1175             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1176                 System.out.println( phys[ 1 ].toNewHampshire() );
1177                 return false;
1178             }
1179             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1180                                                                        false,
1181                                                                        false,
1182                                                                        false,
1183                                                                        TAXONOMY_EXTRACTION.NO,
1184                                                                        false );
1185             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1186                 return false;
1187             }
1188             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1189                 System.out.println( phys2[ 0 ].toNewHampshire() );
1190                 return false;
1191             }
1192             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1193                 System.out.println( phys2[ 1 ].toNewHampshire() );
1194                 return false;
1195             }
1196             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1197                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1198             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1199                 return false;
1200             }
1201             if ( !phys3[ 0 ]
1202                     .toNewHampshire()
1203                     .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))))));" ) ) {
1204                 System.out.println( phys3[ 0 ].toNewHampshire() );
1205                 return false;
1206             }
1207             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1208                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1209             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1210                 return false;
1211             }
1212             if ( !phys4[ 0 ]
1213                     .toNewHampshire()
1214                     .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))))));" ) ) {
1215                 System.out.println( phys4[ 0 ].toNewHampshire() );
1216                 return false;
1217             }
1218         }
1219         catch ( final Exception e ) {
1220             e.printStackTrace();
1221             return false;
1222         }
1223         return true;
1224     }
1225
1226     public static final boolean testNHXparsingFromURL() {
1227         try {
1228             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1229             final URL u = new URL( s );
1230             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1231             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1232             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1233                 return false;
1234             }
1235             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1236                 System.out.println( phys[ 0 ].toNewHampshire() );
1237                 return false;
1238             }
1239             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1240                 System.out.println( phys[ 1 ].toNewHampshire() );
1241                 return false;
1242             }
1243             final URL u2 = new URL( s );
1244             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1245             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1246                 return false;
1247             }
1248             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1249                 System.out.println( phys2[ 0 ].toNewHampshire() );
1250                 return false;
1251             }
1252             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1253             final NHXParser p = new NHXParser();
1254             final URL u3 = new URL( s );
1255             p.setSource( u3 );
1256             if ( !p.hasNext() ) {
1257                 return false;
1258             }
1259             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1260                 return false;
1261             }
1262             if ( !p.hasNext() ) {
1263                 return false;
1264             }
1265             p.reset();
1266             if ( !p.hasNext() ) {
1267                 return false;
1268             }
1269             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1270                 return false;
1271             }
1272             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1273                 return false;
1274             }
1275             p.reset();
1276             if ( !p.hasNext() ) {
1277                 return false;
1278             }
1279             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1280                 return false;
1281             }
1282             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1283                 return false;
1284             }
1285         }
1286         catch ( final Exception e ) {
1287             System.out.println( e.toString() );
1288             e.printStackTrace();
1289             return false;
1290         }
1291         return true;
1292     }
1293
1294     public static boolean testOverlapRemoval() {
1295         try {
1296             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1297             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1298             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1299             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1300             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1301             final List<Boolean> covered = new ArrayList<Boolean>();
1302             covered.add( true ); // 0
1303             covered.add( false ); // 1
1304             covered.add( true ); // 2
1305             covered.add( false ); // 3
1306             covered.add( true ); // 4
1307             covered.add( true ); // 5
1308             covered.add( false ); // 6
1309             covered.add( true ); // 7
1310             covered.add( true ); // 8
1311             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1312                 return false;
1313             }
1314             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1315                 return false;
1316             }
1317             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1318                 return false;
1319             }
1320             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1321                 return false;
1322             }
1323             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1324                 return false;
1325             }
1326             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1327             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1328             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1329             ab.addProteinDomain( a );
1330             ab.addProteinDomain( b );
1331             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1332             if ( ab.getNumberOfProteinDomains() != 2 ) {
1333                 return false;
1334             }
1335             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1336                 return false;
1337             }
1338             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1339                 return false;
1340             }
1341             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1342             if ( ab.getNumberOfProteinDomains() != 2 ) {
1343                 return false;
1344             }
1345             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1346                 return false;
1347             }
1348             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1349             final Domain d = new BasicDomain( "d",
1350                                               ( short ) 10000,
1351                                               ( short ) 10500,
1352                                               ( short ) 1,
1353                                               ( short ) 1,
1354                                               0.0000001,
1355                                               1 );
1356             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1357             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1358             cde.addProteinDomain( c );
1359             cde.addProteinDomain( d );
1360             cde.addProteinDomain( e );
1361             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1362             if ( cde.getNumberOfProteinDomains() != 3 ) {
1363                 return false;
1364             }
1365             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1366                 return false;
1367             }
1368             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1369             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1370             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1371             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1372             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1373             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1374             fghi.addProteinDomain( f );
1375             fghi.addProteinDomain( g );
1376             fghi.addProteinDomain( h );
1377             fghi.addProteinDomain( i );
1378             fghi.addProteinDomain( i );
1379             fghi.addProteinDomain( i );
1380             fghi.addProteinDomain( i2 );
1381             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1382             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1383                 return false;
1384             }
1385             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1386                 return false;
1387             }
1388             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1389                 return false;
1390             }
1391             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1392             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1393                 return false;
1394             }
1395             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1396                 return false;
1397             }
1398             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1399             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1400             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1401             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1402             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1403             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1404             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1405             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1406             jklm.addProteinDomain( j );
1407             jklm.addProteinDomain( k );
1408             jklm.addProteinDomain( l );
1409             jklm.addProteinDomain( m );
1410             jklm.addProteinDomain( m0 );
1411             jklm.addProteinDomain( m1 );
1412             jklm.addProteinDomain( m2 );
1413             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1414             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1415                 return false;
1416             }
1417             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1418                 return false;
1419             }
1420             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1421                 return false;
1422             }
1423             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1424             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1425                 return false;
1426             }
1427             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1428                 return false;
1429             }
1430             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1431             final Protein od = new BasicProtein( "od", "varanus", 0 );
1432             od.addProteinDomain( only );
1433             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1434             if ( od.getNumberOfProteinDomains() != 1 ) {
1435                 return false;
1436             }
1437             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace( System.out );
1443             return false;
1444         }
1445         return true;
1446     }
1447
1448     public static final boolean testPfamTreeReading() {
1449         try {
1450             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1451             final NHXParser parser = new NHXParser();
1452             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1453             parser.setReplaceUnderscores( false );
1454             parser.setGuessRootedness( true );
1455             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1456             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1457             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1458                 return false;
1459             }
1460             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1461                 return false;
1462             }
1463         }
1464         catch ( final Exception e ) {
1465             e.printStackTrace();
1466         }
1467         return true;
1468     }
1469
1470     public static final boolean testPhyloXMLparsingFromURL() {
1471         try {
1472             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1473             final URL u = new URL( s );
1474             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1475             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1476             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1477                 return false;
1478             }
1479         }
1480         catch ( final Exception e ) {
1481             e.printStackTrace();
1482         }
1483         return true;
1484     }
1485
1486     public static final boolean testToLReading() {
1487         try {
1488             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1489             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1490             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1491             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1492                 return false;
1493             }
1494             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1495                 return false;
1496             }
1497             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1498                 return false;
1499             }
1500             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1501                 return false;
1502             }
1503         }
1504         catch ( final Exception e ) {
1505             e.printStackTrace();
1506         }
1507         return true;
1508     }
1509
1510     public static final boolean testTreeBaseReading() {
1511         try {
1512             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1513             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1514             parser.setReplaceUnderscores( true );
1515             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1516             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1517             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1518                 return false;
1519             }
1520             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1521             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1522             parser2.setReplaceUnderscores( true );
1523             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1524             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1525             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1526                 return false;
1527             }
1528         }
1529         catch ( final Exception e ) {
1530             e.printStackTrace();
1531         }
1532         return true;
1533     }
1534
1535     public static final boolean testTreeFamReading() {
1536         try {
1537             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1538             final NHXParser parser = new NHXParser();
1539             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1540             parser.setReplaceUnderscores( false );
1541             parser.setGuessRootedness( true );
1542             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1543             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1544             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1545                 return false;
1546             }
1547             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1548                 return false;
1549             }
1550         }
1551         catch ( final Exception e ) {
1552             e.printStackTrace();
1553         }
1554         return true;
1555     }
1556
1557     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1558         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1559         return p;
1560     }
1561
1562     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1563         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1564     }
1565
1566     private static boolean testAminoAcidSequence() {
1567         try {
1568             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1569             if ( aa1.getLength() != 13 ) {
1570                 return false;
1571             }
1572             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1573                 return false;
1574             }
1575             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1576                 return false;
1577             }
1578             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1579                 return false;
1580             }
1581             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1582             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1583                 return false;
1584             }
1585             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1586             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1587                 return false;
1588             }
1589             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1590             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1591                 return false;
1592             }
1593         }
1594         catch ( final Exception e ) {
1595             e.printStackTrace();
1596             return false;
1597         }
1598         return true;
1599     }
1600
1601     private static boolean testBasicDomain() {
1602         try {
1603             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1604             if ( !pd.getDomainId().equals( "id" ) ) {
1605                 return false;
1606             }
1607             if ( pd.getNumber() != 1 ) {
1608                 return false;
1609             }
1610             if ( pd.getTotalCount() != 4 ) {
1611                 return false;
1612             }
1613             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1614                 return false;
1615             }
1616             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1617             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1618             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1619             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1620             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1621             if ( !a1.equals( a1 ) ) {
1622                 return false;
1623             }
1624             if ( !a1.equals( a1_copy ) ) {
1625                 return false;
1626             }
1627             if ( !a1.equals( a1_equal ) ) {
1628                 return false;
1629             }
1630             if ( !a1.equals( a2 ) ) {
1631                 return false;
1632             }
1633             if ( a1.equals( a3 ) ) {
1634                 return false;
1635             }
1636             if ( a1.compareTo( a1 ) != 0 ) {
1637                 return false;
1638             }
1639             if ( a1.compareTo( a1_copy ) != 0 ) {
1640                 return false;
1641             }
1642             if ( a1.compareTo( a1_equal ) != 0 ) {
1643                 return false;
1644             }
1645             if ( a1.compareTo( a2 ) != 0 ) {
1646                 return false;
1647             }
1648             if ( a1.compareTo( a3 ) == 0 ) {
1649                 return false;
1650             }
1651         }
1652         catch ( final Exception e ) {
1653             e.printStackTrace( System.out );
1654             return false;
1655         }
1656         return true;
1657     }
1658
1659     private static boolean testBasicNodeMethods() {
1660         try {
1661             if ( PhylogenyNode.getNodeCount() != 0 ) {
1662                 return false;
1663             }
1664             final PhylogenyNode n1 = new PhylogenyNode();
1665             final PhylogenyNode n2 = PhylogenyNode
1666                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1667             final PhylogenyNode n3 = PhylogenyNode
1668                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1669             final PhylogenyNode n4 = PhylogenyNode
1670                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1671             if ( n1.isHasAssignedEvent() ) {
1672                 return false;
1673             }
1674             if ( PhylogenyNode.getNodeCount() != 4 ) {
1675                 return false;
1676             }
1677             if ( n3.getIndicator() != 0 ) {
1678                 return false;
1679             }
1680             if ( n3.getNumberOfExternalNodes() != 1 ) {
1681                 return false;
1682             }
1683             if ( !n3.isExternal() ) {
1684                 return false;
1685             }
1686             if ( !n3.isRoot() ) {
1687                 return false;
1688             }
1689             if ( !n4.getName().equals( "n4" ) ) {
1690                 return false;
1691             }
1692         }
1693         catch ( final Exception e ) {
1694             e.printStackTrace( System.out );
1695             return false;
1696         }
1697         return true;
1698     }
1699
1700     private static boolean testBasicPhyloXMLparsing() {
1701         try {
1702             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1703             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1704             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1705                                                               xml_parser );
1706             if ( xml_parser.getErrorCount() > 0 ) {
1707                 System.out.println( xml_parser.getErrorMessages().toString() );
1708                 return false;
1709             }
1710             if ( phylogenies_0.length != 4 ) {
1711                 return false;
1712             }
1713             final Phylogeny t1 = phylogenies_0[ 0 ];
1714             final Phylogeny t2 = phylogenies_0[ 1 ];
1715             final Phylogeny t3 = phylogenies_0[ 2 ];
1716             final Phylogeny t4 = phylogenies_0[ 3 ];
1717             if ( t1.getNumberOfExternalNodes() != 1 ) {
1718                 return false;
1719             }
1720             if ( !t1.isRooted() ) {
1721                 return false;
1722             }
1723             if ( t1.isRerootable() ) {
1724                 return false;
1725             }
1726             if ( !t1.getType().equals( "gene_tree" ) ) {
1727                 return false;
1728             }
1729             if ( t2.getNumberOfExternalNodes() != 2 ) {
1730                 return false;
1731             }
1732             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1733                 return false;
1734             }
1735             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1736                 return false;
1737             }
1738             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1739                 return false;
1740             }
1741             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1742                 return false;
1743             }
1744             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1745                 return false;
1746             }
1747             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1748                 return false;
1749             }
1750             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1751                     .startsWith( "actgtgggggt" ) ) {
1752                 return false;
1753             }
1754             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1755                     .startsWith( "ctgtgatgcat" ) ) {
1756                 return false;
1757             }
1758             if ( t3.getNumberOfExternalNodes() != 4 ) {
1759                 return false;
1760             }
1761             if ( !t1.getName().equals( "t1" ) ) {
1762                 return false;
1763             }
1764             if ( !t2.getName().equals( "t2" ) ) {
1765                 return false;
1766             }
1767             if ( !t3.getName().equals( "t3" ) ) {
1768                 return false;
1769             }
1770             if ( !t4.getName().equals( "t4" ) ) {
1771                 return false;
1772             }
1773             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1774                 return false;
1775             }
1776             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1777                 return false;
1778             }
1779             if ( !t3.getNode( "root node" ).isDuplication() ) {
1780                 return false;
1781             }
1782             if ( !t3.getNode( "node a" ).isDuplication() ) {
1783                 return false;
1784             }
1785             if ( t3.getNode( "node a" ).isSpeciation() ) {
1786                 return false;
1787             }
1788             if ( t3.getNode( "node bc" ).isDuplication() ) {
1789                 return false;
1790             }
1791             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
1792                 return false;
1793             }
1794             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1795                 return false;
1796             }
1797             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1798                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1799                 return false;
1800             }
1801             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1802                 return false;
1803             }
1804             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1805                 return false;
1806             }
1807             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1808                 return false;
1809             }
1810             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1811                     .equals( "apoptosis" ) ) {
1812                 return false;
1813             }
1814             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1815                     .equals( "GO:0006915" ) ) {
1816                 return false;
1817             }
1818             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1819                     .equals( "UniProtKB" ) ) {
1820                 return false;
1821             }
1822             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1823                     .equals( "experimental" ) ) {
1824                 return false;
1825             }
1826             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1827                     .equals( "function" ) ) {
1828                 return false;
1829             }
1830             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1831                     .getValue() != 1 ) {
1832                 return false;
1833             }
1834             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1835                     .getType().equals( "ml" ) ) {
1836                 return false;
1837             }
1838             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1839                     .equals( "apoptosis" ) ) {
1840                 return false;
1841             }
1842             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1843                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1844                 return false;
1845             }
1846             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1847                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1848                 return false;
1849             }
1850             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1851                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1852                 return false;
1853             }
1854             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1855                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1856                 return false;
1857             }
1858             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1859                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1860                 return false;
1861             }
1862             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1863                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1864                 return false;
1865             }
1866             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1867                     .equals( "GO:0005829" ) ) {
1868                 return false;
1869             }
1870             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1871                     .equals( "intracellular organelle" ) ) {
1872                 return false;
1873             }
1874             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1875                 return false;
1876             }
1877             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1878                     .equals( "UniProt link" ) ) ) {
1879                 return false;
1880             }
1881             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1882                 return false;
1883             }
1884             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1885             if ( x.size() != 4 ) {
1886                 return false;
1887             }
1888             int c = 0;
1889             for( final Accession acc : x ) {
1890                 if ( c == 0 ) {
1891                     if ( !acc.getSource().equals( "KEGG" ) ) {
1892                         return false;
1893                     }
1894                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1895                         return false;
1896                     }
1897                 }
1898                 c++;
1899             }
1900         }
1901         catch ( final Exception e ) {
1902             e.printStackTrace( System.out );
1903             return false;
1904         }
1905         return true;
1906     }
1907
1908     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1909         try {
1910             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1911             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1912             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1913                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1914             }
1915             else {
1916                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1917             }
1918             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1919                                                               xml_parser );
1920             if ( xml_parser.getErrorCount() > 0 ) {
1921                 System.out.println( xml_parser.getErrorMessages().toString() );
1922                 return false;
1923             }
1924             if ( phylogenies_0.length != 4 ) {
1925                 return false;
1926             }
1927             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1928             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1929             if ( phylogenies_t1.length != 1 ) {
1930                 return false;
1931             }
1932             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1933             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1934                 return false;
1935             }
1936             if ( !t1_rt.isRooted() ) {
1937                 return false;
1938             }
1939             if ( t1_rt.isRerootable() ) {
1940                 return false;
1941             }
1942             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1943                 return false;
1944             }
1945             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1946             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1947             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1948             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1949                 return false;
1950             }
1951             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1952                 return false;
1953             }
1954             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1955                 return false;
1956             }
1957             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1958                 return false;
1959             }
1960             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1961                     .startsWith( "actgtgggggt" ) ) {
1962                 return false;
1963             }
1964             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1965                     .startsWith( "ctgtgatgcat" ) ) {
1966                 return false;
1967             }
1968             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1969             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1970             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1971             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1972             if ( phylogenies_1.length != 1 ) {
1973                 return false;
1974             }
1975             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1976             if ( !t3_rt.getName().equals( "t3" ) ) {
1977                 return false;
1978             }
1979             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1980                 return false;
1981             }
1982             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1983                 return false;
1984             }
1985             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1986                 return false;
1987             }
1988             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1989                 return false;
1990             }
1991             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1992                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1993                 return false;
1994             }
1995             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1996                 return false;
1997             }
1998             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1999                 return false;
2000             }
2001             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2002                     .equals( "UniProtKB" ) ) {
2003                 return false;
2004             }
2005             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2006                     .equals( "apoptosis" ) ) {
2007                 return false;
2008             }
2009             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2010                     .equals( "GO:0006915" ) ) {
2011                 return false;
2012             }
2013             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2014                     .equals( "UniProtKB" ) ) {
2015                 return false;
2016             }
2017             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2018                     .equals( "experimental" ) ) {
2019                 return false;
2020             }
2021             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2022                     .equals( "function" ) ) {
2023                 return false;
2024             }
2025             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2026                     .getValue() != 1 ) {
2027                 return false;
2028             }
2029             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2030                     .getType().equals( "ml" ) ) {
2031                 return false;
2032             }
2033             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2034                     .equals( "apoptosis" ) ) {
2035                 return false;
2036             }
2037             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2038                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2039                 return false;
2040             }
2041             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2042                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2043                 return false;
2044             }
2045             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2046                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2047                 return false;
2048             }
2049             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2050                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2051                 return false;
2052             }
2053             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2054                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2055                 return false;
2056             }
2057             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2058                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2059                 return false;
2060             }
2061             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2062                     .equals( "GO:0005829" ) ) {
2063                 return false;
2064             }
2065             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2066                     .equals( "intracellular organelle" ) ) {
2067                 return false;
2068             }
2069             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2070                 return false;
2071             }
2072             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2073                     .equals( "UniProt link" ) ) ) {
2074                 return false;
2075             }
2076             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2077                 return false;
2078             }
2079             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2080                 return false;
2081             }
2082             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2083                     .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." ) ) ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2087                 return false;
2088             }
2089             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2090                 return false;
2091             }
2092             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2096                 return false;
2097             }
2098             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2099                     .equals( "ncbi" ) ) {
2100                 return false;
2101             }
2102             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2103                 return false;
2104             }
2105             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2106                     .getName().equals( "B" ) ) {
2107                 return false;
2108             }
2109             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2110                     .getFrom() != 21 ) {
2111                 return false;
2112             }
2113             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2114                 return false;
2115             }
2116             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2117                     .getLength() != 24 ) {
2118                 return false;
2119             }
2120             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2121                     .getConfidence() != 0 ) {
2122                 return false;
2123             }
2124             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2125                     .equals( "pfam" ) ) {
2126                 return false;
2127             }
2128             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2129                 return false;
2130             }
2131             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2132                 return false;
2133             }
2134             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2135                 return false;
2136             }
2137             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2138                 return false;
2139             }
2140             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2141             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2142                 return false;
2143             }
2144             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2145                 return false;
2146             }
2147             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2148                 return false;
2149             }
2150             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2151                 return false;
2152             }
2153             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2154                 return false;
2155             }
2156             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2157                 return false;
2158             }
2159             if ( taxbb.getSynonyms().size() != 2 ) {
2160                 return false;
2161             }
2162             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2163                 return false;
2164             }
2165             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2166                 return false;
2167             }
2168             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2169                 return false;
2170             }
2171             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2172                 return false;
2173             }
2174             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2175                 return false;
2176             }
2177             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2178                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2179                 return false;
2180             }
2181             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2182                 return false;
2183             }
2184             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2185                 return false;
2186             }
2187             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2188                 return false;
2189             }
2190             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2191                 return false;
2192             }
2193             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2194                 return false;
2195             }
2196             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2197                 return false;
2198             }
2199             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2200                 return false;
2201             }
2202             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2203                 return false;
2204             }
2205             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2206                     .equalsIgnoreCase( "435" ) ) {
2207                 return false;
2208             }
2209             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2210                 return false;
2211             }
2212             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2213                     .equalsIgnoreCase( "443.7" ) ) {
2214                 return false;
2215             }
2216             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2217                 return false;
2218             }
2219             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2220                 return false;
2221             }
2222             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2223                     .equalsIgnoreCase( "433" ) ) {
2224                 return false;
2225             }
2226             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2227                     .getCrossReferences();
2228             if ( x.size() != 4 ) {
2229                 return false;
2230             }
2231             int c = 0;
2232             for( final Accession acc : x ) {
2233                 if ( c == 0 ) {
2234                     if ( !acc.getSource().equals( "KEGG" ) ) {
2235                         return false;
2236                     }
2237                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2238                         return false;
2239                     }
2240                 }
2241                 c++;
2242             }
2243         }
2244         catch ( final Exception e ) {
2245             e.printStackTrace( System.out );
2246             return false;
2247         }
2248         return true;
2249     }
2250
2251     private static boolean testBasicPhyloXMLparsingValidating() {
2252         try {
2253             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2254             PhyloXmlParser xml_parser = null;
2255             try {
2256                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2257             }
2258             catch ( final Exception e ) {
2259                 // Do nothing -- means were not running from jar.
2260             }
2261             if ( xml_parser == null ) {
2262                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2263                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2264                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2265                 }
2266                 else {
2267                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2268                 }
2269             }
2270             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2271                                                               xml_parser );
2272             if ( xml_parser.getErrorCount() > 0 ) {
2273                 System.out.println( xml_parser.getErrorMessages().toString() );
2274                 return false;
2275             }
2276             if ( phylogenies_0.length != 4 ) {
2277                 return false;
2278             }
2279             final Phylogeny t1 = phylogenies_0[ 0 ];
2280             final Phylogeny t2 = phylogenies_0[ 1 ];
2281             final Phylogeny t3 = phylogenies_0[ 2 ];
2282             final Phylogeny t4 = phylogenies_0[ 3 ];
2283             if ( !t1.getName().equals( "t1" ) ) {
2284                 return false;
2285             }
2286             if ( !t2.getName().equals( "t2" ) ) {
2287                 return false;
2288             }
2289             if ( !t3.getName().equals( "t3" ) ) {
2290                 return false;
2291             }
2292             if ( !t4.getName().equals( "t4" ) ) {
2293                 return false;
2294             }
2295             if ( t1.getNumberOfExternalNodes() != 1 ) {
2296                 return false;
2297             }
2298             if ( t2.getNumberOfExternalNodes() != 2 ) {
2299                 return false;
2300             }
2301             if ( t3.getNumberOfExternalNodes() != 4 ) {
2302                 return false;
2303             }
2304             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2305             final Phylogeny[] phylogenies_1 = factory.create( x2, 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_1.length != 4 ) {
2312                 return false;
2313             }
2314             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2315                                                               xml_parser );
2316             if ( xml_parser.getErrorCount() > 0 ) {
2317                 System.out.println( "errors:" );
2318                 System.out.println( xml_parser.getErrorMessages().toString() );
2319                 return false;
2320             }
2321             if ( phylogenies_2.length != 1 ) {
2322                 return false;
2323             }
2324             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2325                 return false;
2326             }
2327             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2328                                                               xml_parser );
2329             if ( xml_parser.getErrorCount() > 0 ) {
2330                 System.out.println( xml_parser.getErrorMessages().toString() );
2331                 return false;
2332             }
2333             if ( phylogenies_3.length != 2 ) {
2334                 return false;
2335             }
2336             final Phylogeny a = phylogenies_3[ 0 ];
2337             if ( !a.getName().equals( "tree 4" ) ) {
2338                 return false;
2339             }
2340             if ( a.getNumberOfExternalNodes() != 3 ) {
2341                 return false;
2342             }
2343             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2344                 return false;
2345             }
2346             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2347                 return false;
2348             }
2349             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2350                                                               xml_parser );
2351             if ( xml_parser.getErrorCount() > 0 ) {
2352                 System.out.println( xml_parser.getErrorMessages().toString() );
2353                 return false;
2354             }
2355             if ( phylogenies_4.length != 1 ) {
2356                 return false;
2357             }
2358             final Phylogeny s = phylogenies_4[ 0 ];
2359             if ( s.getNumberOfExternalNodes() != 6 ) {
2360                 return false;
2361             }
2362             s.getNode( "first" );
2363             s.getNode( "<>" );
2364             s.getNode( "\"<a'b&c'd\">\"" );
2365             s.getNode( "'''\"" );
2366             s.getNode( "\"\"\"" );
2367             s.getNode( "dick & doof" );
2368         }
2369         catch ( final Exception e ) {
2370             e.printStackTrace( System.out );
2371             return false;
2372         }
2373         return true;
2374     }
2375
2376     private static boolean testBasicProtein() {
2377         try {
2378             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2379             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2381             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2382             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2383             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2384             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2385             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2386             p0.addProteinDomain( y );
2387             p0.addProteinDomain( e );
2388             p0.addProteinDomain( b );
2389             p0.addProteinDomain( c );
2390             p0.addProteinDomain( d );
2391             p0.addProteinDomain( a );
2392             p0.addProteinDomain( x );
2393             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2394                 return false;
2395             }
2396             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2397                 return false;
2398             }
2399             //
2400             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2401             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2402             aa0.addProteinDomain( a1 );
2403             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2404                 return false;
2405             }
2406             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2407                 return false;
2408             }
2409             //
2410             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2411             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2412             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2413             aa1.addProteinDomain( a11 );
2414             aa1.addProteinDomain( a12 );
2415             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2416                 return false;
2417             }
2418             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2419                 return false;
2420             }
2421             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2422             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2423                 return false;
2424             }
2425             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2426                 return false;
2427             }
2428             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2429                 return false;
2430             }
2431             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2432             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2433                 return false;
2434             }
2435             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2436                 return false;
2437             }
2438             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2439                 return false;
2440             }
2441             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2442                 return false;
2443             }
2444             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2445             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2446                 return false;
2447             }
2448             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2449                 return false;
2450             }
2451             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2452                 return false;
2453             }
2454             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2455                 return false;
2456             }
2457             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2458             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2459                 return false;
2460             }
2461             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2462                 return false;
2463             }
2464             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2465                 return false;
2466             }
2467             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2468                 return false;
2469             }
2470             //
2471             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2472             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2473             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2474             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2475             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2476             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2477             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2478             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2479             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2480             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2481             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2482             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2483             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2484             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2485             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2486             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2487             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2488             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2489             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2490             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2491             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2492             p00.addProteinDomain( y0 );
2493             p00.addProteinDomain( e0 );
2494             p00.addProteinDomain( b0 );
2495             p00.addProteinDomain( c0 );
2496             p00.addProteinDomain( d0 );
2497             p00.addProteinDomain( a0 );
2498             p00.addProteinDomain( x0 );
2499             p00.addProteinDomain( y1 );
2500             p00.addProteinDomain( y2 );
2501             p00.addProteinDomain( y3 );
2502             p00.addProteinDomain( e1 );
2503             p00.addProteinDomain( e2 );
2504             p00.addProteinDomain( e3 );
2505             p00.addProteinDomain( e4 );
2506             p00.addProteinDomain( e5 );
2507             p00.addProteinDomain( z0 );
2508             p00.addProteinDomain( z1 );
2509             p00.addProteinDomain( z2 );
2510             p00.addProteinDomain( zz0 );
2511             p00.addProteinDomain( zz1 );
2512             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2513                 return false;
2514             }
2515             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2516                 return false;
2517             }
2518             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2519                 return false;
2520             }
2521             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2522                 return false;
2523             }
2524             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" ) ) {
2525                 return false;
2526             }
2527             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2528             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2529             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2530             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2531             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2532             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2533             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2534             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2535             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2536             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2537             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2538             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2539             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2540             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2541             p.addProteinDomain( B15 );
2542             p.addProteinDomain( C50 );
2543             p.addProteinDomain( A60 );
2544             p.addProteinDomain( A30 );
2545             p.addProteinDomain( C70 );
2546             p.addProteinDomain( B35 );
2547             p.addProteinDomain( B40 );
2548             p.addProteinDomain( A0 );
2549             p.addProteinDomain( A10 );
2550             p.addProteinDomain( A20 );
2551             p.addProteinDomain( B25 );
2552             p.addProteinDomain( D80 );
2553             List<String> domains_ids = new ArrayList<String>();
2554             domains_ids.add( "A" );
2555             domains_ids.add( "B" );
2556             domains_ids.add( "C" );
2557             if ( !p.contains( domains_ids, false ) ) {
2558                 return false;
2559             }
2560             if ( !p.contains( domains_ids, true ) ) {
2561                 return false;
2562             }
2563             domains_ids.add( "X" );
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( "C" );
2573             domains_ids.add( "D" );
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( "D" );
2583             domains_ids.add( "C" );
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( "B" );
2594             if ( !p.contains( domains_ids, false ) ) {
2595                 return false;
2596             }
2597             if ( !p.contains( domains_ids, true ) ) {
2598                 return false;
2599             }
2600             domains_ids = new ArrayList<String>();
2601             domains_ids.add( "A" );
2602             domains_ids.add( "A" );
2603             domains_ids.add( "A" );
2604             domains_ids.add( "B" );
2605             domains_ids.add( "B" );
2606             if ( !p.contains( domains_ids, false ) ) {
2607                 return false;
2608             }
2609             if ( !p.contains( domains_ids, true ) ) {
2610                 return false;
2611             }
2612             domains_ids = new ArrayList<String>();
2613             domains_ids.add( "A" );
2614             domains_ids.add( "A" );
2615             domains_ids.add( "B" );
2616             domains_ids.add( "A" );
2617             domains_ids.add( "B" );
2618             domains_ids.add( "B" );
2619             domains_ids.add( "A" );
2620             domains_ids.add( "B" );
2621             domains_ids.add( "C" );
2622             domains_ids.add( "A" );
2623             domains_ids.add( "C" );
2624             domains_ids.add( "D" );
2625             if ( !p.contains( domains_ids, false ) ) {
2626                 return false;
2627             }
2628             if ( p.contains( domains_ids, true ) ) {
2629                 return false;
2630             }
2631         }
2632         catch ( final Exception e ) {
2633             e.printStackTrace( System.out );
2634             return false;
2635         }
2636         return true;
2637     }
2638
2639     private static boolean testBasicTable() {
2640         try {
2641             final BasicTable<String> t0 = new BasicTable<String>();
2642             if ( t0.getNumberOfColumns() != 0 ) {
2643                 return false;
2644             }
2645             if ( t0.getNumberOfRows() != 0 ) {
2646                 return false;
2647             }
2648             t0.setValue( 3, 2, "23" );
2649             t0.setValue( 10, 1, "error" );
2650             t0.setValue( 10, 1, "110" );
2651             t0.setValue( 9, 1, "19" );
2652             t0.setValue( 1, 10, "101" );
2653             t0.setValue( 10, 10, "1010" );
2654             t0.setValue( 100, 10, "10100" );
2655             t0.setValue( 0, 0, "00" );
2656             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2657                 return false;
2658             }
2659             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2660                 return false;
2661             }
2662             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2663                 return false;
2664             }
2665             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2666                 return false;
2667             }
2668             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2669                 return false;
2670             }
2671             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2672                 return false;
2673             }
2674             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2675                 return false;
2676             }
2677             if ( t0.getNumberOfColumns() != 101 ) {
2678                 return false;
2679             }
2680             if ( t0.getNumberOfRows() != 11 ) {
2681                 return false;
2682             }
2683             if ( t0.getValueAsString( 49, 4 ) != null ) {
2684                 return false;
2685             }
2686             final String l = ForesterUtil.getLineSeparator();
2687             final StringBuffer source = new StringBuffer();
2688             source.append( "" + l );
2689             source.append( "# 1 1 1 1 1 1 1 1" + l );
2690             source.append( " 00 01 02 03" + l );
2691             source.append( "   10 11 12 13  " + l );
2692             source.append( "20 21 22 23 " + l );
2693             source.append( "    30  31    32 33" + l );
2694             source.append( "40 41 42 43" + l );
2695             source.append( "  # 1 1 1 1 1 " + l );
2696             source.append( "50 51 52 53 54" + l );
2697             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2698             if ( t1.getNumberOfColumns() != 5 ) {
2699                 return false;
2700             }
2701             if ( t1.getNumberOfRows() != 6 ) {
2702                 return false;
2703             }
2704             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2705                 return false;
2706             }
2707             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2708                 return false;
2709             }
2710             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2711                 return false;
2712             }
2713             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2714                 return false;
2715             }
2716             final StringBuffer source1 = new StringBuffer();
2717             source1.append( "" + l );
2718             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2719             source1.append( " 00; 01 ;02;03" + l );
2720             source1.append( "   10; 11; 12; 13  " + l );
2721             source1.append( "20; 21; 22; 23 " + l );
2722             source1.append( "    30;  31;    32; 33" + l );
2723             source1.append( "40;41;42;43" + l );
2724             source1.append( "  # 1 1 1 1 1 " + l );
2725             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2726             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2727             if ( t2.getNumberOfColumns() != 5 ) {
2728                 return false;
2729             }
2730             if ( t2.getNumberOfRows() != 6 ) {
2731                 return false;
2732             }
2733             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2737                 return false;
2738             }
2739             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2740                 return false;
2741             }
2742             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2743                 return false;
2744             }
2745             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2746                 return false;
2747             }
2748             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2749                 return false;
2750             }
2751             final StringBuffer source2 = new StringBuffer();
2752             source2.append( "" + l );
2753             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2754             source2.append( " 00; 01 ;02;03" + l );
2755             source2.append( "   10; 11; 12; 13  " + l );
2756             source2.append( "20; 21; 22; 23 " + l );
2757             source2.append( "                     " + l );
2758             source2.append( "    30;  31;    32; 33" + l );
2759             source2.append( "40;41;42;43" + l );
2760             source2.append( "  comment: 1 1 1 1 1 " + l );
2761             source2.append( ";;;50  ;   52; 53;;54   " + l );
2762             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2763                                                                         ';',
2764                                                                         false,
2765                                                                         false,
2766                                                                         "comment:",
2767                                                                         false );
2768             if ( tl.size() != 2 ) {
2769                 return false;
2770             }
2771             final BasicTable<String> t3 = tl.get( 0 );
2772             final BasicTable<String> t4 = tl.get( 1 );
2773             if ( t3.getNumberOfColumns() != 4 ) {
2774                 return false;
2775             }
2776             if ( t3.getNumberOfRows() != 3 ) {
2777                 return false;
2778             }
2779             if ( t4.getNumberOfColumns() != 4 ) {
2780                 return false;
2781             }
2782             if ( t4.getNumberOfRows() != 3 ) {
2783                 return false;
2784             }
2785             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2786                 return false;
2787             }
2788             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2789                 return false;
2790             }
2791         }
2792         catch ( final Exception e ) {
2793             e.printStackTrace( System.out );
2794             return false;
2795         }
2796         return true;
2797     }
2798
2799     private static boolean testBasicTolXMLparsing() {
2800         try {
2801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2802             final TolParser parser = new TolParser();
2803             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2804             if ( parser.getErrorCount() > 0 ) {
2805                 System.out.println( parser.getErrorMessages().toString() );
2806                 return false;
2807             }
2808             if ( phylogenies_0.length != 1 ) {
2809                 return false;
2810             }
2811             final Phylogeny t1 = phylogenies_0[ 0 ];
2812             if ( t1.getNumberOfExternalNodes() != 5 ) {
2813                 return false;
2814             }
2815             if ( !t1.isRooted() ) {
2816                 return false;
2817             }
2818             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2819                 return false;
2820             }
2821             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2822                 return false;
2823             }
2824             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2825                 return false;
2826             }
2827             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2828                 return false;
2829             }
2830             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2831             if ( parser.getErrorCount() > 0 ) {
2832                 System.out.println( parser.getErrorMessages().toString() );
2833                 return false;
2834             }
2835             if ( phylogenies_1.length != 1 ) {
2836                 return false;
2837             }
2838             final Phylogeny t2 = phylogenies_1[ 0 ];
2839             if ( t2.getNumberOfExternalNodes() != 664 ) {
2840                 return false;
2841             }
2842             if ( !t2.isRooted() ) {
2843                 return false;
2844             }
2845             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2846                 return false;
2847             }
2848             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2849                 return false;
2850             }
2851             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2852                 return false;
2853             }
2854             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2855                 return false;
2856             }
2857             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2858                 return false;
2859             }
2860             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2861                     .equals( "Aquifex" ) ) {
2862                 return false;
2863             }
2864             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2865             if ( parser.getErrorCount() > 0 ) {
2866                 System.out.println( parser.getErrorMessages().toString() );
2867                 return false;
2868             }
2869             if ( phylogenies_2.length != 1 ) {
2870                 return false;
2871             }
2872             final Phylogeny t3 = phylogenies_2[ 0 ];
2873             if ( t3.getNumberOfExternalNodes() != 184 ) {
2874                 return false;
2875             }
2876             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2877                 return false;
2878             }
2879             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2880                 return false;
2881             }
2882             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2883                 return false;
2884             }
2885             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2886             if ( parser.getErrorCount() > 0 ) {
2887                 System.out.println( parser.getErrorMessages().toString() );
2888                 return false;
2889             }
2890             if ( phylogenies_3.length != 1 ) {
2891                 return false;
2892             }
2893             final Phylogeny t4 = phylogenies_3[ 0 ];
2894             if ( t4.getNumberOfExternalNodes() != 1 ) {
2895                 return false;
2896             }
2897             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2898                 return false;
2899             }
2900             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2901                 return false;
2902             }
2903             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2904                 return false;
2905             }
2906             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2907             if ( parser.getErrorCount() > 0 ) {
2908                 System.out.println( parser.getErrorMessages().toString() );
2909                 return false;
2910             }
2911             if ( phylogenies_4.length != 1 ) {
2912                 return false;
2913             }
2914             final Phylogeny t5 = phylogenies_4[ 0 ];
2915             if ( t5.getNumberOfExternalNodes() != 13 ) {
2916                 return false;
2917             }
2918             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2919                 return false;
2920             }
2921             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2922                 return false;
2923             }
2924             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2925                 return false;
2926             }
2927         }
2928         catch ( final Exception e ) {
2929             e.printStackTrace( System.out );
2930             return false;
2931         }
2932         return true;
2933     }
2934
2935     private static boolean testBasicTreeMethods() {
2936         try {
2937             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2938             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2939             if ( t2.getNumberOfExternalNodes() != 4 ) {
2940                 return false;
2941             }
2942             if ( t2.getHeight() != 8.5 ) {
2943                 return false;
2944             }
2945             if ( !t2.isCompletelyBinary() ) {
2946                 return false;
2947             }
2948             if ( t2.isEmpty() ) {
2949                 return false;
2950             }
2951             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2952             if ( t3.getNumberOfExternalNodes() != 5 ) {
2953                 return false;
2954             }
2955             if ( t3.getHeight() != 11 ) {
2956                 return false;
2957             }
2958             if ( t3.isCompletelyBinary() ) {
2959                 return false;
2960             }
2961             final PhylogenyNode n = t3.getNode( "ABC" );
2962             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 ];
2963             if ( t4.getNumberOfExternalNodes() != 9 ) {
2964                 return false;
2965             }
2966             if ( t4.getHeight() != 11 ) {
2967                 return false;
2968             }
2969             if ( t4.isCompletelyBinary() ) {
2970                 return false;
2971             }
2972             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)" );
2973             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2974             if ( t5.getNumberOfExternalNodes() != 8 ) {
2975                 return false;
2976             }
2977             if ( t5.getHeight() != 15 ) {
2978                 return false;
2979             }
2980             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)" );
2981             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2982             if ( t6.getHeight() != 15 ) {
2983                 return false;
2984             }
2985             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)" );
2986             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2987             if ( t7.getHeight() != 15 ) {
2988                 return false;
2989             }
2990             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)" );
2991             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2992             if ( t8.getNumberOfExternalNodes() != 10 ) {
2993                 return false;
2994             }
2995             if ( t8.getHeight() != 15 ) {
2996                 return false;
2997             }
2998             final char[] a9 = new char[] { 'a' };
2999             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3000             if ( t9.getHeight() != 0 ) {
3001                 return false;
3002             }
3003             final char[] a10 = new char[] { 'a', ':', '6' };
3004             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3005             if ( t10.getHeight() != 6 ) {
3006                 return false;
3007             }
3008         }
3009         catch ( final Exception e ) {
3010             e.printStackTrace( System.out );
3011             return false;
3012         }
3013         return true;
3014     }
3015
3016     private static boolean testConfidenceAssessor() {
3017         try {
3018             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3019             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3020             final Phylogeny[] ev0 = factory
3021                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3022                              new NHXParser() );
3023             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3024             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3025                 return false;
3026             }
3027             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3028                 return false;
3029             }
3030             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3031             final Phylogeny[] ev1 = factory
3032                     .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)));",
3033                              new NHXParser() );
3034             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3035             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3036                 return false;
3037             }
3038             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3039                 return false;
3040             }
3041             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3042             final Phylogeny[] ev_b = factory
3043                     .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",
3044                              new NHXParser() );
3045             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3046             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3047                 return false;
3048             }
3049             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3050                 return false;
3051             }
3052             //
3053             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3054             final Phylogeny[] ev1x = factory
3055                     .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)));",
3056                              new NHXParser() );
3057             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3058             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3059                 return false;
3060             }
3061             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3062                 return false;
3063             }
3064             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3065             final Phylogeny[] ev_bx = factory
3066                     .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",
3067                              new NHXParser() );
3068             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3069             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3070                 return false;
3071             }
3072             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3073                 return false;
3074             }
3075             final Phylogeny[] t2 = factory
3076                     .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);",
3077                              new NHXParser() );
3078             final Phylogeny[] ev2 = factory
3079                     .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);",
3080                              new NHXParser() );
3081             for( final Phylogeny target : t2 ) {
3082                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3083             }
3084             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3085                                                  new NHXParser() )[ 0 ];
3086             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3087             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3088             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3089                 return false;
3090             }
3091             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3092                 return false;
3093             }
3094             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3095                 return false;
3096             }
3097         }
3098         catch ( final Exception e ) {
3099             e.printStackTrace();
3100             return false;
3101         }
3102         return true;
3103     }
3104
3105     private static boolean testCopyOfNodeData() {
3106         try {
3107             final PhylogenyNode n1 = PhylogenyNode
3108                     .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]" );
3109             final PhylogenyNode n2 = n1.copyNodeData();
3110             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3111                 return false;
3112             }
3113         }
3114         catch ( final Exception e ) {
3115             e.printStackTrace();
3116             return false;
3117         }
3118         return true;
3119     }
3120
3121     private static boolean testCreateBalancedPhylogeny() {
3122         try {
3123             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3124             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3125                 return false;
3126             }
3127             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3128                 return false;
3129             }
3130             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3131             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3132                 return false;
3133             }
3134             if ( p1.getNumberOfExternalNodes() != 100 ) {
3135                 return false;
3136             }
3137         }
3138         catch ( final Exception e ) {
3139             e.printStackTrace();
3140             return false;
3141         }
3142         return true;
3143     }
3144
3145     private static boolean testCreateUriForSeqWeb() {
3146         try {
3147             final PhylogenyNode n = new PhylogenyNode();
3148             n.setName( "tr|B3RJ64" );
3149             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3150                 return false;
3151             }
3152             n.setName( "B0LM41_HUMAN" );
3153             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3154                 return false;
3155             }
3156             n.setName( "NP_001025424" );
3157             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3158                 return false;
3159             }
3160             n.setName( "_NM_001030253-" );
3161             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3162                 return false;
3163             }
3164             n.setName( "XM_002122186" );
3165             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3166                 return false;
3167             }
3168             n.setName( "dgh_AAA34956_gdg" );
3169             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3170                 return false;
3171             }
3172             n.setName( "AAA34956" );
3173             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3174                 return false;
3175             }
3176             n.setName( "GI:394892" );
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( "gi_394892" );
3182             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3183                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3184                 return false;
3185             }
3186             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3187             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3188                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3189                 return false;
3190             }
3191             n.setName( "P12345" );
3192             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3193                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3194                 return false;
3195             }
3196             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3197             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3198                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3199                 return false;
3200             }
3201         }
3202         catch ( final Exception e ) {
3203             e.printStackTrace( System.out );
3204             return false;
3205         }
3206         return true;
3207     }
3208
3209     private static boolean testDataObjects() {
3210         try {
3211             final Confidence s0 = new Confidence();
3212             final Confidence s1 = new Confidence();
3213             if ( !s0.isEqual( s1 ) ) {
3214                 return false;
3215             }
3216             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3217             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3218             if ( s2.isEqual( s1 ) ) {
3219                 return false;
3220             }
3221             if ( !s2.isEqual( s3 ) ) {
3222                 return false;
3223             }
3224             final Confidence s4 = ( Confidence ) s3.copy();
3225             if ( !s4.isEqual( s3 ) ) {
3226                 return false;
3227             }
3228             s3.asSimpleText();
3229             s3.asText();
3230             // Taxonomy
3231             // ----------
3232             final Taxonomy t1 = new Taxonomy();
3233             final Taxonomy t2 = new Taxonomy();
3234             final Taxonomy t3 = new Taxonomy();
3235             final Taxonomy t4 = new Taxonomy();
3236             final Taxonomy t5 = new Taxonomy();
3237             t1.setIdentifier( new Identifier( "ecoli" ) );
3238             t1.setTaxonomyCode( "ECOLI" );
3239             t1.setScientificName( "E. coli" );
3240             t1.setCommonName( "coli" );
3241             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3242             if ( !t1.isEqual( t0 ) ) {
3243                 return false;
3244             }
3245             t2.setIdentifier( new Identifier( "ecoli" ) );
3246             t2.setTaxonomyCode( "OTHER" );
3247             t2.setScientificName( "what" );
3248             t2.setCommonName( "something" );
3249             if ( !t1.isEqual( t2 ) ) {
3250                 return false;
3251             }
3252             t2.setIdentifier( new Identifier( "nemve" ) );
3253             if ( t1.isEqual( t2 ) ) {
3254                 return false;
3255             }
3256             t1.setIdentifier( null );
3257             t3.setTaxonomyCode( "ECOLI" );
3258             t3.setScientificName( "what" );
3259             t3.setCommonName( "something" );
3260             if ( !t1.isEqual( t3 ) ) {
3261                 return false;
3262             }
3263             t1.setIdentifier( null );
3264             t1.setTaxonomyCode( "" );
3265             t4.setScientificName( "E. ColI" );
3266             t4.setCommonName( "something" );
3267             if ( !t1.isEqual( t4 ) ) {
3268                 return false;
3269             }
3270             t4.setScientificName( "B. subtilis" );
3271             t4.setCommonName( "something" );
3272             if ( t1.isEqual( t4 ) ) {
3273                 return false;
3274             }
3275             t1.setIdentifier( null );
3276             t1.setTaxonomyCode( "" );
3277             t1.setScientificName( "" );
3278             t5.setCommonName( "COLI" );
3279             if ( !t1.isEqual( t5 ) ) {
3280                 return false;
3281             }
3282             t5.setCommonName( "vibrio" );
3283             if ( t1.isEqual( t5 ) ) {
3284                 return false;
3285             }
3286             // Identifier
3287             // ----------
3288             final Identifier id0 = new Identifier( "123", "pfam" );
3289             final Identifier id1 = ( Identifier ) id0.copy();
3290             if ( !id1.isEqual( id1 ) ) {
3291                 return false;
3292             }
3293             if ( !id1.isEqual( id0 ) ) {
3294                 return false;
3295             }
3296             if ( !id0.isEqual( id1 ) ) {
3297                 return false;
3298             }
3299             id1.asSimpleText();
3300             id1.asText();
3301             // ProteinDomain
3302             // ---------------
3303             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3304             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3305             if ( !pd1.isEqual( pd1 ) ) {
3306                 return false;
3307             }
3308             if ( !pd1.isEqual( pd0 ) ) {
3309                 return false;
3310             }
3311             pd1.asSimpleText();
3312             pd1.asText();
3313             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3314             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3315             if ( !pd3.isEqual( pd3 ) ) {
3316                 return false;
3317             }
3318             if ( !pd2.isEqual( pd3 ) ) {
3319                 return false;
3320             }
3321             if ( !pd0.isEqual( pd3 ) ) {
3322                 return false;
3323             }
3324             pd3.asSimpleText();
3325             pd3.asText();
3326             // DomainArchitecture
3327             // ------------------
3328             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3329             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3330             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3331             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3332             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3333             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3334             domains0.add( d2 );
3335             domains0.add( d0 );
3336             domains0.add( d3 );
3337             domains0.add( d1 );
3338             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3339             if ( ds0.getNumberOfDomains() != 4 ) {
3340                 return false;
3341             }
3342             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3343             if ( !ds0.isEqual( ds0 ) ) {
3344                 return false;
3345             }
3346             if ( !ds0.isEqual( ds1 ) ) {
3347                 return false;
3348             }
3349             if ( ds1.getNumberOfDomains() != 4 ) {
3350                 return false;
3351             }
3352             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3353             domains1.add( d1 );
3354             domains1.add( d2 );
3355             domains1.add( d4 );
3356             domains1.add( d0 );
3357             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3358             if ( ds0.isEqual( ds2 ) ) {
3359                 return false;
3360             }
3361             ds1.asSimpleText();
3362             ds1.asText();
3363             ds1.toNHX();
3364             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3365             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3366                 System.out.println( ds3.toNHX() );
3367                 return false;
3368             }
3369             if ( ds3.getNumberOfDomains() != 3 ) {
3370                 return false;
3371             }
3372             // Event
3373             // -----
3374             final Event e1 = new Event( Event.EventType.fusion );
3375             if ( e1.isDuplication() ) {
3376                 return false;
3377             }
3378             if ( !e1.isFusion() ) {
3379                 return false;
3380             }
3381             if ( !e1.asText().toString().equals( "fusion" ) ) {
3382                 return false;
3383             }
3384             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3385                 return false;
3386             }
3387             final Event e11 = new Event( Event.EventType.fusion );
3388             if ( !e11.isEqual( e1 ) ) {
3389                 return false;
3390             }
3391             if ( !e11.toNHX().toString().equals( "" ) ) {
3392                 return false;
3393             }
3394             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3395             if ( e2.isDuplication() ) {
3396                 return false;
3397             }
3398             if ( !e2.isSpeciationOrDuplication() ) {
3399                 return false;
3400             }
3401             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3402                 return false;
3403             }
3404             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3405                 return false;
3406             }
3407             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3408                 return false;
3409             }
3410             if ( e11.isEqual( e2 ) ) {
3411                 return false;
3412             }
3413             final Event e2c = ( Event ) e2.copy();
3414             if ( !e2c.isEqual( e2 ) ) {
3415                 return false;
3416             }
3417             Event e3 = new Event( 1, 2, 3 );
3418             if ( e3.isDuplication() ) {
3419                 return false;
3420             }
3421             if ( e3.isSpeciation() ) {
3422                 return false;
3423             }
3424             if ( e3.isGeneLoss() ) {
3425                 return false;
3426             }
3427             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3428                 return false;
3429             }
3430             final Event e3c = ( Event ) e3.copy();
3431             final Event e3cc = ( Event ) e3c.copy();
3432             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3433                 return false;
3434             }
3435             e3 = null;
3436             if ( !e3c.isEqual( e3cc ) ) {
3437                 return false;
3438             }
3439             Event e4 = new Event( 1, 2, 3 );
3440             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3441                 return false;
3442             }
3443             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3444                 return false;
3445             }
3446             final Event e4c = ( Event ) e4.copy();
3447             e4 = null;
3448             final Event e4cc = ( Event ) e4c.copy();
3449             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3450                 return false;
3451             }
3452             if ( !e4c.isEqual( e4cc ) ) {
3453                 return false;
3454             }
3455             final Event e5 = new Event();
3456             if ( !e5.isUnassigned() ) {
3457                 return false;
3458             }
3459             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3460                 return false;
3461             }
3462             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3463                 return false;
3464             }
3465             final Event e6 = new Event( 1, 0, 0 );
3466             if ( !e6.asText().toString().equals( "duplication" ) ) {
3467                 return false;
3468             }
3469             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3470                 return false;
3471             }
3472             final Event e7 = new Event( 0, 1, 0 );
3473             if ( !e7.asText().toString().equals( "speciation" ) ) {
3474                 return false;
3475             }
3476             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3477                 return false;
3478             }
3479             final Event e8 = new Event( 0, 0, 1 );
3480             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3481                 return false;
3482             }
3483             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3484                 return false;
3485             }
3486         }
3487         catch ( final Exception e ) {
3488             e.printStackTrace( System.out );
3489             return false;
3490         }
3491         return true;
3492     }
3493
3494     private static boolean testDeletionOfExternalNodes() {
3495         try {
3496             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3497             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3498             final PhylogenyWriter w = new PhylogenyWriter();
3499             if ( t0.isEmpty() ) {
3500                 return false;
3501             }
3502             if ( t0.getNumberOfExternalNodes() != 1 ) {
3503                 return false;
3504             }
3505             t0.deleteSubtree( t0.getNode( "A" ), false );
3506             if ( t0.getNumberOfExternalNodes() != 0 ) {
3507                 return false;
3508             }
3509             if ( !t0.isEmpty() ) {
3510                 return false;
3511             }
3512             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3513             if ( t1.getNumberOfExternalNodes() != 2 ) {
3514                 return false;
3515             }
3516             t1.deleteSubtree( t1.getNode( "A" ), false );
3517             if ( t1.getNumberOfExternalNodes() != 1 ) {
3518                 return false;
3519             }
3520             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3521                 return false;
3522             }
3523             t1.deleteSubtree( t1.getNode( "B" ), false );
3524             if ( t1.getNumberOfExternalNodes() != 1 ) {
3525                 return false;
3526             }
3527             t1.deleteSubtree( t1.getNode( "r" ), false );
3528             if ( !t1.isEmpty() ) {
3529                 return false;
3530             }
3531             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3532             if ( t2.getNumberOfExternalNodes() != 3 ) {
3533                 return false;
3534             }
3535             t2.deleteSubtree( t2.getNode( "B" ), false );
3536             if ( t2.getNumberOfExternalNodes() != 2 ) {
3537                 return false;
3538             }
3539             t2.toNewHampshireX();
3540             PhylogenyNode n = t2.getNode( "A" );
3541             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3542                 return false;
3543             }
3544             t2.deleteSubtree( t2.getNode( "A" ), false );
3545             if ( t2.getNumberOfExternalNodes() != 2 ) {
3546                 return false;
3547             }
3548             t2.deleteSubtree( t2.getNode( "C" ), true );
3549             if ( t2.getNumberOfExternalNodes() != 1 ) {
3550                 return false;
3551             }
3552             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3553             if ( t3.getNumberOfExternalNodes() != 4 ) {
3554                 return false;
3555             }
3556             t3.deleteSubtree( t3.getNode( "B" ), true );
3557             if ( t3.getNumberOfExternalNodes() != 3 ) {
3558                 return false;
3559             }
3560             n = t3.getNode( "A" );
3561             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3562                 return false;
3563             }
3564             n = n.getNextExternalNode();
3565             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3566                 return false;
3567             }
3568             t3.deleteSubtree( t3.getNode( "A" ), true );
3569             if ( t3.getNumberOfExternalNodes() != 2 ) {
3570                 return false;
3571             }
3572             n = t3.getNode( "C" );
3573             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3574                 return false;
3575             }
3576             t3.deleteSubtree( t3.getNode( "C" ), true );
3577             if ( t3.getNumberOfExternalNodes() != 1 ) {
3578                 return false;
3579             }
3580             t3.deleteSubtree( t3.getNode( "D" ), true );
3581             if ( t3.getNumberOfExternalNodes() != 0 ) {
3582                 return false;
3583             }
3584             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3585             if ( t4.getNumberOfExternalNodes() != 6 ) {
3586                 return false;
3587             }
3588             t4.deleteSubtree( t4.getNode( "B2" ), true );
3589             if ( t4.getNumberOfExternalNodes() != 5 ) {
3590                 return false;
3591             }
3592             String s = w.toNewHampshire( t4, true ).toString();
3593             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3594                 return false;
3595             }
3596             t4.deleteSubtree( t4.getNode( "B11" ), true );
3597             if ( t4.getNumberOfExternalNodes() != 4 ) {
3598                 return false;
3599             }
3600             t4.deleteSubtree( t4.getNode( "C" ), true );
3601             if ( t4.getNumberOfExternalNodes() != 3 ) {
3602                 return false;
3603             }
3604             n = t4.getNode( "A" );
3605             n = n.getNextExternalNode();
3606             if ( !n.getName().equals( "B12" ) ) {
3607                 return false;
3608             }
3609             n = n.getNextExternalNode();
3610             if ( !n.getName().equals( "D" ) ) {
3611                 return false;
3612             }
3613             s = w.toNewHampshire( t4, true ).toString();
3614             if ( !s.equals( "((A,B12),D);" ) ) {
3615                 return false;
3616             }
3617             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3618             t5.deleteSubtree( t5.getNode( "A" ), true );
3619             if ( t5.getNumberOfExternalNodes() != 5 ) {
3620                 return false;
3621             }
3622             s = w.toNewHampshire( t5, true ).toString();
3623             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3624                 return false;
3625             }
3626             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3627             t6.deleteSubtree( t6.getNode( "B11" ), true );
3628             if ( t6.getNumberOfExternalNodes() != 5 ) {
3629                 return false;
3630             }
3631             s = w.toNewHampshire( t6, false ).toString();
3632             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3633                 return false;
3634             }
3635             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3636             t7.deleteSubtree( t7.getNode( "B12" ), true );
3637             if ( t7.getNumberOfExternalNodes() != 5 ) {
3638                 return false;
3639             }
3640             s = w.toNewHampshire( t7, true ).toString();
3641             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3642                 return false;
3643             }
3644             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3645             t8.deleteSubtree( t8.getNode( "B2" ), true );
3646             if ( t8.getNumberOfExternalNodes() != 5 ) {
3647                 return false;
3648             }
3649             s = w.toNewHampshire( t8, false ).toString();
3650             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3651                 return false;
3652             }
3653             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3654             t9.deleteSubtree( t9.getNode( "C" ), true );
3655             if ( t9.getNumberOfExternalNodes() != 5 ) {
3656                 return false;
3657             }
3658             s = w.toNewHampshire( t9, true ).toString();
3659             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3660                 return false;
3661             }
3662             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3663             t10.deleteSubtree( t10.getNode( "D" ), true );
3664             if ( t10.getNumberOfExternalNodes() != 5 ) {
3665                 return false;
3666             }
3667             s = w.toNewHampshire( t10, true ).toString();
3668             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3669                 return false;
3670             }
3671             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3672             t11.deleteSubtree( t11.getNode( "A" ), true );
3673             if ( t11.getNumberOfExternalNodes() != 2 ) {
3674                 return false;
3675             }
3676             s = w.toNewHampshire( t11, true ).toString();
3677             if ( !s.equals( "(B,C);" ) ) {
3678                 return false;
3679             }
3680             t11.deleteSubtree( t11.getNode( "C" ), true );
3681             if ( t11.getNumberOfExternalNodes() != 1 ) {
3682                 return false;
3683             }
3684             s = w.toNewHampshire( t11, false ).toString();
3685             if ( !s.equals( "B;" ) ) {
3686                 return false;
3687             }
3688             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3689             t12.deleteSubtree( t12.getNode( "B2" ), true );
3690             if ( t12.getNumberOfExternalNodes() != 8 ) {
3691                 return false;
3692             }
3693             s = w.toNewHampshire( t12, true ).toString();
3694             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3695                 return false;
3696             }
3697             t12.deleteSubtree( t12.getNode( "B3" ), true );
3698             if ( t12.getNumberOfExternalNodes() != 7 ) {
3699                 return false;
3700             }
3701             s = w.toNewHampshire( t12, true ).toString();
3702             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3703                 return false;
3704             }
3705             t12.deleteSubtree( t12.getNode( "C3" ), true );
3706             if ( t12.getNumberOfExternalNodes() != 6 ) {
3707                 return false;
3708             }
3709             s = w.toNewHampshire( t12, true ).toString();
3710             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3711                 return false;
3712             }
3713             t12.deleteSubtree( t12.getNode( "A1" ), true );
3714             if ( t12.getNumberOfExternalNodes() != 5 ) {
3715                 return false;
3716             }
3717             s = w.toNewHampshire( t12, true ).toString();
3718             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3719                 return false;
3720             }
3721             t12.deleteSubtree( t12.getNode( "B1" ), true );
3722             if ( t12.getNumberOfExternalNodes() != 4 ) {
3723                 return false;
3724             }
3725             s = w.toNewHampshire( t12, true ).toString();
3726             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3727                 return false;
3728             }
3729             t12.deleteSubtree( t12.getNode( "A3" ), true );
3730             if ( t12.getNumberOfExternalNodes() != 3 ) {
3731                 return false;
3732             }
3733             s = w.toNewHampshire( t12, true ).toString();
3734             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3735                 return false;
3736             }
3737             t12.deleteSubtree( t12.getNode( "A2" ), true );
3738             if ( t12.getNumberOfExternalNodes() != 2 ) {
3739                 return false;
3740             }
3741             s = w.toNewHampshire( t12, true ).toString();
3742             if ( !s.equals( "(C1,C2);" ) ) {
3743                 return false;
3744             }
3745             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3746             t13.deleteSubtree( t13.getNode( "D" ), true );
3747             if ( t13.getNumberOfExternalNodes() != 4 ) {
3748                 return false;
3749             }
3750             s = w.toNewHampshire( t13, true ).toString();
3751             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3752                 return false;
3753             }
3754             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3755             t14.deleteSubtree( t14.getNode( "E" ), true );
3756             if ( t14.getNumberOfExternalNodes() != 5 ) {
3757                 return false;
3758             }
3759             s = w.toNewHampshire( t14, true ).toString();
3760             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3761                 return false;
3762             }
3763             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3764             t15.deleteSubtree( t15.getNode( "B2" ), true );
3765             if ( t15.getNumberOfExternalNodes() != 11 ) {
3766                 return false;
3767             }
3768             t15.deleteSubtree( t15.getNode( "B1" ), true );
3769             if ( t15.getNumberOfExternalNodes() != 10 ) {
3770                 return false;
3771             }
3772             t15.deleteSubtree( t15.getNode( "B3" ), true );
3773             if ( t15.getNumberOfExternalNodes() != 9 ) {
3774                 return false;
3775             }
3776             t15.deleteSubtree( t15.getNode( "B4" ), true );
3777             if ( t15.getNumberOfExternalNodes() != 8 ) {
3778                 return false;
3779             }
3780             t15.deleteSubtree( t15.getNode( "A1" ), true );
3781             if ( t15.getNumberOfExternalNodes() != 7 ) {
3782                 return false;
3783             }
3784             t15.deleteSubtree( t15.getNode( "C4" ), true );
3785             if ( t15.getNumberOfExternalNodes() != 6 ) {
3786                 return false;
3787             }
3788         }
3789         catch ( final Exception e ) {
3790             e.printStackTrace( System.out );
3791             return false;
3792         }
3793         return true;
3794     }
3795
3796     private static boolean testDescriptiveStatistics() {
3797         try {
3798             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3799             dss1.addValue( 82 );
3800             dss1.addValue( 78 );
3801             dss1.addValue( 70 );
3802             dss1.addValue( 58 );
3803             dss1.addValue( 42 );
3804             if ( dss1.getN() != 5 ) {
3805                 return false;
3806             }
3807             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3808                 return false;
3809             }
3810             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3811                 return false;
3812             }
3813             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3814                 return false;
3815             }
3816             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3817                 return false;
3818             }
3819             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3820                 return false;
3821             }
3822             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3823                 return false;
3824             }
3825             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3826                 return false;
3827             }
3828             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3829                 return false;
3830             }
3831             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3832                 return false;
3833             }
3834             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3835                 return false;
3836             }
3837             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3838                 return false;
3839             }
3840             dss1.addValue( 123 );
3841             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3842                 return false;
3843             }
3844             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3845                 return false;
3846             }
3847             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3848                 return false;
3849             }
3850             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3851             dss2.addValue( -1.85 );
3852             dss2.addValue( 57.5 );
3853             dss2.addValue( 92.78 );
3854             dss2.addValue( 57.78 );
3855             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3856                 return false;
3857             }
3858             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3859                 return false;
3860             }
3861             final double[] a = dss2.getDataAsDoubleArray();
3862             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3863                 return false;
3864             }
3865             dss2.addValue( -100 );
3866             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3867                 return false;
3868             }
3869             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3870                 return false;
3871             }
3872             final double[] ds = new double[ 14 ];
3873             ds[ 0 ] = 34;
3874             ds[ 1 ] = 23;
3875             ds[ 2 ] = 1;
3876             ds[ 3 ] = 32;
3877             ds[ 4 ] = 11;
3878             ds[ 5 ] = 2;
3879             ds[ 6 ] = 12;
3880             ds[ 7 ] = 33;
3881             ds[ 8 ] = 13;
3882             ds[ 9 ] = 22;
3883             ds[ 10 ] = 21;
3884             ds[ 11 ] = 35;
3885             ds[ 12 ] = 24;
3886             ds[ 13 ] = 31;
3887             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3888             if ( bins.length != 4 ) {
3889                 return false;
3890             }
3891             if ( bins[ 0 ] != 2 ) {
3892                 return false;
3893             }
3894             if ( bins[ 1 ] != 3 ) {
3895                 return false;
3896             }
3897             if ( bins[ 2 ] != 4 ) {
3898                 return false;
3899             }
3900             if ( bins[ 3 ] != 5 ) {
3901                 return false;
3902             }
3903             final double[] ds1 = new double[ 9 ];
3904             ds1[ 0 ] = 10.0;
3905             ds1[ 1 ] = 19.0;
3906             ds1[ 2 ] = 9.999;
3907             ds1[ 3 ] = 0.0;
3908             ds1[ 4 ] = 39.9;
3909             ds1[ 5 ] = 39.999;
3910             ds1[ 6 ] = 30.0;
3911             ds1[ 7 ] = 19.999;
3912             ds1[ 8 ] = 30.1;
3913             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3914             if ( bins1.length != 4 ) {
3915                 return false;
3916             }
3917             if ( bins1[ 0 ] != 2 ) {
3918                 return false;
3919             }
3920             if ( bins1[ 1 ] != 3 ) {
3921                 return false;
3922             }
3923             if ( bins1[ 2 ] != 0 ) {
3924                 return false;
3925             }
3926             if ( bins1[ 3 ] != 4 ) {
3927                 return false;
3928             }
3929             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3930             if ( bins1_1.length != 3 ) {
3931                 return false;
3932             }
3933             if ( bins1_1[ 0 ] != 3 ) {
3934                 return false;
3935             }
3936             if ( bins1_1[ 1 ] != 2 ) {
3937                 return false;
3938             }
3939             if ( bins1_1[ 2 ] != 4 ) {
3940                 return false;
3941             }
3942             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3943             if ( bins1_2.length != 3 ) {
3944                 return false;
3945             }
3946             if ( bins1_2[ 0 ] != 2 ) {
3947                 return false;
3948             }
3949             if ( bins1_2[ 1 ] != 2 ) {
3950                 return false;
3951             }
3952             if ( bins1_2[ 2 ] != 2 ) {
3953                 return false;
3954             }
3955             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3956             dss3.addValue( 1 );
3957             dss3.addValue( 1 );
3958             dss3.addValue( 1 );
3959             dss3.addValue( 2 );
3960             dss3.addValue( 3 );
3961             dss3.addValue( 4 );
3962             dss3.addValue( 5 );
3963             dss3.addValue( 5 );
3964             dss3.addValue( 5 );
3965             dss3.addValue( 6 );
3966             dss3.addValue( 7 );
3967             dss3.addValue( 8 );
3968             dss3.addValue( 9 );
3969             dss3.addValue( 10 );
3970             dss3.addValue( 10 );
3971             dss3.addValue( 10 );
3972             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3973             histo.toStringBuffer( 10, '=', 40, 5 );
3974             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3975         }
3976         catch ( final Exception e ) {
3977             e.printStackTrace( System.out );
3978             return false;
3979         }
3980         return true;
3981     }
3982
3983     private static boolean testDir( final String file ) {
3984         try {
3985             final File f = new File( file );
3986             if ( !f.exists() ) {
3987                 return false;
3988             }
3989             if ( !f.isDirectory() ) {
3990                 return false;
3991             }
3992             if ( !f.canRead() ) {
3993                 return false;
3994             }
3995         }
3996         catch ( final Exception e ) {
3997             return false;
3998         }
3999         return true;
4000     }
4001
4002     private static boolean testEbiEntryRetrieval() {
4003         try {
4004             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4005             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4006                 System.out.println( entry.getAccession() );
4007                 return false;
4008             }
4009             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4010                 System.out.println( entry.getTaxonomyScientificName() );
4011                 return false;
4012             }
4013             if ( !entry.getSequenceName()
4014                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4015                 System.out.println( entry.getSequenceName() );
4016                 return false;
4017             }
4018             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4019                 System.out.println( entry.getGeneName() );
4020                 return false;
4021             }
4022             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4023                 System.out.println( entry.getTaxonomyIdentifier() );
4024                 return false;
4025             }
4026             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4027                 System.out.println( entry.getAnnotations().first().getRefValue() );
4028                 return false;
4029             }
4030             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4031                 System.out.println( entry.getAnnotations().first().getRefSource() );
4032                 return false;
4033             }
4034             if ( entry.getCrossReferences().size() < 1 ) {
4035                 return false;
4036             }
4037             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4038             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4039                 return false;
4040             }
4041             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4042                 System.out.println( entry1.getTaxonomyScientificName() );
4043                 return false;
4044             }
4045             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4046                 System.out.println( entry1.getSequenceName() );
4047                 return false;
4048             }
4049             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4050                 System.out.println( entry1.getTaxonomyIdentifier() );
4051                 return false;
4052             }
4053             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4054                 System.out.println( entry1.getGeneName() );
4055                 return false;
4056             }
4057             if ( entry1.getCrossReferences().size() < 1 ) {
4058                 return false;
4059             }
4060             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4061             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4062                 return false;
4063             }
4064             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4065                 System.out.println( entry2.getTaxonomyScientificName() );
4066                 return false;
4067             }
4068             if ( !entry2.getSequenceName()
4069                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4070                 System.out.println( entry2.getSequenceName() );
4071                 return false;
4072             }
4073             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4074                 System.out.println( entry2.getTaxonomyIdentifier() );
4075                 return false;
4076             }
4077             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4078                 System.out.println( entry2.getGeneName() );
4079                 return false;
4080             }
4081             if ( entry2.getCrossReferences().size() < 1 ) {
4082                 return false;
4083             }
4084             if ( !entry2.getChromosome().equals( "20" ) ) {
4085                 return false;
4086             }
4087             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4088                 return false;
4089             }
4090             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4091             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4092                 return false;
4093             }
4094             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4095                 System.out.println( entry3.getTaxonomyScientificName() );
4096                 return false;
4097             }
4098             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4099                 System.out.println( entry3.getSequenceName() );
4100                 return false;
4101             }
4102             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4103                 System.out.println( entry3.getTaxonomyIdentifier() );
4104                 return false;
4105             }
4106             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4107                 System.out.println( entry3.getSequenceSymbol() );
4108                 return false;
4109             }
4110             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4111                 return false;
4112             }
4113             if ( entry3.getCrossReferences().size() < 1 ) {
4114                 return false;
4115             }
4116             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4117             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4118                 return false;
4119             }
4120             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4121                 System.out.println( entry4.getTaxonomyScientificName() );
4122                 return false;
4123             }
4124             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4125                 System.out.println( entry4.getSequenceName() );
4126                 return false;
4127             }
4128             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4129                 System.out.println( entry4.getTaxonomyIdentifier() );
4130                 return false;
4131             }
4132             if ( !entry4.getGeneName().equals( "ras" ) ) {
4133                 System.out.println( entry4.getGeneName() );
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             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4153             if ( !entry6.getAccession().equals( "M30539" ) ) {
4154                 return false;
4155             }
4156             if ( !entry6.getGeneName().equals( "ras" ) ) {
4157                 return false;
4158             }
4159             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4160                 return false;
4161             }
4162             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4163                 return false;
4164             }
4165             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4166                 return false;
4167             }
4168             if ( entry6.getCrossReferences().size() < 1 ) {
4169                 return false;
4170             }
4171         }
4172         catch ( final IOException e ) {
4173             System.out.println();
4174             System.out.println( "the following might be due to absence internet connection:" );
4175             e.printStackTrace( System.out );
4176             return true;
4177         }
4178         catch ( final Exception e ) {
4179             e.printStackTrace();
4180             return false;
4181         }
4182         return true;
4183     }
4184
4185     private static boolean testExternalNodeRelatedMethods() {
4186         try {
4187             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4188             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4189             PhylogenyNode n = t1.getNode( "A" );
4190             n = n.getNextExternalNode();
4191             if ( !n.getName().equals( "B" ) ) {
4192                 return false;
4193             }
4194             n = n.getNextExternalNode();
4195             if ( !n.getName().equals( "C" ) ) {
4196                 return false;
4197             }
4198             n = n.getNextExternalNode();
4199             if ( !n.getName().equals( "D" ) ) {
4200                 return false;
4201             }
4202             n = t1.getNode( "B" );
4203             while ( !n.isLastExternalNode() ) {
4204                 n = n.getNextExternalNode();
4205             }
4206             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4207             n = t2.getNode( "A" );
4208             n = n.getNextExternalNode();
4209             if ( !n.getName().equals( "B" ) ) {
4210                 return false;
4211             }
4212             n = n.getNextExternalNode();
4213             if ( !n.getName().equals( "C" ) ) {
4214                 return false;
4215             }
4216             n = n.getNextExternalNode();
4217             if ( !n.getName().equals( "D" ) ) {
4218                 return false;
4219             }
4220             n = t2.getNode( "B" );
4221             while ( !n.isLastExternalNode() ) {
4222                 n = n.getNextExternalNode();
4223             }
4224             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4225             n = t3.getNode( "A" );
4226             n = n.getNextExternalNode();
4227             if ( !n.getName().equals( "B" ) ) {
4228                 return false;
4229             }
4230             n = n.getNextExternalNode();
4231             if ( !n.getName().equals( "C" ) ) {
4232                 return false;
4233             }
4234             n = n.getNextExternalNode();
4235             if ( !n.getName().equals( "D" ) ) {
4236                 return false;
4237             }
4238             n = n.getNextExternalNode();
4239             if ( !n.getName().equals( "E" ) ) {
4240                 return false;
4241             }
4242             n = n.getNextExternalNode();
4243             if ( !n.getName().equals( "F" ) ) {
4244                 return false;
4245             }
4246             n = n.getNextExternalNode();
4247             if ( !n.getName().equals( "G" ) ) {
4248                 return false;
4249             }
4250             n = n.getNextExternalNode();
4251             if ( !n.getName().equals( "H" ) ) {
4252                 return false;
4253             }
4254             n = t3.getNode( "B" );
4255             while ( !n.isLastExternalNode() ) {
4256                 n = n.getNextExternalNode();
4257             }
4258             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4259             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4260                 final PhylogenyNode node = iter.next();
4261             }
4262             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4263             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4264                 final PhylogenyNode node = iter.next();
4265             }
4266             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4267             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4268             if ( !iter.next().getName().equals( "A" ) ) {
4269                 return false;
4270             }
4271             if ( !iter.next().getName().equals( "B" ) ) {
4272                 return false;
4273             }
4274             if ( !iter.next().getName().equals( "C" ) ) {
4275                 return false;
4276             }
4277             if ( !iter.next().getName().equals( "D" ) ) {
4278                 return false;
4279             }
4280             if ( !iter.next().getName().equals( "E" ) ) {
4281                 return false;
4282             }
4283             if ( !iter.next().getName().equals( "F" ) ) {
4284                 return false;
4285             }
4286             if ( iter.hasNext() ) {
4287                 return false;
4288             }
4289         }
4290         catch ( final Exception e ) {
4291             e.printStackTrace( System.out );
4292             return false;
4293         }
4294         return true;
4295     }
4296
4297     private static boolean testExtractSNFromNodeName() {
4298         try {
4299             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4300                 return false;
4301             }
4302             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4303                 return false;
4304             }
4305             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4309                     .equals( "Mus musculus musculus" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4313                     .equals( "Mus musculus musculus" ) ) {
4314                 return false;
4315             }
4316             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4317                     .equals( "Mus musculus musculus" ) ) {
4318                 return false;
4319             }
4320             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4321                     .equals( "Mus musculus musculus" ) ) {
4322                 return false;
4323             }
4324             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4325                 return false;
4326             }
4327             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4328                     .equals( "Mus musculus musculus" ) ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4332                     .equals( "Mus musculus musculus" ) ) {
4333                 return false;
4334             }
4335             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4336                 return false;
4337             }
4338             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4339                 return false;
4340             }
4341             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4342                 return false;
4343             }
4344             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4345                 return false;
4346             }
4347             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4348                     .equals( "Mus musculus musculus" ) ) {
4349                 return false;
4350             }
4351             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4352                 return false;
4353             }
4354             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4355                 return false;
4356             }
4357             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4358                 return false;
4359             }
4360             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4361                 return false;
4362             }
4363             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4367                 return false;
4368             }
4369             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4376                     .equals( "Mus musculus" ) ) {
4377                 return false;
4378             }
4379             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4380                     .equals( "Mus musculus" ) ) {
4381                 return false;
4382             }
4383             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4384                 return false;
4385             }
4386             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4387                     .equals( "Mus musculus musculus" ) ) {
4388                 return false;
4389             }
4390             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4391                     .equals( "Mus musculus musculus" ) ) {
4392                 return false;
4393             }
4394             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4395                     .equals( "Mus musculus musculus" ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4402                     .equals( "Pilostyles mexicana" ) ) {
4403                 return false;
4404             }
4405             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4406                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4410                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4414                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4418                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4422                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4423                 return false;
4424             }
4425             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4426                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4427                 return false;
4428             }
4429             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4430                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4434                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4435                 return false;
4436             }
4437             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4438                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4442                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4446                     .equals( "Escherichia coli (strain K12)" ) ) {
4447                 return false;
4448             }
4449             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4450                     .equals( "Escherichia coli (strain K12)" ) ) {
4451                 return false;
4452             }
4453             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4454                     .equals( "Escherichia coli (str. K12)" ) ) {
4455                 return false;
4456             }
4457             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4458                     .equals( "Escherichia coli (str. K12)" ) ) {
4459                 return false;
4460             }
4461             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4462                     .equals( "Escherichia coli (str. K12)" ) ) {
4463                 return false;
4464             }
4465             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4466                     .equals( "Escherichia coli (var. K12)" ) ) {
4467                 return false;
4468             }
4469             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4470                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4471                 return false;
4472             }
4473             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4474                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4475                 return false;
4476             }
4477             if ( !ParserUtils
4478                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4479                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4480                 return false;
4481             }
4482             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4483                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4484                 return false;
4485             }
4486             if ( !ParserUtils
4487                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4488                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4489                 return false;
4490             }
4491             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4492                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4493                 return false;
4494             }
4495             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4496                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4500                 return false;
4501             }
4502             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4503                 return false;
4504             }
4505             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4506                 return false;
4507             }
4508             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4509                     .equals( "Macrocera sp." ) ) {
4510                 return false;
4511             }
4512             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4513                 return false;
4514             }
4515             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4516                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4517                 return false;
4518             }
4519             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4520                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4521                 return false;
4522             }
4523             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4524                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4525                 return false;
4526             }
4527             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4528                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4529                 return false;
4530             }
4531         }
4532         catch ( final Exception e ) {
4533             e.printStackTrace( System.out );
4534             return false;
4535         }
4536         return true;
4537     }
4538
4539     private static boolean testExtractTaxonomyDataFromNodeName() {
4540         try {
4541             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4542             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4543                 return false;
4544             }
4545             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4546             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4547                 return false;
4548             }
4549             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4550             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4551                 return false;
4552             }
4553             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4554             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4555                 return false;
4556             }
4557             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4558             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4559                 return false;
4560             }
4561             n = new PhylogenyNode( "HNRPR_HUMAN" );
4562             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4563                 return false;
4564             }
4565             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4566             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4567                 return false;
4568             }
4569         }
4570         catch ( final Exception e ) {
4571             e.printStackTrace( System.out );
4572             return false;
4573         }
4574         return true;
4575     }
4576
4577     private static boolean testExtractTaxonomyCodeFromNodeName() {
4578         try {
4579             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4580                 return false;
4581             }
4582             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4583                     .equals( "SOYBN" ) ) {
4584                 return false;
4585             }
4586             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4587                     .equals( "ARATH" ) ) {
4588                 return false;
4589             }
4590             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4591                     .equals( "ARATH" ) ) {
4592                 return false;
4593             }
4594             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4595                 return false;
4596             }
4597             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4598                 return false;
4599             }
4600             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4601                 return false;
4602             }
4603             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4604                     .equals( "SOYBN" ) ) {
4605                 return false;
4606             }
4607             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4608                     .equals( "SOYBN" ) ) {
4609                 return false;
4610             }
4611             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4612                     .equals( "SOYBN" ) ) {
4613                 return false;
4614             }
4615             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4616                     .equals( "SOYBN" ) ) {
4617                 return false;
4618             }
4619             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4620                     .equals( "SOYBN" ) ) {
4621                 return false;
4622             }
4623             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4624                     .equals( "SOYBN" ) ) {
4625                 return false;
4626             }
4627             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4628                     .equals( "SOYBN" ) ) {
4629                 return false;
4630             }
4631             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4632                     .equals( "SOYBN" ) ) {
4633                 return false;
4634             }
4635             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4636                 return false;
4637             }
4638             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4639                     .equals( "SOYBN" ) ) {
4640                 return false;
4641             }
4642             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4643                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4644                 return false;
4645             }
4646             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4647                     .equals( "9YX45" ) ) {
4648                 return false;
4649             }
4650             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4651                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4652                                                                .equals( "MOUSE" ) ) {
4653                 return false;
4654             }
4655             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4656                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4657                                                                .equals( "MOUSE" ) ) {
4658                 return false;
4659             }
4660             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4661                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4662                                                                .equals( "MOUSE" ) ) {
4663                 return false;
4664             }
4665             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4666                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4667                 return false;
4668             }
4669             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4670                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4674                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4675                 return false;
4676             }
4677             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4678                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4679                 return false;
4680             }
4681             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4682                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4683                 return false;
4684             }
4685             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4686                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4687                 return false;
4688             }
4689             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4690                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4691                 return false;
4692             }
4693             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4694                     .equals( "RAT" ) ) {
4695                 return false;
4696             }
4697             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4698                     .equals( "PIG" ) ) {
4699                 return false;
4700             }
4701             if ( !ParserUtils
4702                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4703                     .equals( "MOUSE" ) ) {
4704                 return false;
4705             }
4706             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4707                     .equals( "MOUSE" ) ) {
4708                 return false;
4709             }
4710             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4711                 return false;
4712             }
4713         }
4714         catch ( final Exception e ) {
4715             e.printStackTrace( System.out );
4716             return false;
4717         }
4718         return true;
4719     }
4720
4721     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4722         try {
4723             PhylogenyNode n = new PhylogenyNode();
4724             n.setName( "tr|B3RJ64" );
4725             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4726                 return false;
4727             }
4728             n.setName( "tr.B3RJ64" );
4729             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4730                 return false;
4731             }
4732             n.setName( "tr=B3RJ64" );
4733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4734                 return false;
4735             }
4736             n.setName( "tr-B3RJ64" );
4737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4738                 return false;
4739             }
4740             n.setName( "tr/B3RJ64" );
4741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4742                 return false;
4743             }
4744             n.setName( "tr\\B3RJ64" );
4745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4746                 return false;
4747             }
4748             n.setName( "tr_B3RJ64" );
4749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4750                 return false;
4751             }
4752             n.setName( " tr|B3RJ64 " );
4753             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4754                 return false;
4755             }
4756             n.setName( "-tr|B3RJ64-" );
4757             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4758                 return false;
4759             }
4760             n.setName( "-tr=B3RJ64-" );
4761             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4762                 return false;
4763             }
4764             n.setName( "_tr=B3RJ64_" );
4765             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4766                 return false;
4767             }
4768             n.setName( " tr_tr|B3RJ64_sp|123 " );
4769             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4770                 return false;
4771             }
4772             n.setName( "B3RJ64" );
4773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4774                 return false;
4775             }
4776             n.setName( "sp|B3RJ64" );
4777             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4778                 return false;
4779             }
4780             n.setName( "sp|B3RJ64C" );
4781             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4782                 return false;
4783             }
4784             n.setName( "sp B3RJ64" );
4785             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4786                 return false;
4787             }
4788             n.setName( "sp|B3RJ6X" );
4789             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4790                 return false;
4791             }
4792             n.setName( "sp|B3RJ6" );
4793             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4794                 return false;
4795             }
4796             n.setName( "K1PYK7_CRAGI" );
4797             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4798                 return false;
4799             }
4800             n.setName( "K1PYK7_PEA" );
4801             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4802                 return false;
4803             }
4804             n.setName( "K1PYK7_RAT" );
4805             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4806                 return false;
4807             }
4808             n.setName( "K1PYK7_PIG" );
4809             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4810                 return false;
4811             }
4812             n.setName( "~K1PYK7_PIG~" );
4813             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4814                 return false;
4815             }
4816             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4817             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4818                 return false;
4819             }
4820             n.setName( "K1PYKX_CRAGI" );
4821             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4822                 return false;
4823             }
4824             n.setName( "XXXXX_CRAGI" );
4825             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4826                 return false;
4827             }
4828             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4829             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4830                 return false;
4831             }
4832             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4833             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4834                 return false;
4835             }
4836             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4837             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4838                 return false;
4839             }
4840             n = new PhylogenyNode();
4841             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4842             seq.setSymbol( "K1PYK7_CRAGI" );
4843             n.getNodeData().addSequence( seq );
4844             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4845                 return false;
4846             }
4847             seq.setSymbol( "tr|B3RJ64" );
4848             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4849                 return false;
4850             }
4851             n = new PhylogenyNode();
4852             seq = new org.forester.phylogeny.data.Sequence();
4853             seq.setName( "K1PYK7_CRAGI" );
4854             n.getNodeData().addSequence( seq );
4855             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4856                 return false;
4857             }
4858             seq.setName( "tr|B3RJ64" );
4859             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4860                 return false;
4861             }
4862             n = new PhylogenyNode();
4863             seq = new org.forester.phylogeny.data.Sequence();
4864             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4865             n.getNodeData().addSequence( seq );
4866             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4867                 return false;
4868             }
4869             n = new PhylogenyNode();
4870             seq = new org.forester.phylogeny.data.Sequence();
4871             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4872             n.getNodeData().addSequence( seq );
4873             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4874                 return false;
4875             }
4876             //
4877             n = new PhylogenyNode();
4878             n.setName( "ACP19736" );
4879             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4880                 return false;
4881             }
4882             n = new PhylogenyNode();
4883             n.setName( "|ACP19736|" );
4884             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4885                 return false;
4886             }
4887         }
4888         catch ( final Exception e ) {
4889             e.printStackTrace( System.out );
4890             return false;
4891         }
4892         return true;
4893     }
4894
4895     private static boolean testFastaParser() {
4896         try {
4897             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4898                 return false;
4899             }
4900             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4901                 return false;
4902             }
4903             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4904             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4905                 return false;
4906             }
4907             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4908                 return false;
4909             }
4910             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4911                 return false;
4912             }
4913             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4914                 return false;
4915             }
4916             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4917                 return false;
4918             }
4919             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4920                 return false;
4921             }
4922         }
4923         catch ( final Exception e ) {
4924             e.printStackTrace();
4925             return false;
4926         }
4927         return true;
4928     }
4929
4930     private static boolean testGenbankAccessorParsing() {
4931         //The format for GenBank Accession numbers are:
4932         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4933         //Protein:    3 letters + 5 numerals
4934         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4935         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4936             return false;
4937         }
4938         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4939             return false;
4940         }
4941         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4942             return false;
4943         }
4944         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4945             return false;
4946         }
4947         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4948             return false;
4949         }
4950         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4951             return false;
4952         }
4953         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4954             return false;
4955         }
4956         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4957             return false;
4958         }
4959         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4960             return false;
4961         }
4962         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4963             return false;
4964         }
4965         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4966             return false;
4967         }
4968         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4969             return false;
4970         }
4971         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4972             return false;
4973         }
4974         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4975             return false;
4976         }
4977         return true;
4978     }
4979
4980     private static boolean testGeneralMsaParser() {
4981         try {
4982             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4983             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4984             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4985             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4986             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4987             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4988             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4989             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4990             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4991                 return false;
4992             }
4993             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4994                 return false;
4995             }
4996             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4997                 return false;
4998             }
4999             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5000                 return false;
5001             }
5002             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5003                 return false;
5004             }
5005             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5006                 return false;
5007             }
5008             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5009                 return false;
5010             }
5011             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5012                 return false;
5013             }
5014             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5015                 return false;
5016             }
5017             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5018                 return false;
5019             }
5020             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5021                 return false;
5022             }
5023             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5024                 return false;
5025             }
5026             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5027             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5028                 return false;
5029             }
5030             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5031                 return false;
5032             }
5033             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5034                 return false;
5035             }
5036             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5037             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5038                 return false;
5039             }
5040             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5041                 return false;
5042             }
5043             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5044                 return false;
5045             }
5046             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5047             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5048                 return false;
5049             }
5050             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5051                 return false;
5052             }
5053             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5054                 return false;
5055             }
5056         }
5057         catch ( final Exception e ) {
5058             e.printStackTrace();
5059             return false;
5060         }
5061         return true;
5062     }
5063
5064     private static boolean testGeneralTable() {
5065         try {
5066             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5067             t0.setValue( 3, 2, "23" );
5068             t0.setValue( 10, 1, "error" );
5069             t0.setValue( 10, 1, "110" );
5070             t0.setValue( 9, 1, "19" );
5071             t0.setValue( 1, 10, "101" );
5072             t0.setValue( 10, 10, "1010" );
5073             t0.setValue( 100, 10, "10100" );
5074             t0.setValue( 0, 0, "00" );
5075             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5076                 return false;
5077             }
5078             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5079                 return false;
5080             }
5081             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5082                 return false;
5083             }
5084             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5085                 return false;
5086             }
5087             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5088                 return false;
5089             }
5090             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5091                 return false;
5092             }
5093             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5094                 return false;
5095             }
5096             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5097                 return false;
5098             }
5099             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5100                 return false;
5101             }
5102             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5103             t1.setValue( "3", "2", "23" );
5104             t1.setValue( "10", "1", "error" );
5105             t1.setValue( "10", "1", "110" );
5106             t1.setValue( "9", "1", "19" );
5107             t1.setValue( "1", "10", "101" );
5108             t1.setValue( "10", "10", "1010" );
5109             t1.setValue( "100", "10", "10100" );
5110             t1.setValue( "0", "0", "00" );
5111             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5112             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5113                 return false;
5114             }
5115             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5116                 return false;
5117             }
5118             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5119                 return false;
5120             }
5121             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5122                 return false;
5123             }
5124             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5125                 return false;
5126             }
5127             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5128                 return false;
5129             }
5130             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5131                 return false;
5132             }
5133             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5134                 return false;
5135             }
5136             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5137                 return false;
5138             }
5139             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5140                 return false;
5141             }
5142         }
5143         catch ( final Exception e ) {
5144             e.printStackTrace( System.out );
5145             return false;
5146         }
5147         return true;
5148     }
5149
5150     private static boolean testGetDistance() {
5151         try {
5152             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5153             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",
5154                                                  new NHXParser() )[ 0 ];
5155             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5156                 return false;
5157             }
5158             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5159                 return false;
5160             }
5161             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5162                 return false;
5163             }
5164             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5165                 return false;
5166             }
5167             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5168                 return false;
5169             }
5170             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5171                 return false;
5172             }
5173             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5174                 return false;
5175             }
5176             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5177                 return false;
5178             }
5179             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5180                 return false;
5181             }
5182             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5183                 return false;
5184             }
5185             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5186                 return false;
5187             }
5188             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5189                 return false;
5190             }
5191             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5192                 return false;
5193             }
5194             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5195                 return false;
5196             }
5197             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5198                 return false;
5199             }
5200             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5201                 return false;
5202             }
5203             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5204                 return false;
5205             }
5206             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5207                 return false;
5208             }
5209             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5210                 return false;
5211             }
5212             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5213                 return false;
5214             }
5215             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5216                 return false;
5217             }
5218             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5219                 return false;
5220             }
5221             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5222                 return false;
5223             }
5224             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5225                 return false;
5226             }
5227             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5228                 return false;
5229             }
5230             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5231                 return false;
5232             }
5233             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5234                 return false;
5235             }
5236             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5237                 return false;
5238             }
5239             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5240                 return false;
5241             }
5242             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5243                 return false;
5244             }
5245             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5246                 return false;
5247             }
5248             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",
5249                                                  new NHXParser() )[ 0 ];
5250             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5251                 return false;
5252             }
5253             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5254                 return false;
5255             }
5256             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5257                 return false;
5258             }
5259             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5260                 return false;
5261             }
5262             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5263                 return false;
5264             }
5265             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5266                 return false;
5267             }
5268             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5269                 return false;
5270             }
5271             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5272                 return false;
5273             }
5274             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5275                 return false;
5276             }
5277             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5278                 return false;
5279             }
5280             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5281                 return false;
5282             }
5283         }
5284         catch ( final Exception e ) {
5285             e.printStackTrace( System.out );
5286             return false;
5287         }
5288         return true;
5289     }
5290
5291     private static boolean testGetLCA() {
5292         try {
5293             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5294             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5295                                                  new NHXParser() )[ 0 ];
5296             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5297             if ( !A.getName().equals( "A" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5301             if ( !gh.getName().equals( "gh" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5305             if ( !ab.getName().equals( "ab" ) ) {
5306                 return false;
5307             }
5308             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5309             if ( !ab2.getName().equals( "ab" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5313             if ( !gh2.getName().equals( "gh" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5317             if ( !gh3.getName().equals( "gh" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5321             if ( !abc.getName().equals( "abc" ) ) {
5322                 return false;
5323             }
5324             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5325             if ( !abc2.getName().equals( "abc" ) ) {
5326                 return false;
5327             }
5328             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5329             if ( !abcd.getName().equals( "abcd" ) ) {
5330                 return false;
5331             }
5332             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5333             if ( !abcd2.getName().equals( "abcd" ) ) {
5334                 return false;
5335             }
5336             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5337             if ( !abcdef.getName().equals( "abcdef" ) ) {
5338                 return false;
5339             }
5340             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5341             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5342                 return false;
5343             }
5344             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5345             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5346                 return false;
5347             }
5348             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5349             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5350                 return false;
5351             }
5352             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5353             if ( !abcde.getName().equals( "abcde" ) ) {
5354                 return false;
5355             }
5356             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5357             if ( !abcde2.getName().equals( "abcde" ) ) {
5358                 return false;
5359             }
5360             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5361             if ( !r.getName().equals( "abcdefgh" ) ) {
5362                 return false;
5363             }
5364             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5365             if ( !r2.getName().equals( "abcdefgh" ) ) {
5366                 return false;
5367             }
5368             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5369             if ( !r3.getName().equals( "abcdefgh" ) ) {
5370                 return false;
5371             }
5372             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5373             if ( !abcde3.getName().equals( "abcde" ) ) {
5374                 return false;
5375             }
5376             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5377             if ( !abcde4.getName().equals( "abcde" ) ) {
5378                 return false;
5379             }
5380             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5381             if ( !ab3.getName().equals( "ab" ) ) {
5382                 return false;
5383             }
5384             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5385             if ( !ab4.getName().equals( "ab" ) ) {
5386                 return false;
5387             }
5388             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5389             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5390             if ( !cd.getName().equals( "cd" ) ) {
5391                 return false;
5392             }
5393             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5394             if ( !cd2.getName().equals( "cd" ) ) {
5395                 return false;
5396             }
5397             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5398             if ( !cde.getName().equals( "cde" ) ) {
5399                 return false;
5400             }
5401             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5402             if ( !cde2.getName().equals( "cde" ) ) {
5403                 return false;
5404             }
5405             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5406             if ( !cdef.getName().equals( "cdef" ) ) {
5407                 return false;
5408             }
5409             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5410             if ( !cdef2.getName().equals( "cdef" ) ) {
5411                 return false;
5412             }
5413             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5414             if ( !cdef3.getName().equals( "cdef" ) ) {
5415                 return false;
5416             }
5417             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5418             if ( !rt.getName().equals( "r" ) ) {
5419                 return false;
5420             }
5421             final Phylogeny p3 = factory
5422                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5423                              new NHXParser() )[ 0 ];
5424             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5425             if ( !bc_3.getName().equals( "bc" ) ) {
5426                 return false;
5427             }
5428             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5429             if ( !ac_3.getName().equals( "abc" ) ) {
5430                 return false;
5431             }
5432             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5433             if ( !ad_3.getName().equals( "abcde" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5437             if ( !af_3.getName().equals( "abcdef" ) ) {
5438                 return false;
5439             }
5440             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5441             if ( !ag_3.getName().equals( "" ) ) {
5442                 return false;
5443             }
5444             if ( !ag_3.isRoot() ) {
5445                 return false;
5446             }
5447             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5448             if ( !al_3.getName().equals( "" ) ) {
5449                 return false;
5450             }
5451             if ( !al_3.isRoot() ) {
5452                 return false;
5453             }
5454             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5455             if ( !kl_3.getName().equals( "" ) ) {
5456                 return false;
5457             }
5458             if ( !kl_3.isRoot() ) {
5459                 return false;
5460             }
5461             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5462             if ( !fl_3.getName().equals( "" ) ) {
5463                 return false;
5464             }
5465             if ( !fl_3.isRoot() ) {
5466                 return false;
5467             }
5468             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5469             if ( !gk_3.getName().equals( "ghijk" ) ) {
5470                 return false;
5471             }
5472             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5473             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5474             if ( !r_4.getName().equals( "r" ) ) {
5475                 return false;
5476             }
5477             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5478             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5479             if ( !r_5.getName().equals( "root" ) ) {
5480                 return false;
5481             }
5482             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5483             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5484             if ( !r_6.getName().equals( "rot" ) ) {
5485                 return false;
5486             }
5487             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5488             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5489             if ( !r_7.getName().equals( "rott" ) ) {
5490                 return false;
5491             }
5492         }
5493         catch ( final Exception e ) {
5494             e.printStackTrace( System.out );
5495             return false;
5496         }
5497         return true;
5498     }
5499
5500     private static boolean testGetLCA2() {
5501         try {
5502             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5503             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5504             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5505             PhylogenyMethods.preOrderReId( p_a );
5506             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5507                                                                                               p_a.getNode( "a" ) );
5508             if ( !p_a_1.getName().equals( "a" ) ) {
5509                 return false;
5510             }
5511             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5512             PhylogenyMethods.preOrderReId( p_b );
5513             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5514                                                                                               p_b.getNode( "a" ) );
5515             if ( !p_b_1.getName().equals( "b" ) ) {
5516                 return false;
5517             }
5518             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5519                                                                                               p_b.getNode( "b" ) );
5520             if ( !p_b_2.getName().equals( "b" ) ) {
5521                 return false;
5522             }
5523             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5524             PhylogenyMethods.preOrderReId( p_c );
5525             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5526                                                                                               p_c.getNode( "a" ) );
5527             if ( !p_c_1.getName().equals( "b" ) ) {
5528                 return false;
5529             }
5530             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5531                                                                                               p_c.getNode( "c" ) );
5532             if ( !p_c_2.getName().equals( "c" ) ) {
5533                 System.out.println( p_c_2.getName() );
5534                 System.exit( -1 );
5535                 return false;
5536             }
5537             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5538                                                                                               p_c.getNode( "b" ) );
5539             if ( !p_c_3.getName().equals( "b" ) ) {
5540                 return false;
5541             }
5542             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5543                                                                                               p_c.getNode( "a" ) );
5544             if ( !p_c_4.getName().equals( "c" ) ) {
5545                 return false;
5546             }
5547             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5548                                                  new NHXParser() )[ 0 ];
5549             PhylogenyMethods.preOrderReId( p1 );
5550             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5551                                                                                           p1.getNode( "A" ) );
5552             if ( !A.getName().equals( "A" ) ) {
5553                 return false;
5554             }
5555             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5556                                                                                            p1.getNode( "gh" ) );
5557             if ( !gh.getName().equals( "gh" ) ) {
5558                 return false;
5559             }
5560             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5561                                                                                            p1.getNode( "B" ) );
5562             if ( !ab.getName().equals( "ab" ) ) {
5563                 return false;
5564             }
5565             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5566                                                                                             p1.getNode( "A" ) );
5567             if ( !ab2.getName().equals( "ab" ) ) {
5568                 return false;
5569             }
5570             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5571                                                                                             p1.getNode( "G" ) );
5572             if ( !gh2.getName().equals( "gh" ) ) {
5573                 return false;
5574             }
5575             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5576                                                                                             p1.getNode( "H" ) );
5577             if ( !gh3.getName().equals( "gh" ) ) {
5578                 return false;
5579             }
5580             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5581                                                                                             p1.getNode( "A" ) );
5582             if ( !abc.getName().equals( "abc" ) ) {
5583                 return false;
5584             }
5585             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5586                                                                                              p1.getNode( "C" ) );
5587             if ( !abc2.getName().equals( "abc" ) ) {
5588                 return false;
5589             }
5590             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5591                                                                                              p1.getNode( "D" ) );
5592             if ( !abcd.getName().equals( "abcd" ) ) {
5593                 return false;
5594             }
5595             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5596                                                                                               p1.getNode( "A" ) );
5597             if ( !abcd2.getName().equals( "abcd" ) ) {
5598                 return false;
5599             }
5600             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5601                                                                                                p1.getNode( "F" ) );
5602             if ( !abcdef.getName().equals( "abcdef" ) ) {
5603                 return false;
5604             }
5605             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5606                                                                                                 p1.getNode( "A" ) );
5607             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5608                 return false;
5609             }
5610             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5611                                                                                                 p1.getNode( "F" ) );
5612             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5613                 return false;
5614             }
5615             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5616                                                                                                 p1.getNode( "ab" ) );
5617             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5618                 return false;
5619             }
5620             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5621                                                                                               p1.getNode( "E" ) );
5622             if ( !abcde.getName().equals( "abcde" ) ) {
5623                 return false;
5624             }
5625             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5626                                                                                                p1.getNode( "A" ) );
5627             if ( !abcde2.getName().equals( "abcde" ) ) {
5628                 return false;
5629             }
5630             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5631                                                                                           p1.getNode( "abcdefgh" ) );
5632             if ( !r.getName().equals( "abcdefgh" ) ) {
5633                 return false;
5634             }
5635             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5636                                                                                            p1.getNode( "H" ) );
5637             if ( !r2.getName().equals( "abcdefgh" ) ) {
5638                 return false;
5639             }
5640             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5641                                                                                            p1.getNode( "A" ) );
5642             if ( !r3.getName().equals( "abcdefgh" ) ) {
5643                 return false;
5644             }
5645             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5646                                                                                                p1.getNode( "abcde" ) );
5647             if ( !abcde3.getName().equals( "abcde" ) ) {
5648                 return false;
5649             }
5650             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5651                                                                                                p1.getNode( "E" ) );
5652             if ( !abcde4.getName().equals( "abcde" ) ) {
5653                 return false;
5654             }
5655             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5656                                                                                             p1.getNode( "B" ) );
5657             if ( !ab3.getName().equals( "ab" ) ) {
5658                 return false;
5659             }
5660             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5661                                                                                             p1.getNode( "ab" ) );
5662             if ( !ab4.getName().equals( "ab" ) ) {
5663                 return false;
5664             }
5665             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5666             PhylogenyMethods.preOrderReId( p2 );
5667             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5668                                                                                            p2.getNode( "d" ) );
5669             if ( !cd.getName().equals( "cd" ) ) {
5670                 return false;
5671             }
5672             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5673                                                                                             p2.getNode( "c" ) );
5674             if ( !cd2.getName().equals( "cd" ) ) {
5675                 return false;
5676             }
5677             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5678                                                                                             p2.getNode( "e" ) );
5679             if ( !cde.getName().equals( "cde" ) ) {
5680                 return false;
5681             }
5682             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5683                                                                                              p2.getNode( "c" ) );
5684             if ( !cde2.getName().equals( "cde" ) ) {
5685                 return false;
5686             }
5687             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5688                                                                                              p2.getNode( "f" ) );
5689             if ( !cdef.getName().equals( "cdef" ) ) {
5690                 return false;
5691             }
5692             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5693                                                                                               p2.getNode( "f" ) );
5694             if ( !cdef2.getName().equals( "cdef" ) ) {
5695                 return false;
5696             }
5697             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5698                                                                                               p2.getNode( "d" ) );
5699             if ( !cdef3.getName().equals( "cdef" ) ) {
5700                 return false;
5701             }
5702             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5703                                                                                            p2.getNode( "a" ) );
5704             if ( !rt.getName().equals( "r" ) ) {
5705                 return false;
5706             }
5707             final Phylogeny p3 = factory
5708                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5709                              new NHXParser() )[ 0 ];
5710             PhylogenyMethods.preOrderReId( p3 );
5711             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5712                                                                                              p3.getNode( "c" ) );
5713             if ( !bc_3.getName().equals( "bc" ) ) {
5714                 return false;
5715             }
5716             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5717                                                                                              p3.getNode( "c" ) );
5718             if ( !ac_3.getName().equals( "abc" ) ) {
5719                 return false;
5720             }
5721             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5722                                                                                              p3.getNode( "d" ) );
5723             if ( !ad_3.getName().equals( "abcde" ) ) {
5724                 return false;
5725             }
5726             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5727                                                                                              p3.getNode( "f" ) );
5728             if ( !af_3.getName().equals( "abcdef" ) ) {
5729                 return false;
5730             }
5731             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5732                                                                                              p3.getNode( "g" ) );
5733             if ( !ag_3.getName().equals( "" ) ) {
5734                 return false;
5735             }
5736             if ( !ag_3.isRoot() ) {
5737                 return false;
5738             }
5739             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5740                                                                                              p3.getNode( "l" ) );
5741             if ( !al_3.getName().equals( "" ) ) {
5742                 return false;
5743             }
5744             if ( !al_3.isRoot() ) {
5745                 return false;
5746             }
5747             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5748                                                                                              p3.getNode( "l" ) );
5749             if ( !kl_3.getName().equals( "" ) ) {
5750                 return false;
5751             }
5752             if ( !kl_3.isRoot() ) {
5753                 return false;
5754             }
5755             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5756                                                                                              p3.getNode( "l" ) );
5757             if ( !fl_3.getName().equals( "" ) ) {
5758                 return false;
5759             }
5760             if ( !fl_3.isRoot() ) {
5761                 return false;
5762             }
5763             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5764                                                                                              p3.getNode( "k" ) );
5765             if ( !gk_3.getName().equals( "ghijk" ) ) {
5766                 return false;
5767             }
5768             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5769             PhylogenyMethods.preOrderReId( p4 );
5770             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5771                                                                                             p4.getNode( "c" ) );
5772             if ( !r_4.getName().equals( "r" ) ) {
5773                 return false;
5774             }
5775             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5776             PhylogenyMethods.preOrderReId( p5 );
5777             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5778                                                                                             p5.getNode( "c" ) );
5779             if ( !r_5.getName().equals( "root" ) ) {
5780                 return false;
5781             }
5782             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5783             PhylogenyMethods.preOrderReId( p6 );
5784             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5785                                                                                             p6.getNode( "a" ) );
5786             if ( !r_6.getName().equals( "rot" ) ) {
5787                 return false;
5788             }
5789             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5790             PhylogenyMethods.preOrderReId( p7 );
5791             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5792                                                                                             p7.getNode( "e" ) );
5793             if ( !r_7.getName().equals( "rott" ) ) {
5794                 return false;
5795             }
5796             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5797                                                                                              p7.getNode( "a" ) );
5798             if ( !r_71.getName().equals( "rott" ) ) {
5799                 return false;
5800             }
5801             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5802                                                                                              p7.getNode( "rott" ) );
5803             if ( !r_72.getName().equals( "rott" ) ) {
5804                 return false;
5805             }
5806             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5807                                                                                              p7.getNode( "a" ) );
5808             if ( !r_73.getName().equals( "rott" ) ) {
5809                 return false;
5810             }
5811             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5812                                                                                              p7.getNode( "rott" ) );
5813             if ( !r_74.getName().equals( "rott" ) ) {
5814                 return false;
5815             }
5816             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5817                                                                                              p7.getNode( "e" ) );
5818             if ( !r_75.getName().equals( "e" ) ) {
5819                 return false;
5820             }
5821         }
5822         catch ( final Exception e ) {
5823             e.printStackTrace( System.out );
5824             return false;
5825         }
5826         return true;
5827     }
5828
5829     private static boolean testHmmscanOutputParser() {
5830         final String test_dir = Test.PATH_TO_TEST_DATA;
5831         try {
5832             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5833                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5834             parser1.parse();
5835             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5836                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5837             final List<Protein> proteins = parser2.parse();
5838             if ( parser2.getProteinsEncountered() != 4 ) {
5839                 return false;
5840             }
5841             if ( proteins.size() != 4 ) {
5842                 return false;
5843             }
5844             if ( parser2.getDomainsEncountered() != 69 ) {
5845                 return false;
5846             }
5847             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5848                 return false;
5849             }
5850             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5851                 return false;
5852             }
5853             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5854                 return false;
5855             }
5856             final Protein p1 = proteins.get( 0 );
5857             if ( p1.getNumberOfProteinDomains() != 15 ) {
5858                 return false;
5859             }
5860             if ( p1.getLength() != 850 ) {
5861                 return false;
5862             }
5863             final Protein p2 = proteins.get( 1 );
5864             if ( p2.getNumberOfProteinDomains() != 51 ) {
5865                 return false;
5866             }
5867             if ( p2.getLength() != 1291 ) {
5868                 return false;
5869             }
5870             final Protein p3 = proteins.get( 2 );
5871             if ( p3.getNumberOfProteinDomains() != 2 ) {
5872                 return false;
5873             }
5874             final Protein p4 = proteins.get( 3 );
5875             if ( p4.getNumberOfProteinDomains() != 1 ) {
5876                 return false;
5877             }
5878             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5879                 return false;
5880             }
5881             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5882                 return false;
5883             }
5884             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5885                 return false;
5886             }
5887             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5888                 return false;
5889             }
5890             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5891                 return false;
5892             }
5893             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5894                 return false;
5895             }
5896             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5897                 return false;
5898             }
5899         }
5900         catch ( final Exception e ) {
5901             e.printStackTrace( System.out );
5902             return false;
5903         }
5904         return true;
5905     }
5906
5907     private static boolean testLastExternalNodeMethods() {
5908         try {
5909             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5910             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5911             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5912             final PhylogenyNode n1 = t0.getNode( "A" );
5913             if ( n1.isLastExternalNode() ) {
5914                 return false;
5915             }
5916             final PhylogenyNode n2 = t0.getNode( "B" );
5917             if ( n2.isLastExternalNode() ) {
5918                 return false;
5919             }
5920             final PhylogenyNode n3 = t0.getNode( "C" );
5921             if ( n3.isLastExternalNode() ) {
5922                 return false;
5923             }
5924             final PhylogenyNode n4 = t0.getNode( "D" );
5925             if ( !n4.isLastExternalNode() ) {
5926                 return false;
5927             }
5928         }
5929         catch ( final Exception e ) {
5930             e.printStackTrace( System.out );
5931             return false;
5932         }
5933         return true;
5934     }
5935
5936     private static boolean testLevelOrderIterator() {
5937         try {
5938             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5939             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5940             PhylogenyNodeIterator it0;
5941             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5942                 it0.next();
5943             }
5944             for( it0.reset(); it0.hasNext(); ) {
5945                 it0.next();
5946             }
5947             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5948             if ( !it.next().getName().equals( "r" ) ) {
5949                 return false;
5950             }
5951             if ( !it.next().getName().equals( "ab" ) ) {
5952                 return false;
5953             }
5954             if ( !it.next().getName().equals( "cd" ) ) {
5955                 return false;
5956             }
5957             if ( !it.next().getName().equals( "A" ) ) {
5958                 return false;
5959             }
5960             if ( !it.next().getName().equals( "B" ) ) {
5961                 return false;
5962             }
5963             if ( !it.next().getName().equals( "C" ) ) {
5964                 return false;
5965             }
5966             if ( !it.next().getName().equals( "D" ) ) {
5967                 return false;
5968             }
5969             if ( it.hasNext() ) {
5970                 return false;
5971             }
5972             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",
5973                                                  new NHXParser() )[ 0 ];
5974             PhylogenyNodeIterator it2;
5975             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5976                 it2.next();
5977             }
5978             for( it2.reset(); it2.hasNext(); ) {
5979                 it2.next();
5980             }
5981             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5982             if ( !it3.next().getName().equals( "r" ) ) {
5983                 return false;
5984             }
5985             if ( !it3.next().getName().equals( "abc" ) ) {
5986                 return false;
5987             }
5988             if ( !it3.next().getName().equals( "defg" ) ) {
5989                 return false;
5990             }
5991             if ( !it3.next().getName().equals( "A" ) ) {
5992                 return false;
5993             }
5994             if ( !it3.next().getName().equals( "B" ) ) {
5995                 return false;
5996             }
5997             if ( !it3.next().getName().equals( "C" ) ) {
5998                 return false;
5999             }
6000             if ( !it3.next().getName().equals( "D" ) ) {
6001                 return false;
6002             }
6003             if ( !it3.next().getName().equals( "E" ) ) {
6004                 return false;
6005             }
6006             if ( !it3.next().getName().equals( "F" ) ) {
6007                 return false;
6008             }
6009             if ( !it3.next().getName().equals( "G" ) ) {
6010                 return false;
6011             }
6012             if ( !it3.next().getName().equals( "1" ) ) {
6013                 return false;
6014             }
6015             if ( !it3.next().getName().equals( "2" ) ) {
6016                 return false;
6017             }
6018             if ( !it3.next().getName().equals( "3" ) ) {
6019                 return false;
6020             }
6021             if ( !it3.next().getName().equals( "4" ) ) {
6022                 return false;
6023             }
6024             if ( !it3.next().getName().equals( "5" ) ) {
6025                 return false;
6026             }
6027             if ( !it3.next().getName().equals( "6" ) ) {
6028                 return false;
6029             }
6030             if ( !it3.next().getName().equals( "f1" ) ) {
6031                 return false;
6032             }
6033             if ( !it3.next().getName().equals( "f2" ) ) {
6034                 return false;
6035             }
6036             if ( !it3.next().getName().equals( "f3" ) ) {
6037                 return false;
6038             }
6039             if ( !it3.next().getName().equals( "a" ) ) {
6040                 return false;
6041             }
6042             if ( !it3.next().getName().equals( "b" ) ) {
6043                 return false;
6044             }
6045             if ( !it3.next().getName().equals( "f21" ) ) {
6046                 return false;
6047             }
6048             if ( !it3.next().getName().equals( "X" ) ) {
6049                 return false;
6050             }
6051             if ( !it3.next().getName().equals( "Y" ) ) {
6052                 return false;
6053             }
6054             if ( !it3.next().getName().equals( "Z" ) ) {
6055                 return false;
6056             }
6057             if ( it3.hasNext() ) {
6058                 return false;
6059             }
6060             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6061             PhylogenyNodeIterator it4;
6062             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6063                 it4.next();
6064             }
6065             for( it4.reset(); it4.hasNext(); ) {
6066                 it4.next();
6067             }
6068             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6069             if ( !it5.next().getName().equals( "r" ) ) {
6070                 return false;
6071             }
6072             if ( !it5.next().getName().equals( "A" ) ) {
6073                 return false;
6074             }
6075             if ( !it5.next().getName().equals( "B" ) ) {
6076                 return false;
6077             }
6078             if ( !it5.next().getName().equals( "C" ) ) {
6079                 return false;
6080             }
6081             if ( !it5.next().getName().equals( "D" ) ) {
6082                 return false;
6083             }
6084             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6085             PhylogenyNodeIterator it6;
6086             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6087                 it6.next();
6088             }
6089             for( it6.reset(); it6.hasNext(); ) {
6090                 it6.next();
6091             }
6092             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6093             if ( !it7.next().getName().equals( "A" ) ) {
6094                 return false;
6095             }
6096             if ( it.hasNext() ) {
6097                 return false;
6098             }
6099         }
6100         catch ( final Exception e ) {
6101             e.printStackTrace( System.out );
6102             return false;
6103         }
6104         return true;
6105     }
6106
6107     private static boolean testMafft( final String path ) {
6108         try {
6109             final List<String> opts = new ArrayList<String>();
6110             opts.add( "--maxiterate" );
6111             opts.add( "1000" );
6112             opts.add( "--localpair" );
6113             opts.add( "--quiet" );
6114             Msa msa = null;
6115             final MsaInferrer mafft = Mafft.createInstance( path );
6116             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6117             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6118                 return false;
6119             }
6120             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6121                 return false;
6122             }
6123         }
6124         catch ( final Exception e ) {
6125             e.printStackTrace( System.out );
6126             return false;
6127         }
6128         return true;
6129     }
6130
6131     private static boolean testMidpointrooting() {
6132         try {
6133             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6134             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6135             PhylogenyMethods.midpointRoot( t0 );
6136             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6137                 return false;
6138             }
6139             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6140                 return false;
6141             }
6142             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6143                            1 ) ) {
6144                 return false;
6145             }
6146             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",
6147                                                  new NHXParser() )[ 0 ];
6148             if ( !t1.isRooted() ) {
6149                 return false;
6150             }
6151             PhylogenyMethods.midpointRoot( t1 );
6152             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6153                 return false;
6154             }
6155             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6156                 return false;
6157             }
6158             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6159                 return false;
6160             }
6161             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6162                 return false;
6163             }
6164             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6165                 return false;
6166             }
6167             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6168                 return false;
6169             }
6170             t1.reRoot( t1.getNode( "A" ) );
6171             PhylogenyMethods.midpointRoot( t1 );
6172             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6173                 return false;
6174             }
6175             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6176                 return false;
6177             }
6178             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6179                 return false;
6180             }
6181             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6182                 return false;
6183             }
6184             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6185                 System.exit( -1 );
6186                 return false;
6187             }
6188             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6189                 return false;
6190             }
6191         }
6192         catch ( final Exception e ) {
6193             e.printStackTrace( System.out );
6194             return false;
6195         }
6196         return true;
6197     }
6198
6199     private static boolean testMsaQualityMethod() {
6200         try {
6201             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6202             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6203             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6204             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6205             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6206             l.add( s0 );
6207             l.add( s1 );
6208             l.add( s2 );
6209             l.add( s3 );
6210             final Msa msa = BasicMsa.createInstance( l );
6211             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6212                 return false;
6213             }
6214             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6215                 return false;
6216             }
6217             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6218                 return false;
6219             }
6220             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6221                 return false;
6222             }
6223             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6224                 return false;
6225             }
6226             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6227                 return false;
6228             }
6229             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6230                 return false;
6231             }
6232         }
6233         catch ( final Exception e ) {
6234             e.printStackTrace( System.out );
6235             return false;
6236         }
6237         return true;
6238     }
6239
6240     private static boolean testMsaEntropy() {
6241         try {
6242             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6243             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6244             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6245             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6246             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6247             l.add( s0 );
6248             l.add( s1 );
6249             l.add( s2 );
6250             l.add( s3 );
6251             final Msa msa = BasicMsa.createInstance( l );
6252             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6253             //FIXME
6254             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6255             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6256             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6257             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6258             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6259             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6260             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6261             //            System.out.println();
6262             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6263             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6264             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6265             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6266             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6267             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6268             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6269             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6270             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6271             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6272             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6273             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6274             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6275             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6276             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6277             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6278             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6279             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6280             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6281             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6282             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6283             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6284             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6285             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6286             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6287             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6288             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6289             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6290             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6291             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6292             final Msa msa2 = BasicMsa.createInstance( l2 );
6293             //            System.out.println();
6294             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6295             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6296             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6297         }
6298         catch ( final Exception e ) {
6299             e.printStackTrace( System.out );
6300             return false;
6301         }
6302         return true;
6303     }
6304
6305     private static boolean testDeleteableMsa() {
6306         try {
6307             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6308             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6309             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6310             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6311             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6312             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6313             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6314             l0.add( s0 );
6315             l0.add( s1 );
6316             l0.add( s2 );
6317             l0.add( s3 );
6318             l0.add( s4 );
6319             l0.add( s5 );
6320             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6321             dmsa0.deleteRow( "b", false );
6322             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6323                 return false;
6324             }
6325             dmsa0.deleteRow( "e", false );
6326             dmsa0.deleteRow( "a", false );
6327             dmsa0.deleteRow( "f", false );
6328             if ( dmsa0.getLength() != 4 ) {
6329                 return false;
6330             }
6331             if ( dmsa0.getNumberOfSequences() != 2 ) {
6332                 return false;
6333             }
6334             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6335                 return false;
6336             }
6337             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6338                 return false;
6339             }
6340             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6341                 return false;
6342             }
6343             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6344                 return false;
6345             }
6346             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6347                 return false;
6348             }
6349             dmsa0.deleteRow( "c", false );
6350             dmsa0.deleteRow( "d", false );
6351             if ( dmsa0.getNumberOfSequences() != 0 ) {
6352                 return false;
6353             }
6354             //
6355             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6356             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6357             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6358             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6359             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6360             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6361             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6362             l1.add( s_0 );
6363             l1.add( s_1 );
6364             l1.add( s_2 );
6365             l1.add( s_3 );
6366             l1.add( s_4 );
6367             l1.add( s_5 );
6368             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6369             dmsa1.deleteGapOnlyColumns();
6370             dmsa1.deleteRow( "a", false );
6371             dmsa1.deleteRow( "f", false );
6372             dmsa1.deleteRow( "d", false );
6373             dmsa1.deleteGapOnlyColumns();
6374             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6375                 return false;
6376             }
6377             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6378                 return false;
6379             }
6380             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6381                 return false;
6382             }
6383             dmsa1.deleteRow( "c", false );
6384             dmsa1.deleteGapOnlyColumns();
6385             final Writer w0 = new StringWriter();
6386             dmsa1.write( w0, MSA_FORMAT.FASTA );
6387             final Writer w1 = new StringWriter();
6388             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6389             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6390                 return false;
6391             }
6392             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6393                 return false;
6394             }
6395             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6396             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6397             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6398             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6399             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6400             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6401             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6402             l2.add( s__0 );
6403             l2.add( s__1 );
6404             l2.add( s__2 );
6405             l2.add( s__3 );
6406             l2.add( s__4 );
6407             l2.add( s__5 );
6408             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6409             dmsa2.deleteGapColumns( 0.5 );
6410             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6411                 return false;
6412             }
6413             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6414                 return false;
6415             }
6416             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6417                 return false;
6418             }
6419             dmsa2.deleteGapColumns( 0.2 );
6420             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6421                 return false;
6422             }
6423             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6424                 return false;
6425             }
6426             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6427                 return false;
6428             }
6429             dmsa2.deleteGapColumns( 0 );
6430             dmsa2.deleteRow( "a", false );
6431             dmsa2.deleteRow( "b", false );
6432             dmsa2.deleteRow( "f", false );
6433             dmsa2.deleteRow( "e", false );
6434             dmsa2.setIdentifier( 0, "new_c" );
6435             dmsa2.setIdentifier( 1, "new_d" );
6436             dmsa2.setResidueAt( 0, 0, 'x' );
6437             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6438             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6439                 return false;
6440             }
6441             final Writer w = new StringWriter();
6442             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6443             final String phylip = w.toString();
6444             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6445                 System.out.println( phylip );
6446                 return false;
6447             }
6448             final Writer w2 = new StringWriter();
6449             dmsa2.write( w2, MSA_FORMAT.FASTA );
6450             final String fasta = w2.toString();
6451             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6452                 System.out.println( fasta );
6453                 return false;
6454             }
6455         }
6456         catch ( final Exception e ) {
6457             e.printStackTrace( System.out );
6458             return false;
6459         }
6460         return true;
6461     }
6462
6463     private static boolean testNextNodeWithCollapsing() {
6464         try {
6465             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6466             PhylogenyNode n;
6467             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6468             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6469             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6470             t0.getNode( "cd" ).setCollapse( true );
6471             t0.getNode( "cde" ).setCollapse( true );
6472             n = t0.getFirstExternalNode();
6473             while ( n != null ) {
6474                 ext.add( n );
6475                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6476             }
6477             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6478                 return false;
6479             }
6480             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6481                 return false;
6482             }
6483             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6490                 return false;
6491             }
6492             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6493                 return false;
6494             }
6495             ext.clear();
6496             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6497             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6498             t1.getNode( "ab" ).setCollapse( true );
6499             t1.getNode( "cd" ).setCollapse( true );
6500             t1.getNode( "cde" ).setCollapse( true );
6501             n = t1.getNode( "ab" );
6502             ext = new ArrayList<PhylogenyNode>();
6503             while ( n != null ) {
6504                 ext.add( n );
6505                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6506             }
6507             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6508                 return false;
6509             }
6510             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6511                 return false;
6512             }
6513             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6520                 return false;
6521             }
6522             ext.clear();
6523             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6524             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6525             t2.getNode( "ab" ).setCollapse( true );
6526             t2.getNode( "cd" ).setCollapse( true );
6527             t2.getNode( "cde" ).setCollapse( true );
6528             t2.getNode( "c" ).setCollapse( true );
6529             t2.getNode( "d" ).setCollapse( true );
6530             t2.getNode( "e" ).setCollapse( true );
6531             t2.getNode( "gh" ).setCollapse( true );
6532             n = t2.getNode( "ab" );
6533             ext = new ArrayList<PhylogenyNode>();
6534             while ( n != null ) {
6535                 ext.add( n );
6536                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6537             }
6538             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6539                 return false;
6540             }
6541             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6542                 return false;
6543             }
6544             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6545                 return false;
6546             }
6547             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6548                 return false;
6549             }
6550             ext.clear();
6551             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6552             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6553             t3.getNode( "ab" ).setCollapse( true );
6554             t3.getNode( "cd" ).setCollapse( true );
6555             t3.getNode( "cde" ).setCollapse( true );
6556             t3.getNode( "c" ).setCollapse( true );
6557             t3.getNode( "d" ).setCollapse( true );
6558             t3.getNode( "e" ).setCollapse( true );
6559             t3.getNode( "gh" ).setCollapse( true );
6560             t3.getNode( "fgh" ).setCollapse( true );
6561             n = t3.getNode( "ab" );
6562             ext = new ArrayList<PhylogenyNode>();
6563             while ( n != null ) {
6564                 ext.add( n );
6565                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6566             }
6567             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6568                 return false;
6569             }
6570             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6571                 return false;
6572             }
6573             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6574                 return false;
6575             }
6576             ext.clear();
6577             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6578             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6579             t4.getNode( "ab" ).setCollapse( true );
6580             t4.getNode( "cd" ).setCollapse( true );
6581             t4.getNode( "cde" ).setCollapse( true );
6582             t4.getNode( "c" ).setCollapse( true );
6583             t4.getNode( "d" ).setCollapse( true );
6584             t4.getNode( "e" ).setCollapse( true );
6585             t4.getNode( "gh" ).setCollapse( true );
6586             t4.getNode( "fgh" ).setCollapse( true );
6587             t4.getNode( "abcdefgh" ).setCollapse( true );
6588             n = t4.getNode( "abcdefgh" );
6589             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6590                 return false;
6591             }
6592             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6593             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6594             ext.clear();
6595             n = t5.getFirstExternalNode();
6596             while ( n != null ) {
6597                 ext.add( n );
6598                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6599             }
6600             if ( ext.size() != 8 ) {
6601                 return false;
6602             }
6603             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6604                 return false;
6605             }
6606             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6607                 return false;
6608             }
6609             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6610                 return false;
6611             }
6612             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6625                 return false;
6626             }
6627             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6628             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6629             ext.clear();
6630             t6.getNode( "ab" ).setCollapse( true );
6631             n = t6.getNode( "ab" );
6632             while ( n != null ) {
6633                 ext.add( n );
6634                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6635             }
6636             if ( ext.size() != 7 ) {
6637                 return false;
6638             }
6639             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6640                 return false;
6641             }
6642             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6643                 return false;
6644             }
6645             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6646                 return false;
6647             }
6648             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6658                 return false;
6659             }
6660             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6661             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6662             ext.clear();
6663             t7.getNode( "cd" ).setCollapse( true );
6664             n = t7.getNode( "a" );
6665             while ( n != null ) {
6666                 ext.add( n );
6667                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6668             }
6669             if ( ext.size() != 7 ) {
6670                 return false;
6671             }
6672             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6673                 return false;
6674             }
6675             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6676                 return false;
6677             }
6678             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6679                 return false;
6680             }
6681             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6682                 return false;
6683             }
6684             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6685                 return false;
6686             }
6687             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6688                 return false;
6689             }
6690             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6691                 return false;
6692             }
6693             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6694             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6695             ext.clear();
6696             t8.getNode( "cd" ).setCollapse( true );
6697             t8.getNode( "c" ).setCollapse( true );
6698             t8.getNode( "d" ).setCollapse( true );
6699             n = t8.getNode( "a" );
6700             while ( n != null ) {
6701                 ext.add( n );
6702                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6703             }
6704             if ( ext.size() != 7 ) {
6705                 return false;
6706             }
6707             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6708                 return false;
6709             }
6710             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6711                 return false;
6712             }
6713             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6714                 System.out.println( "2 fail" );
6715                 return false;
6716             }
6717             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6724                 return false;
6725             }
6726             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6727                 return false;
6728             }
6729             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6730             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6731             ext.clear();
6732             t9.getNode( "gh" ).setCollapse( true );
6733             n = t9.getNode( "a" );
6734             while ( n != null ) {
6735                 ext.add( n );
6736                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6737             }
6738             if ( ext.size() != 7 ) {
6739                 return false;
6740             }
6741             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6742                 return false;
6743             }
6744             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6745                 return false;
6746             }
6747             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6748                 return false;
6749             }
6750             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6751                 return false;
6752             }
6753             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6754                 return false;
6755             }
6756             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6757                 return false;
6758             }
6759             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6760                 return false;
6761             }
6762             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6763             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6764             ext.clear();
6765             t10.getNode( "gh" ).setCollapse( true );
6766             t10.getNode( "g" ).setCollapse( true );
6767             t10.getNode( "h" ).setCollapse( true );
6768             n = t10.getNode( "a" );
6769             while ( n != null ) {
6770                 ext.add( n );
6771                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6772             }
6773             if ( ext.size() != 7 ) {
6774                 return false;
6775             }
6776             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6777                 return false;
6778             }
6779             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6780                 return false;
6781             }
6782             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6783                 return false;
6784             }
6785             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6786                 return false;
6787             }
6788             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6789                 return false;
6790             }
6791             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6792                 return false;
6793             }
6794             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6795                 return false;
6796             }
6797             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6798             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6799             ext.clear();
6800             t11.getNode( "gh" ).setCollapse( true );
6801             t11.getNode( "fgh" ).setCollapse( true );
6802             n = t11.getNode( "a" );
6803             while ( n != null ) {
6804                 ext.add( n );
6805                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6806             }
6807             if ( ext.size() != 6 ) {
6808                 return false;
6809             }
6810             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6811                 return false;
6812             }
6813             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6814                 return false;
6815             }
6816             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6817                 return false;
6818             }
6819             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6820                 return false;
6821             }
6822             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6823                 return false;
6824             }
6825             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6826                 return false;
6827             }
6828             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6829             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6830             ext.clear();
6831             t12.getNode( "gh" ).setCollapse( true );
6832             t12.getNode( "fgh" ).setCollapse( true );
6833             t12.getNode( "g" ).setCollapse( true );
6834             t12.getNode( "h" ).setCollapse( true );
6835             t12.getNode( "f" ).setCollapse( true );
6836             n = t12.getNode( "a" );
6837             while ( n != null ) {
6838                 ext.add( n );
6839                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6840             }
6841             if ( ext.size() != 6 ) {
6842                 return false;
6843             }
6844             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6845                 return false;
6846             }
6847             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6848                 return false;
6849             }
6850             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6851                 return false;
6852             }
6853             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6857                 return false;
6858             }
6859             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6860                 return false;
6861             }
6862             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6863             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6864             ext.clear();
6865             t13.getNode( "ab" ).setCollapse( true );
6866             t13.getNode( "b" ).setCollapse( true );
6867             t13.getNode( "fgh" ).setCollapse( true );
6868             t13.getNode( "gh" ).setCollapse( true );
6869             n = t13.getNode( "ab" );
6870             while ( n != null ) {
6871                 ext.add( n );
6872                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6873             }
6874             if ( ext.size() != 5 ) {
6875                 return false;
6876             }
6877             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6878                 return false;
6879             }
6880             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6881                 return false;
6882             }
6883             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6887                 return false;
6888             }
6889             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6890                 return false;
6891             }
6892             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6893             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6894             ext.clear();
6895             t14.getNode( "ab" ).setCollapse( true );
6896             t14.getNode( "a" ).setCollapse( true );
6897             t14.getNode( "fgh" ).setCollapse( true );
6898             t14.getNode( "gh" ).setCollapse( true );
6899             n = t14.getNode( "ab" );
6900             while ( n != null ) {
6901                 ext.add( n );
6902                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6903             }
6904             if ( ext.size() != 5 ) {
6905                 return false;
6906             }
6907             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6908                 return false;
6909             }
6910             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6920                 return false;
6921             }
6922             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" );
6923             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6924             ext.clear();
6925             t15.getNode( "ab" ).setCollapse( true );
6926             t15.getNode( "a" ).setCollapse( true );
6927             t15.getNode( "fgh" ).setCollapse( true );
6928             t15.getNode( "gh" ).setCollapse( true );
6929             n = t15.getNode( "ab" );
6930             while ( n != null ) {
6931                 ext.add( n );
6932                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6933             }
6934             if ( ext.size() != 6 ) {
6935                 return false;
6936             }
6937             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6938                 return false;
6939             }
6940             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6941                 return false;
6942             }
6943             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6944                 return false;
6945             }
6946             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6947                 return false;
6948             }
6949             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6950                 return false;
6951             }
6952             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6953                 return false;
6954             }
6955             //
6956             //
6957             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" );
6958             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6959             ext.clear();
6960             t16.getNode( "ab" ).setCollapse( true );
6961             t16.getNode( "a" ).setCollapse( true );
6962             t16.getNode( "fgh" ).setCollapse( true );
6963             t16.getNode( "gh" ).setCollapse( true );
6964             t16.getNode( "cd" ).setCollapse( true );
6965             t16.getNode( "cde" ).setCollapse( true );
6966             t16.getNode( "d" ).setCollapse( true );
6967             t16.getNode( "x" ).setCollapse( true );
6968             n = t16.getNode( "ab" );
6969             while ( n != null ) {
6970                 ext.add( n );
6971                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6972             }
6973             if ( ext.size() != 4 ) {
6974                 return false;
6975             }
6976             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6977                 return false;
6978             }
6979             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6980                 return false;
6981             }
6982             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6983                 return false;
6984             }
6985             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6986                 return false;
6987             }
6988         }
6989         catch ( final Exception e ) {
6990             e.printStackTrace( System.out );
6991             return false;
6992         }
6993         return true;
6994     }
6995
6996     private static boolean testNexusCharactersParsing() {
6997         try {
6998             final NexusCharactersParser parser = new NexusCharactersParser();
6999             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7000             parser.parse();
7001             String[] labels = parser.getCharStateLabels();
7002             if ( labels.length != 7 ) {
7003                 return false;
7004             }
7005             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7006                 return false;
7007             }
7008             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7009                 return false;
7010             }
7011             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7012                 return false;
7013             }
7014             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7015                 return false;
7016             }
7017             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7018                 return false;
7019             }
7020             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7021                 return false;
7022             }
7023             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7024                 return false;
7025             }
7026             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7027             parser.parse();
7028             labels = parser.getCharStateLabels();
7029             if ( labels.length != 7 ) {
7030                 return false;
7031             }
7032             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7033                 return false;
7034             }
7035             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7036                 return false;
7037             }
7038             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7039                 return false;
7040             }
7041             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7042                 return false;
7043             }
7044             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7045                 return false;
7046             }
7047             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7048                 return false;
7049             }
7050             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7051                 return false;
7052             }
7053         }
7054         catch ( final Exception e ) {
7055             e.printStackTrace( System.out );
7056             return false;
7057         }
7058         return true;
7059     }
7060
7061     private static boolean testNexusMatrixParsing() {
7062         try {
7063             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7064             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7065             parser.parse();
7066             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7067             if ( m.getNumberOfCharacters() != 9 ) {
7068                 return false;
7069             }
7070             if ( m.getNumberOfIdentifiers() != 5 ) {
7071                 return false;
7072             }
7073             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7074                 return false;
7075             }
7076             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7077                 return false;
7078             }
7079             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7080                 return false;
7081             }
7082             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7083                 return false;
7084             }
7085             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7086                 return false;
7087             }
7088             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7089                 return false;
7090             }
7091             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7092                 return false;
7093             }
7094             //            if ( labels.length != 7 ) {
7095             //                return false;
7096             //            }
7097             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7098             //                return false;
7099             //            }
7100             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7104             //                return false;
7105             //            }
7106             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7107             //                return false;
7108             //            }
7109             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7110             //                return false;
7111             //            }
7112             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7113             //                return false;
7114             //            }
7115             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7116             //                return false;
7117             //            }
7118             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7119             //            parser.parse();
7120             //            labels = parser.getCharStateLabels();
7121             //            if ( labels.length != 7 ) {
7122             //                return false;
7123             //            }
7124             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7125             //                return false;
7126             //            }
7127             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7128             //                return false;
7129             //            }
7130             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7131             //                return false;
7132             //            }
7133             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7134             //                return false;
7135             //            }
7136             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7137             //                return false;
7138             //            }
7139             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7140             //                return false;
7141             //            }
7142             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7143             //                return false;
7144             //            }
7145         }
7146         catch ( final Exception e ) {
7147             e.printStackTrace( System.out );
7148             return false;
7149         }
7150         return true;
7151     }
7152
7153     private static boolean testNexusTreeParsing() {
7154         try {
7155             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7156             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7157             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7158             if ( phylogenies.length != 1 ) {
7159                 return false;
7160             }
7161             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7162                 return false;
7163             }
7164             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7165                 return false;
7166             }
7167             phylogenies = null;
7168             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7169             if ( phylogenies.length != 1 ) {
7170                 return false;
7171             }
7172             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7173                 return false;
7174             }
7175             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7176                 return false;
7177             }
7178             phylogenies = null;
7179             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7180             if ( phylogenies.length != 1 ) {
7181                 return false;
7182             }
7183             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7184                 return false;
7185             }
7186             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7187                 return false;
7188             }
7189             if ( phylogenies[ 0 ].isRooted() ) {
7190                 return false;
7191             }
7192             phylogenies = null;
7193             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7194             if ( phylogenies.length != 18 ) {
7195                 return false;
7196             }
7197             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7198                 return false;
7199             }
7200             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7201                 return false;
7202             }
7203             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7204                 return false;
7205             }
7206             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7207                 return false;
7208             }
7209             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7216                 return false;
7217             }
7218             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7219                 return false;
7220             }
7221             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7222                 return false;
7223             }
7224             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7225                 return false;
7226             }
7227             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7228                 return false;
7229             }
7230             if ( phylogenies[ 8 ].isRooted() ) {
7231                 return false;
7232             }
7233             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7234                 return false;
7235             }
7236             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7237                 return false;
7238             }
7239             if ( !phylogenies[ 9 ].isRooted() ) {
7240                 return false;
7241             }
7242             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7246                 return false;
7247             }
7248             if ( !phylogenies[ 10 ].isRooted() ) {
7249                 return false;
7250             }
7251             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7252                 return false;
7253             }
7254             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7255                 return false;
7256             }
7257             if ( phylogenies[ 11 ].isRooted() ) {
7258                 return false;
7259             }
7260             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7261                 return false;
7262             }
7263             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7264                 return false;
7265             }
7266             if ( !phylogenies[ 12 ].isRooted() ) {
7267                 return false;
7268             }
7269             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7270                 return false;
7271             }
7272             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7273                 return false;
7274             }
7275             if ( !phylogenies[ 13 ].isRooted() ) {
7276                 return false;
7277             }
7278             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7279                 return false;
7280             }
7281             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7282                 return false;
7283             }
7284             if ( !phylogenies[ 14 ].isRooted() ) {
7285                 return false;
7286             }
7287             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7288                 return false;
7289             }
7290             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7291                 return false;
7292             }
7293             if ( phylogenies[ 15 ].isRooted() ) {
7294                 return false;
7295             }
7296             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7297                 return false;
7298             }
7299             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7300                 return false;
7301             }
7302             if ( !phylogenies[ 16 ].isRooted() ) {
7303                 return false;
7304             }
7305             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7306                 return false;
7307             }
7308             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7309                 return false;
7310             }
7311             if ( phylogenies[ 17 ].isRooted() ) {
7312                 return false;
7313             }
7314             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7315                 return false;
7316             }
7317             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7318             phylogenies = null;
7319             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7320             if ( phylogenies.length != 9 ) {
7321                 return false;
7322             }
7323             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7324                            .getDistanceToParent() ) ) {
7325                 return false;
7326             }
7327             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7328                            .getDistanceToParent() ) ) {
7329                 return false;
7330             }
7331             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7332                 return false;
7333             }
7334             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7335                 return false;
7336             }
7337             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7338                 return false;
7339             }
7340             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7341                 return false;
7342             }
7343             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7344                 return false;
7345             }
7346         }
7347         catch ( final Exception e ) {
7348             e.printStackTrace( System.out );
7349             return false;
7350         }
7351         return true;
7352     }
7353
7354     private static boolean testNexusTreeParsingIterating() {
7355         try {
7356             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7357             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7358             if ( !p.hasNext() ) {
7359                 return false;
7360             }
7361             Phylogeny 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.reset();
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             phy = p.next();
7383             if ( phy == null ) {
7384                 return false;
7385             }
7386             if ( phy.getNumberOfExternalNodes() != 25 ) {
7387                 return false;
7388             }
7389             if ( !phy.getName().equals( "" ) ) {
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.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
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.reset();
7421             if ( !p.hasNext() ) {
7422                 return false;
7423             }
7424             phy = p.next();
7425             if ( phy == null ) {
7426                 return false;
7427             }
7428             if ( phy.getNumberOfExternalNodes() != 10 ) {
7429                 return false;
7430             }
7431             if ( !phy.getName().equals( "name" ) ) {
7432                 return false;
7433             }
7434             if ( p.hasNext() ) {
7435                 return false;
7436             }
7437             phy = p.next();
7438             if ( phy != null ) {
7439                 return false;
7440             }
7441             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7442             if ( !p.hasNext() ) {
7443                 return false;
7444             }
7445             phy = p.next();
7446             if ( phy == null ) {
7447                 return false;
7448             }
7449             if ( phy.getNumberOfExternalNodes() != 3 ) {
7450                 return false;
7451             }
7452             if ( !phy.getName().equals( "" ) ) {
7453                 return false;
7454             }
7455             if ( phy.isRooted() ) {
7456                 return false;
7457             }
7458             if ( p.hasNext() ) {
7459                 return false;
7460             }
7461             phy = p.next();
7462             if ( phy != null ) {
7463                 return false;
7464             }
7465             //
7466             p.reset();
7467             if ( !p.hasNext() ) {
7468                 return false;
7469             }
7470             phy = p.next();
7471             if ( phy == null ) {
7472                 return false;
7473             }
7474             if ( phy.getNumberOfExternalNodes() != 3 ) {
7475                 return false;
7476             }
7477             if ( !phy.getName().equals( "" ) ) {
7478                 return false;
7479             }
7480             if ( p.hasNext() ) {
7481                 return false;
7482             }
7483             phy = p.next();
7484             if ( phy != null ) {
7485                 return false;
7486             }
7487             //
7488             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7489             if ( !p.hasNext() ) {
7490                 return false;
7491             }
7492             //0
7493             phy = p.next();
7494             if ( phy == null ) {
7495                 return false;
7496             }
7497             if ( phy.getNumberOfExternalNodes() != 10 ) {
7498                 return false;
7499             }
7500             if ( !phy.getName().equals( "tree 0" ) ) {
7501                 return false;
7502             }
7503             //1
7504             if ( !p.hasNext() ) {
7505                 return false;
7506             }
7507             phy = p.next();
7508             if ( phy == null ) {
7509                 return false;
7510             }
7511             if ( phy.getNumberOfExternalNodes() != 10 ) {
7512                 return false;
7513             }
7514             if ( !phy.getName().equals( "tree 1" ) ) {
7515                 return false;
7516             }
7517             //2
7518             if ( !p.hasNext() ) {
7519                 return false;
7520             }
7521             phy = p.next();
7522             if ( phy == null ) {
7523                 return false;
7524             }
7525             if ( phy.getNumberOfExternalNodes() != 3 ) {
7526                 System.out.println( phy.toString() );
7527                 return false;
7528             }
7529             if ( !phy.getName().equals( "" ) ) {
7530                 return false;
7531             }
7532             if ( phy.isRooted() ) {
7533                 return false;
7534             }
7535             //3
7536             if ( !p.hasNext() ) {
7537                 return false;
7538             }
7539             phy = p.next();
7540             if ( phy == null ) {
7541                 return false;
7542             }
7543             if ( phy.getNumberOfExternalNodes() != 4 ) {
7544                 return false;
7545             }
7546             if ( !phy.getName().equals( "" ) ) {
7547                 return false;
7548             }
7549             if ( !phy.isRooted() ) {
7550                 return false;
7551             }
7552             //4
7553             if ( !p.hasNext() ) {
7554                 return false;
7555             }
7556             phy = p.next();
7557             if ( phy == null ) {
7558                 return false;
7559             }
7560             if ( phy.getNumberOfExternalNodes() != 5 ) {
7561                 System.out.println( phy.getNumberOfExternalNodes() );
7562                 return false;
7563             }
7564             if ( !phy.getName().equals( "" ) ) {
7565                 return false;
7566             }
7567             if ( !phy.isRooted() ) {
7568                 return false;
7569             }
7570             //5
7571             if ( !p.hasNext() ) {
7572                 return false;
7573             }
7574             phy = p.next();
7575             if ( phy == null ) {
7576                 return false;
7577             }
7578             if ( phy.getNumberOfExternalNodes() != 3 ) {
7579                 return false;
7580             }
7581             if ( !phy.getName().equals( "" ) ) {
7582                 return false;
7583             }
7584             if ( phy.isRooted() ) {
7585                 return false;
7586             }
7587             //6
7588             if ( !p.hasNext() ) {
7589                 return false;
7590             }
7591             phy = p.next();
7592             if ( phy == null ) {
7593                 return false;
7594             }
7595             if ( phy.getNumberOfExternalNodes() != 2 ) {
7596                 return false;
7597             }
7598             if ( !phy.getName().equals( "" ) ) {
7599                 return false;
7600             }
7601             if ( !phy.isRooted() ) {
7602                 return false;
7603             }
7604             //7
7605             if ( !p.hasNext() ) {
7606                 return false;
7607             }
7608             phy = p.next();
7609             if ( phy.getNumberOfExternalNodes() != 3 ) {
7610                 return false;
7611             }
7612             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7613                 return false;
7614             }
7615             if ( !phy.isRooted() ) {
7616                 return false;
7617             }
7618             //8
7619             if ( !p.hasNext() ) {
7620                 return false;
7621             }
7622             phy = p.next();
7623             if ( phy.getNumberOfExternalNodes() != 3 ) {
7624                 return false;
7625             }
7626             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7627                 return false;
7628             }
7629             if ( !phy.getName().equals( "tree 8" ) ) {
7630                 return false;
7631             }
7632             //9
7633             if ( !p.hasNext() ) {
7634                 return false;
7635             }
7636             phy = p.next();
7637             if ( phy.getNumberOfExternalNodes() != 3 ) {
7638                 return false;
7639             }
7640             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7641                 return false;
7642             }
7643             if ( !phy.getName().equals( "tree 9" ) ) {
7644                 return false;
7645             }
7646             //10
7647             if ( !p.hasNext() ) {
7648                 return false;
7649             }
7650             phy = p.next();
7651             if ( phy.getNumberOfExternalNodes() != 3 ) {
7652                 return false;
7653             }
7654             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7655                 return false;
7656             }
7657             if ( !phy.getName().equals( "tree 10" ) ) {
7658                 return false;
7659             }
7660             if ( !phy.isRooted() ) {
7661                 return false;
7662             }
7663             //11
7664             if ( !p.hasNext() ) {
7665                 return false;
7666             }
7667             phy = p.next();
7668             if ( phy.getNumberOfExternalNodes() != 3 ) {
7669                 return false;
7670             }
7671             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7672                 return false;
7673             }
7674             if ( !phy.getName().equals( "tree 11" ) ) {
7675                 return false;
7676             }
7677             if ( phy.isRooted() ) {
7678                 return false;
7679             }
7680             //12
7681             if ( !p.hasNext() ) {
7682                 return false;
7683             }
7684             phy = p.next();
7685             if ( phy.getNumberOfExternalNodes() != 3 ) {
7686                 return false;
7687             }
7688             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7689                 return false;
7690             }
7691             if ( !phy.getName().equals( "tree 12" ) ) {
7692                 return false;
7693             }
7694             if ( !phy.isRooted() ) {
7695                 return false;
7696             }
7697             //13
7698             if ( !p.hasNext() ) {
7699                 return false;
7700             }
7701             phy = p.next();
7702             if ( phy.getNumberOfExternalNodes() != 3 ) {
7703                 return false;
7704             }
7705             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7706                 return false;
7707             }
7708             if ( !phy.getName().equals( "tree 13" ) ) {
7709                 return false;
7710             }
7711             if ( !phy.isRooted() ) {
7712                 return false;
7713             }
7714             //14
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 14" ) ) {
7730                 return false;
7731             }
7732             if ( !phy.isRooted() ) {
7733                 return false;
7734             }
7735             //15
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 15" ) ) {
7751                 return false;
7752             }
7753             if ( phy.isRooted() ) {
7754                 return false;
7755             }
7756             //16
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 16" ) ) {
7772                 return false;
7773             }
7774             if ( !phy.isRooted() ) {
7775                 return false;
7776             }
7777             //17
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy.getNumberOfExternalNodes() != 10 ) {
7783                 System.out.println( phy.getNumberOfExternalNodes() );
7784                 return false;
7785             }
7786             if ( !phy
7787                     .toNewHampshire()
7788                     .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;" ) ) {
7789                 System.out.println( phy.toNewHampshire() );
7790                 return false;
7791             }
7792             if ( !phy.getName().equals( "tree 17" ) ) {
7793                 return false;
7794             }
7795             if ( phy.isRooted() ) {
7796                 return false;
7797             }
7798             //
7799             if ( p.hasNext() ) {
7800                 return false;
7801             }
7802             phy = p.next();
7803             if ( phy != null ) {
7804                 return false;
7805             }
7806             p.reset();
7807             //0
7808             if ( !p.hasNext() ) {
7809                 return false;
7810             }
7811             phy = p.next();
7812             if ( phy == null ) {
7813                 return false;
7814             }
7815             if ( phy.getNumberOfExternalNodes() != 10 ) {
7816                 return false;
7817             }
7818             if ( !phy.getName().equals( "tree 0" ) ) {
7819                 return false;
7820             }
7821             //1
7822             if ( !p.hasNext() ) {
7823                 return false;
7824             }
7825             phy = p.next();
7826             if ( phy == null ) {
7827                 return false;
7828             }
7829             if ( phy.getNumberOfExternalNodes() != 10 ) {
7830                 return false;
7831             }
7832             if ( !phy.getName().equals( "tree 1" ) ) {
7833                 return false;
7834             }
7835             //2
7836             if ( !p.hasNext() ) {
7837                 return false;
7838             }
7839             phy = p.next();
7840             if ( phy == null ) {
7841                 return false;
7842             }
7843             if ( phy.getNumberOfExternalNodes() != 3 ) {
7844                 return false;
7845             }
7846             if ( !phy.getName().equals( "" ) ) {
7847                 return false;
7848             }
7849             if ( phy.isRooted() ) {
7850                 return false;
7851             }
7852             //3
7853             if ( !p.hasNext() ) {
7854                 return false;
7855             }
7856             phy = p.next();
7857             if ( phy == null ) {
7858                 return false;
7859             }
7860             if ( phy.getNumberOfExternalNodes() != 4 ) {
7861                 return false;
7862             }
7863             if ( !phy.getName().equals( "" ) ) {
7864                 return false;
7865             }
7866             if ( !phy.isRooted() ) {
7867                 return false;
7868             }
7869             //4
7870             if ( !p.hasNext() ) {
7871                 return false;
7872             }
7873             phy = p.next();
7874             if ( phy == null ) {
7875                 return false;
7876             }
7877             if ( phy.getNumberOfExternalNodes() != 5 ) {
7878                 System.out.println( phy.getNumberOfExternalNodes() );
7879                 return false;
7880             }
7881             if ( !phy.getName().equals( "" ) ) {
7882                 return false;
7883             }
7884             if ( !phy.isRooted() ) {
7885                 return false;
7886             }
7887             //5
7888             if ( !p.hasNext() ) {
7889                 return false;
7890             }
7891             phy = p.next();
7892             if ( phy == null ) {
7893                 return false;
7894             }
7895             if ( phy.getNumberOfExternalNodes() != 3 ) {
7896                 return false;
7897             }
7898             if ( !phy.getName().equals( "" ) ) {
7899                 return false;
7900             }
7901             if ( phy.isRooted() ) {
7902                 return false;
7903             }
7904             //
7905             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7906             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7907             // 0
7908             if ( !p2.hasNext() ) {
7909                 return false;
7910             }
7911             phy = p2.next();
7912             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7913                 return false;
7914             }
7915             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7916                 return false;
7917             }
7918             // 1
7919             if ( !p2.hasNext() ) {
7920                 return false;
7921             }
7922             phy = p2.next();
7923             // 2
7924             if ( !p2.hasNext() ) {
7925                 return false;
7926             }
7927             phy = p2.next();
7928             // 3
7929             if ( !p2.hasNext() ) {
7930                 return false;
7931             }
7932             phy = p2.next();
7933             // 4
7934             if ( !p2.hasNext() ) {
7935                 return false;
7936             }
7937             phy = p2.next();
7938             // 5
7939             if ( !p2.hasNext() ) {
7940                 return false;
7941             }
7942             phy = p2.next();
7943             // 6
7944             if ( !p2.hasNext() ) {
7945                 return false;
7946             }
7947             phy = p2.next();
7948             // 7
7949             if ( !p2.hasNext() ) {
7950                 return false;
7951             }
7952             phy = p2.next();
7953             // 8
7954             if ( !p2.hasNext() ) {
7955                 return false;
7956             }
7957             phy = p2.next();
7958             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7959                 return false;
7960             }
7961             if ( p2.hasNext() ) {
7962                 return false;
7963             }
7964             phy = p2.next();
7965             if ( phy != null ) {
7966                 return false;
7967             }
7968             // 0
7969             p2.reset();
7970             if ( !p2.hasNext() ) {
7971                 return false;
7972             }
7973             phy = p2.next();
7974             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7975                 return false;
7976             }
7977             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7978                 return false;
7979             }
7980         }
7981         catch ( final Exception e ) {
7982             e.printStackTrace( System.out );
7983             return false;
7984         }
7985         return true;
7986     }
7987
7988     private static boolean testNexusTreeParsingTranslating() {
7989         try {
7990             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7991             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7992             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7993             if ( phylogenies.length != 1 ) {
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 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8003                 return false;
8004             }
8005             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8006                 return false;
8007             }
8008             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8009                     .equals( "Aranaeus" ) ) {
8010                 return false;
8011             }
8012             phylogenies = null;
8013             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8014             if ( phylogenies.length != 3 ) {
8015                 return false;
8016             }
8017             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8018                 return false;
8019             }
8020             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8021                 return false;
8022             }
8023             if ( phylogenies[ 0 ].isRooted() ) {
8024                 return false;
8025             }
8026             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8027                 return false;
8028             }
8029             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8030                 return false;
8031             }
8032             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8033                     .equals( "Aranaeus" ) ) {
8034                 return false;
8035             }
8036             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8037                 return false;
8038             }
8039             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8040                 return false;
8041             }
8042             if ( phylogenies[ 1 ].isRooted() ) {
8043                 return false;
8044             }
8045             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8046                 return false;
8047             }
8048             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8049                 return false;
8050             }
8051             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8052                     .equals( "Aranaeus" ) ) {
8053                 return false;
8054             }
8055             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8056                 return false;
8057             }
8058             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8059                 return false;
8060             }
8061             if ( !phylogenies[ 2 ].isRooted() ) {
8062                 return false;
8063             }
8064             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8065                 return false;
8066             }
8067             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8068                 return false;
8069             }
8070             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8071                     .equals( "Aranaeus" ) ) {
8072                 return false;
8073             }
8074             phylogenies = null;
8075             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8076             if ( phylogenies.length != 3 ) {
8077                 return false;
8078             }
8079             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8080                 return false;
8081             }
8082             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8083                 return false;
8084             }
8085             if ( phylogenies[ 0 ].isRooted() ) {
8086                 return false;
8087             }
8088             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8089                 return false;
8090             }
8091             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8092                 return false;
8093             }
8094             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8095                     .equals( "Aranaeus" ) ) {
8096                 return false;
8097             }
8098             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8099                 return false;
8100             }
8101             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8102                 return false;
8103             }
8104             if ( phylogenies[ 1 ].isRooted() ) {
8105                 return false;
8106             }
8107             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8108                 return false;
8109             }
8110             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8111                 return false;
8112             }
8113             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8114                     .equals( "Aranaeus" ) ) {
8115                 return false;
8116             }
8117             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8118                 return false;
8119             }
8120             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8121                 return false;
8122             }
8123             if ( !phylogenies[ 2 ].isRooted() ) {
8124                 return false;
8125             }
8126             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8127                 return false;
8128             }
8129             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8130                 return false;
8131             }
8132             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8133                     .equals( "Aranaeus" ) ) {
8134                 return false;
8135             }
8136             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8137             if ( phylogenies.length != 3 ) {
8138                 return false;
8139             }
8140             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8141                            0.00100049 ) ) {
8142                 return false;
8143             }
8144         }
8145         catch ( final Exception e ) {
8146             e.printStackTrace( System.out );
8147             return false;
8148         }
8149         return true;
8150     }
8151
8152     private static boolean testNHParsing() {
8153         try {
8154             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8155             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8156             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8157                 return false;
8158             }
8159             final NHXParser nhxp = new NHXParser();
8160             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8161             nhxp.setReplaceUnderscores( true );
8162             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8163             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8164                 return false;
8165             }
8166             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8167                 return false;
8168             }
8169             final Phylogeny p1b = factory
8170                     .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 ",
8171                              new NHXParser() )[ 0 ];
8172             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8173                 return false;
8174             }
8175             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8176                 return false;
8177             }
8178             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8179             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8180             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8181             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8182             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8183             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8184             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8185             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8186             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8187             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8188             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8189                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8190                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8191                     new NHXParser() );
8192             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8193                 return false;
8194             }
8195             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8196                 return false;
8197             }
8198             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8199                 return false;
8200             }
8201             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8202                 return false;
8203             }
8204             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8205             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8206             final String p16_S = "((A,B),C)";
8207             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8208             if ( p16.length != 1 ) {
8209                 return false;
8210             }
8211             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8212                 return false;
8213             }
8214             final String p17_S = "(C,(A,B))";
8215             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8216             if ( p17.length != 1 ) {
8217                 return false;
8218             }
8219             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8220                 return false;
8221             }
8222             final String p18_S = "((A,B),(C,D))";
8223             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8224             if ( p18.length != 1 ) {
8225                 return false;
8226             }
8227             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8228                 return false;
8229             }
8230             final String p19_S = "(((A,B),C),D)";
8231             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8232             if ( p19.length != 1 ) {
8233                 return false;
8234             }
8235             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8236                 return false;
8237             }
8238             final String p20_S = "(A,(B,(C,D)))";
8239             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8240             if ( p20.length != 1 ) {
8241                 return false;
8242             }
8243             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8244                 return false;
8245             }
8246             final String p21_S = "(A,(B,(C,(D,E))))";
8247             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8248             if ( p21.length != 1 ) {
8249                 return false;
8250             }
8251             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8252                 return false;
8253             }
8254             final String p22_S = "((((A,B),C),D),E)";
8255             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8256             if ( p22.length != 1 ) {
8257                 return false;
8258             }
8259             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8260                 return false;
8261             }
8262             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8263             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8264             if ( p23.length != 1 ) {
8265                 System.out.println( "xl=" + p23.length );
8266                 System.exit( -1 );
8267                 return false;
8268             }
8269             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8270                 return false;
8271             }
8272             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8273             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8274             if ( p24.length != 1 ) {
8275                 return false;
8276             }
8277             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8278                 return false;
8279             }
8280             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8281             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8282             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8283             if ( p241.length != 2 ) {
8284                 return false;
8285             }
8286             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8287                 return false;
8288             }
8289             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8290                 return false;
8291             }
8292             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8293                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8294                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8295                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8296                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8297                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8298                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8299                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8300             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8301             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8302                 return false;
8303             }
8304             final String p26_S = "(A,B)ab";
8305             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8306             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8307                 return false;
8308             }
8309             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8310             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8311             if ( p27s.length != 1 ) {
8312                 System.out.println( "xxl=" + p27s.length );
8313                 System.exit( -1 );
8314                 return false;
8315             }
8316             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8317                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8318                 System.exit( -1 );
8319                 return false;
8320             }
8321             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8322                                                     new NHXParser() );
8323             if ( p27.length != 1 ) {
8324                 System.out.println( "yl=" + p27.length );
8325                 System.exit( -1 );
8326                 return false;
8327             }
8328             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8329                 System.out.println( p27[ 0 ].toNewHampshireX() );
8330                 System.exit( -1 );
8331                 return false;
8332             }
8333             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8334             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8335             final String p28_S3 = "(A,B)ab";
8336             final String p28_S4 = "((((A,B),C),D),;E;)";
8337             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8338                                                     new NHXParser() );
8339             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8340                 return false;
8341             }
8342             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8343                 return false;
8344             }
8345             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8346                 return false;
8347             }
8348             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8349                 return false;
8350             }
8351             if ( p28.length != 4 ) {
8352                 return false;
8353             }
8354             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";
8355             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8356             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8357                 return false;
8358             }
8359             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";
8360             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8361             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8362                 return false;
8363             }
8364             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8365             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8366             if ( ( p32.length != 0 ) ) {
8367                 return false;
8368             }
8369             final String p33_S = "A";
8370             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8371             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8372                 return false;
8373             }
8374             final String p34_S = "B;";
8375             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8376             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8377                 return false;
8378             }
8379             final String p35_S = "B:0.2";
8380             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8381             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8382                 return false;
8383             }
8384             final String p36_S = "(A)";
8385             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8386             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8387                 return false;
8388             }
8389             final String p37_S = "((A))";
8390             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8391             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8392                 return false;
8393             }
8394             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8395             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8396             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8397                 return false;
8398             }
8399             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8400             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8401             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8402                 return false;
8403             }
8404             final String p40_S = "(A,B,C)";
8405             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8406             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8407                 return false;
8408             }
8409             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8410             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8411             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8412                 return false;
8413             }
8414             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8415             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8416             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8417                 return false;
8418             }
8419             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)";
8420             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8421             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8422                 return false;
8423             }
8424             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)))";
8425             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8426             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8427                 return false;
8428             }
8429             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8430             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8431             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8432                 return false;
8433             }
8434             final String p46_S = "";
8435             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8436             if ( p46.length != 0 ) {
8437                 return false;
8438             }
8439             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8440             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8441                 return false;
8442             }
8443             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8444             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8445                 return false;
8446             }
8447             final Phylogeny p49 = factory
8448                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8449                              new NHXParser() )[ 0 ];
8450             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8451                 return false;
8452             }
8453             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8454             if ( p50.getNode( "A" ) == null ) {
8455                 return false;
8456             }
8457             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8458                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8459                 return false;
8460             }
8461             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8462                 return false;
8463             }
8464             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8465                     .equals( "((A,B)88:2.0,C);" ) ) {
8466                 return false;
8467             }
8468             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8469             if ( p51.getNode( "A(A" ) == null ) {
8470                 return false;
8471             }
8472             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8473             if ( p52.getNode( "A(A" ) == null ) {
8474                 return false;
8475             }
8476             final Phylogeny p53 = factory
8477                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8478                              new NHXParser() )[ 0 ];
8479             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8480                 return false;
8481             }
8482             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8483             if ( p54.getNode( "A" ) == null ) {
8484                 return false;
8485             }
8486             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8487                 return false;
8488             }
8489             final Phylogeny p55 = factory
8490                     .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);" ),
8491                              new NHXParser() )[ 0 ];
8492             if ( !p55
8493                     .toNewHampshire()
8494                     .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);" ) ) {
8495                 System.out.println( p55.toNewHampshire() );
8496                 return false;
8497             }
8498             final Phylogeny p56 = factory
8499                     .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);" ),
8500                              new NHXParser() )[ 0 ];
8501             if ( !p56
8502                     .toNewHampshire()
8503                     .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);" ) ) {
8504                 System.out.println( p56.toNewHampshire() );
8505                 return false;
8506             }
8507             final Phylogeny p57 = factory
8508                     .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);" ),
8509                              new NHXParser() )[ 0 ];
8510             if ( !p57
8511                     .toNewHampshire()
8512                     .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);" ) ) {
8513                 System.out.println( p56.toNewHampshire() );
8514                 return false;
8515             }
8516             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8517             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8518             if ( !p58.toNewHampshire().equals( s58 ) ) {
8519                 System.out.println( p58.toNewHampshire() );
8520                 return false;
8521             }
8522             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8523             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8524             if ( !p59.toNewHampshire().equals( s59 ) ) {
8525                 System.out.println( p59.toNewHampshire() );
8526                 return false;
8527             }
8528             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8529             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8530             if ( !p60.toNewHampshire().equals( s60 ) ) {
8531                 System.out.println( p60.toNewHampshire() );
8532                 return false;
8533             }
8534             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8535             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8536             if ( !p61.toNewHampshire()
8537                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8538                 System.out.println( p61.toNewHampshire() );
8539                 return false;
8540             }
8541         }
8542         catch ( final Exception e ) {
8543             e.printStackTrace( System.out );
8544             return false;
8545         }
8546         return true;
8547     }
8548
8549     private static boolean testNHParsingIter() {
8550         try {
8551             final String p0_str = "(A,B);";
8552             final NHXParser p = new NHXParser();
8553             p.setSource( p0_str );
8554             if ( !p.hasNext() ) {
8555                 return false;
8556             }
8557             final Phylogeny p0 = p.next();
8558             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8559                 System.out.println( p0.toNewHampshire() );
8560                 return false;
8561             }
8562             if ( p.hasNext() ) {
8563                 return false;
8564             }
8565             if ( p.next() != null ) {
8566                 return false;
8567             }
8568             //
8569             final String p00_str = "(A,B)root;";
8570             p.setSource( p00_str );
8571             final Phylogeny p00 = p.next();
8572             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8573                 System.out.println( p00.toNewHampshire() );
8574                 return false;
8575             }
8576             //
8577             final String p000_str = "A;";
8578             p.setSource( p000_str );
8579             final Phylogeny p000 = p.next();
8580             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8581                 System.out.println( p000.toNewHampshire() );
8582                 return false;
8583             }
8584             //
8585             final String p0000_str = "A";
8586             p.setSource( p0000_str );
8587             final Phylogeny p0000 = p.next();
8588             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8589                 System.out.println( p0000.toNewHampshire() );
8590                 return false;
8591             }
8592             //
8593             p.setSource( "(A)" );
8594             final Phylogeny p00000 = p.next();
8595             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8596                 System.out.println( p00000.toNewHampshire() );
8597                 return false;
8598             }
8599             //
8600             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8601             p.setSource( p1_str );
8602             if ( !p.hasNext() ) {
8603                 return false;
8604             }
8605             final Phylogeny p1_0 = p.next();
8606             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8607                 System.out.println( p1_0.toNewHampshire() );
8608                 return false;
8609             }
8610             if ( !p.hasNext() ) {
8611                 return false;
8612             }
8613             final Phylogeny p1_1 = p.next();
8614             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8615                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8616                 return false;
8617             }
8618             if ( !p.hasNext() ) {
8619                 return false;
8620             }
8621             final Phylogeny p1_2 = p.next();
8622             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8623                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8624                 return false;
8625             }
8626             if ( !p.hasNext() ) {
8627                 return false;
8628             }
8629             final Phylogeny p1_3 = p.next();
8630             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8631                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8632                 return false;
8633             }
8634             if ( p.hasNext() ) {
8635                 return false;
8636             }
8637             if ( p.next() != null ) {
8638                 return false;
8639             }
8640             //
8641             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8642             p.setSource( p2_str );
8643             if ( !p.hasNext() ) {
8644                 return false;
8645             }
8646             Phylogeny p2_0 = p.next();
8647             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8648                 System.out.println( p2_0.toNewHampshire() );
8649                 return false;
8650             }
8651             if ( !p.hasNext() ) {
8652                 return false;
8653             }
8654             Phylogeny p2_1 = p.next();
8655             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8656                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8657                 return false;
8658             }
8659             if ( !p.hasNext() ) {
8660                 return false;
8661             }
8662             Phylogeny p2_2 = p.next();
8663             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8664                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8665                 return false;
8666             }
8667             if ( !p.hasNext() ) {
8668                 return false;
8669             }
8670             Phylogeny p2_3 = p.next();
8671             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8672                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8673                 return false;
8674             }
8675             if ( !p.hasNext() ) {
8676                 return false;
8677             }
8678             Phylogeny p2_4 = p.next();
8679             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8680                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8681                 return false;
8682             }
8683             if ( p.hasNext() ) {
8684                 return false;
8685             }
8686             if ( p.next() != null ) {
8687                 return false;
8688             }
8689             ////
8690             p.reset();
8691             if ( !p.hasNext() ) {
8692                 return false;
8693             }
8694             p2_0 = p.next();
8695             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8696                 System.out.println( p2_0.toNewHampshire() );
8697                 return false;
8698             }
8699             if ( !p.hasNext() ) {
8700                 return false;
8701             }
8702             p2_1 = p.next();
8703             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8704                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8705                 return false;
8706             }
8707             if ( !p.hasNext() ) {
8708                 return false;
8709             }
8710             p2_2 = p.next();
8711             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8712                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8713                 return false;
8714             }
8715             if ( !p.hasNext() ) {
8716                 return false;
8717             }
8718             p2_3 = p.next();
8719             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8720                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8721                 return false;
8722             }
8723             if ( !p.hasNext() ) {
8724                 return false;
8725             }
8726             p2_4 = p.next();
8727             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8728                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8729                 return false;
8730             }
8731             if ( p.hasNext() ) {
8732                 return false;
8733             }
8734             if ( p.next() != null ) {
8735                 return false;
8736             }
8737             //
8738             final String p3_str = "((A,B),C)abc";
8739             p.setSource( p3_str );
8740             if ( !p.hasNext() ) {
8741                 return false;
8742             }
8743             final Phylogeny p3_0 = p.next();
8744             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8745                 return false;
8746             }
8747             if ( p.hasNext() ) {
8748                 return false;
8749             }
8750             if ( p.next() != null ) {
8751                 return false;
8752             }
8753             //
8754             final String p4_str = "((A,B)ab,C)abc";
8755             p.setSource( p4_str );
8756             if ( !p.hasNext() ) {
8757                 return false;
8758             }
8759             final Phylogeny p4_0 = p.next();
8760             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8761                 return false;
8762             }
8763             if ( p.hasNext() ) {
8764                 return false;
8765             }
8766             if ( p.next() != null ) {
8767                 return false;
8768             }
8769             //
8770             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8771             p.setSource( p5_str );
8772             if ( !p.hasNext() ) {
8773                 return false;
8774             }
8775             final Phylogeny p5_0 = p.next();
8776             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8777                 return false;
8778             }
8779             if ( p.hasNext() ) {
8780                 return false;
8781             }
8782             if ( p.next() != null ) {
8783                 return false;
8784             }
8785             //
8786             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8787             p.setSource( p6_str );
8788             if ( !p.hasNext() ) {
8789                 return false;
8790             }
8791             Phylogeny p6_0 = p.next();
8792             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8793                 return false;
8794             }
8795             if ( p.hasNext() ) {
8796                 return false;
8797             }
8798             if ( p.next() != null ) {
8799                 return false;
8800             }
8801             p.reset();
8802             if ( !p.hasNext() ) {
8803                 return false;
8804             }
8805             p6_0 = p.next();
8806             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8807                 return false;
8808             }
8809             if ( p.hasNext() ) {
8810                 return false;
8811             }
8812             if ( p.next() != null ) {
8813                 return false;
8814             }
8815             //
8816             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8817             p.setSource( p7_str );
8818             if ( !p.hasNext() ) {
8819                 return false;
8820             }
8821             Phylogeny p7_0 = p.next();
8822             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8823                 return false;
8824             }
8825             if ( p.hasNext() ) {
8826                 return false;
8827             }
8828             if ( p.next() != null ) {
8829                 return false;
8830             }
8831             p.reset();
8832             if ( !p.hasNext() ) {
8833                 return false;
8834             }
8835             p7_0 = p.next();
8836             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8837                 return false;
8838             }
8839             if ( p.hasNext() ) {
8840                 return false;
8841             }
8842             if ( p.next() != null ) {
8843                 return false;
8844             }
8845             //
8846             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8847             p.setSource( p8_str );
8848             if ( !p.hasNext() ) {
8849                 return false;
8850             }
8851             Phylogeny p8_0 = p.next();
8852             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8853                 return false;
8854             }
8855             if ( !p.hasNext() ) {
8856                 return false;
8857             }
8858             if ( !p.hasNext() ) {
8859                 return false;
8860             }
8861             Phylogeny 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             if ( !p.hasNext() ) {
8873                 return false;
8874             }
8875             p8_0 = p.next();
8876             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8877                 return false;
8878             }
8879             if ( !p.hasNext() ) {
8880                 return false;
8881             }
8882             p8_1 = p.next();
8883             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8884                 return false;
8885             }
8886             if ( p.hasNext() ) {
8887                 return false;
8888             }
8889             if ( p.next() != null ) {
8890                 return false;
8891             }
8892             p.reset();
8893             //
8894             p.setSource( "" );
8895             if ( p.hasNext() ) {
8896                 return false;
8897             }
8898             //
8899             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8900             if ( !p.hasNext() ) {
8901                 return false;
8902             }
8903             Phylogeny p_27 = p.next();
8904             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8905                 System.out.println( p_27.toNewHampshireX() );
8906                 System.exit( -1 );
8907                 return false;
8908             }
8909             if ( p.hasNext() ) {
8910                 return false;
8911             }
8912             if ( p.next() != null ) {
8913                 return false;
8914             }
8915             p.reset();
8916             if ( !p.hasNext() ) {
8917                 return false;
8918             }
8919             p_27 = p.next();
8920             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8921                 System.out.println( p_27.toNewHampshireX() );
8922                 System.exit( -1 );
8923                 return false;
8924             }
8925             if ( p.hasNext() ) {
8926                 return false;
8927             }
8928             if ( p.next() != null ) {
8929                 return false;
8930             }
8931             //
8932             final String p30_str = "(A,B);(C,D)";
8933             final NHXParser p30 = new NHXParser();
8934             p30.setSource( p30_str );
8935             if ( !p30.hasNext() ) {
8936                 return false;
8937             }
8938             Phylogeny phy30 = p30.next();
8939             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8940                 System.out.println( phy30.toNewHampshire() );
8941                 return false;
8942             }
8943             if ( !p30.hasNext() ) {
8944                 return false;
8945             }
8946             Phylogeny phy301 = p30.next();
8947             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8948                 System.out.println( phy301.toNewHampshire() );
8949                 return false;
8950             }
8951             if ( p30.hasNext() ) {
8952                 return false;
8953             }
8954             if ( p30.hasNext() ) {
8955                 return false;
8956             }
8957             if ( p30.next() != null ) {
8958                 return false;
8959             }
8960             if ( p30.next() != null ) {
8961                 return false;
8962             }
8963             p30.reset();
8964             if ( !p30.hasNext() ) {
8965                 return false;
8966             }
8967             phy30 = p30.next();
8968             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8969                 System.out.println( phy30.toNewHampshire() );
8970                 return false;
8971             }
8972             if ( !p30.hasNext() ) {
8973                 return false;
8974             }
8975             phy301 = p30.next();
8976             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8977                 System.out.println( phy301.toNewHampshire() );
8978                 return false;
8979             }
8980             if ( p30.hasNext() ) {
8981                 return false;
8982             }
8983             if ( p30.hasNext() ) {
8984                 return false;
8985             }
8986             if ( p30.next() != null ) {
8987                 return false;
8988             }
8989             if ( p30.next() != null ) {
8990                 return false;
8991             }
8992         }
8993         catch ( final Exception e ) {
8994             e.printStackTrace( System.out );
8995             return false;
8996         }
8997         return true;
8998     }
8999
9000     private static boolean testNHXconversion() {
9001         try {
9002             final PhylogenyNode n1 = new PhylogenyNode();
9003             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9004             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9005             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9006             final PhylogenyNode n5 = PhylogenyNode
9007                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9008             final PhylogenyNode n6 = PhylogenyNode
9009                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9010             if ( !n1.toNewHampshireX().equals( "" ) ) {
9011                 return false;
9012             }
9013             if ( !n2.toNewHampshireX().equals( "" ) ) {
9014                 return false;
9015             }
9016             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9017                 return false;
9018             }
9019             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9020                 return false;
9021             }
9022             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9023                 return false;
9024             }
9025             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9026                 System.out.println( n6.toNewHampshireX() );
9027                 return false;
9028             }
9029             final PhylogenyNode n7 = new PhylogenyNode();
9030             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9031             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9032                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9033                 System.out.println( n7
9034                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9035                 return false;
9036             }
9037         }
9038         catch ( final Exception e ) {
9039             e.printStackTrace( System.out );
9040             return false;
9041         }
9042         return true;
9043     }
9044
9045     private static boolean testNHXNodeParsing() {
9046         try {
9047             final PhylogenyNode n1 = new PhylogenyNode();
9048             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9049             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9050             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9051             final PhylogenyNode n5 = PhylogenyNode
9052                     .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]" );
9053             if ( !n3.getName().equals( "n3" ) ) {
9054                 return false;
9055             }
9056             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9057                 return false;
9058             }
9059             if ( n3.isDuplication() ) {
9060                 return false;
9061             }
9062             if ( n3.isHasAssignedEvent() ) {
9063                 return false;
9064             }
9065             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9066                 return false;
9067             }
9068             if ( !n4.getName().equals( "n4" ) ) {
9069                 return false;
9070             }
9071             if ( n4.getDistanceToParent() != 0.01 ) {
9072                 return false;
9073             }
9074             if ( !n5.getName().equals( "n5" ) ) {
9075                 return false;
9076             }
9077             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9078                 return false;
9079             }
9080             if ( n5.getDistanceToParent() != 0.1 ) {
9081                 return false;
9082             }
9083             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9084                 return false;
9085             }
9086             if ( !n5.isDuplication() ) {
9087                 return false;
9088             }
9089             if ( !n5.isHasAssignedEvent() ) {
9090                 return false;
9091             }
9092             final PhylogenyNode n8 = PhylogenyNode
9093                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9094                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9095             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9096                 return false;
9097             }
9098             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9099                 return false;
9100             }
9101             final PhylogenyNode n9 = PhylogenyNode
9102                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9103                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9104             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9105                 return false;
9106             }
9107             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9108                 return false;
9109             }
9110             final PhylogenyNode n10 = PhylogenyNode
9111                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9112             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9113                 return false;
9114             }
9115             final PhylogenyNode n20 = PhylogenyNode
9116                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9117             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9118                 return false;
9119             }
9120             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9121                 return false;
9122             }
9123             final PhylogenyNode n20x = PhylogenyNode
9124                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9125             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9126                 return false;
9127             }
9128             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9129                 return false;
9130             }
9131             final PhylogenyNode n20xx = PhylogenyNode
9132                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9133             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9134                 return false;
9135             }
9136             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9137                 return false;
9138             }
9139             final PhylogenyNode n20xxx = PhylogenyNode
9140                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9141             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9142                 return false;
9143             }
9144             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9145                 return false;
9146             }
9147             final PhylogenyNode n20xxxx = PhylogenyNode
9148                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9149             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9150                 return false;
9151             }
9152             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9153                 return false;
9154             }
9155             final PhylogenyNode n21 = PhylogenyNode
9156                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9157             if ( !n21.getName().equals( "N21_PIG" ) ) {
9158                 return false;
9159             }
9160             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9161                 return false;
9162             }
9163             final PhylogenyNode n21x = PhylogenyNode
9164                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9165             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9166                 return false;
9167             }
9168             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9169                 return false;
9170             }
9171             final PhylogenyNode n22 = PhylogenyNode
9172                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9173             if ( !n22.getName().equals( "n22/PIG" ) ) {
9174                 return false;
9175             }
9176             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9177                 return false;
9178             }
9179             final PhylogenyNode n23 = PhylogenyNode
9180                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9181             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9182                 return false;
9183             }
9184             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9185                 return false;
9186             }
9187             final PhylogenyNode a = PhylogenyNode
9188                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9189             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9190                 return false;
9191             }
9192             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9193                 return false;
9194             }
9195             final PhylogenyNode c1 = PhylogenyNode
9196                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9197                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9198             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9199                 return false;
9200             }
9201             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9202                 return false;
9203             }
9204             final PhylogenyNode c2 = PhylogenyNode
9205                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9206                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9207             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9208                 return false;
9209             }
9210             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9211                 return false;
9212             }
9213             final PhylogenyNode e3 = PhylogenyNode
9214                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9215             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9216                 return false;
9217             }
9218             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9219                 return false;
9220             }
9221             final PhylogenyNode n11 = PhylogenyNode
9222                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9223                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9224             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9225                 return false;
9226             }
9227             if ( n11.getDistanceToParent() != 0.4 ) {
9228                 return false;
9229             }
9230             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9231                 return false;
9232             }
9233             final PhylogenyNode n12 = PhylogenyNode
9234                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9235                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9236             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9237                 return false;
9238             }
9239             if ( n12.getDistanceToParent() != 0.4 ) {
9240                 return false;
9241             }
9242             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9243                 return false;
9244             }
9245             final PhylogenyNode o = PhylogenyNode
9246                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9247             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9248                 return false;
9249             }
9250             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9251                 return false;
9252             }
9253             if ( n1.getName().compareTo( "" ) != 0 ) {
9254                 return false;
9255             }
9256             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9257                 return false;
9258             }
9259             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9260                 return false;
9261             }
9262             if ( n2.getName().compareTo( "" ) != 0 ) {
9263                 return false;
9264             }
9265             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9266                 return false;
9267             }
9268             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9269                 return false;
9270             }
9271             final PhylogenyNode n00 = PhylogenyNode
9272                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9273             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9274                 return false;
9275             }
9276             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9277                 return false;
9278             }
9279             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9280             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9281                 return false;
9282             }
9283             final PhylogenyNode n13 = PhylogenyNode
9284                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9285             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9286                 return false;
9287             }
9288             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9289                 return false;
9290             }
9291             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9292                 return false;
9293             }
9294             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9295                 return false;
9296             }
9297             final PhylogenyNode n14 = PhylogenyNode
9298                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9299             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9300                 return false;
9301             }
9302             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9303                 return false;
9304             }
9305             final PhylogenyNode n15 = PhylogenyNode
9306                     .createInstanceFromNhxString( "something_wicked[123]",
9307                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9308             if ( !n15.getName().equals( "something_wicked" ) ) {
9309                 return false;
9310             }
9311             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9312                 return false;
9313             }
9314             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9315                 return false;
9316             }
9317             final PhylogenyNode n16 = PhylogenyNode
9318                     .createInstanceFromNhxString( "something_wicked2[9]",
9319                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9320             if ( !n16.getName().equals( "something_wicked2" ) ) {
9321                 return false;
9322             }
9323             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9324                 return false;
9325             }
9326             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9327                 return false;
9328             }
9329             final PhylogenyNode n17 = PhylogenyNode
9330                     .createInstanceFromNhxString( "something_wicked3[a]",
9331                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9332             if ( !n17.getName().equals( "something_wicked3" ) ) {
9333                 return false;
9334             }
9335             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9336                 return false;
9337             }
9338             final PhylogenyNode n18 = PhylogenyNode
9339                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9340             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9341                 return false;
9342             }
9343             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9344                 return false;
9345             }
9346             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9347                 return false;
9348             }
9349             final PhylogenyNode n19 = PhylogenyNode
9350                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9351             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9352                 return false;
9353             }
9354             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9355                 return false;
9356             }
9357             final PhylogenyNode n30 = PhylogenyNode
9358                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9359                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9360             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9361                 return false;
9362             }
9363             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9364                 return false;
9365             }
9366             final PhylogenyNode n31 = PhylogenyNode
9367                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9368                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9369             if ( n31.getNodeData().isHasTaxonomy() ) {
9370                 return false;
9371             }
9372             final PhylogenyNode n32 = PhylogenyNode
9373                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9374             if ( n32.getNodeData().isHasTaxonomy() ) {
9375                 return false;
9376             }
9377             final PhylogenyNode n40 = PhylogenyNode
9378                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9379             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9380                 return false;
9381             }
9382             final PhylogenyNode n41 = PhylogenyNode
9383                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9384             if ( n41.getNodeData().isHasTaxonomy() ) {
9385                 return false;
9386             }
9387             final PhylogenyNode n42 = PhylogenyNode
9388                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9389             if ( n42.getNodeData().isHasTaxonomy() ) {
9390                 return false;
9391             }
9392             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9393                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9394             if ( n43.getNodeData().isHasTaxonomy() ) {
9395                 return false;
9396             }
9397             final PhylogenyNode n44 = PhylogenyNode
9398                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9399             if ( n44.getNodeData().isHasTaxonomy() ) {
9400                 return false;
9401             }
9402         }
9403         catch ( final Exception e ) {
9404             e.printStackTrace( System.out );
9405             return false;
9406         }
9407         return true;
9408     }
9409
9410     private static boolean testNHXParsing() {
9411         try {
9412             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9413             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9414             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9415                 return false;
9416             }
9417             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]";
9418             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9419             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9420                 return false;
9421             }
9422             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]";
9423             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9424             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9425                 return false;
9426             }
9427             final Phylogeny[] p3 = factory
9428                     .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]",
9429                              new NHXParser() );
9430             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9431                 return false;
9432             }
9433             final Phylogeny[] p4 = factory
9434                     .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(]",
9435                              new NHXParser() );
9436             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9437                 return false;
9438             }
9439             final Phylogeny[] p5 = factory
9440                     .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(((]",
9441                              new NHXParser() );
9442             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9443                 return false;
9444             }
9445             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)";
9446             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)";
9447             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9448             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9449                 return false;
9450             }
9451             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)))";
9452             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)))";
9453             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9454             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9455                 return false;
9456             }
9457             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])   ))[,,, ])))))))";
9458             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9459             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9460             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9461                 return false;
9462             }
9463             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9464             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9465                 return false;
9466             }
9467             final Phylogeny p10 = factory
9468                     .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]",
9469                              new NHXParser() )[ 0 ];
9470             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9471                 return false;
9472             }
9473             final Phylogeny p11 = factory
9474                     .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]",
9475                              new NHXParser() )[ 0 ];
9476             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9477                 return false;
9478             }
9479             final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
9480                                                   new NHXParser() )[ 0 ];
9481             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9482                 return false;
9483             }
9484         }
9485         catch ( final Exception e ) {
9486             e.printStackTrace( System.out );
9487             return false;
9488         }
9489         return true;
9490     }
9491
9492     private static boolean testNHXParsingMB() {
9493         try {
9494             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9495             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+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}])", new NHXParser() )[ 0 ];
9504             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9505                 return false;
9506             }
9507             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9508                 return false;
9509             }
9510             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9511                            0.1100000000000000e+00 ) ) {
9512                 return false;
9513             }
9514             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9515                 return false;
9516             }
9517             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9518                 return false;
9519             }
9520             final Phylogeny p2 = factory
9521                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9522                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9523                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9524                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9525                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9526                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9527                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9528                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9529                             + "7.369400000000000e-02}])",
9530                             new NHXParser() )[ 0 ];
9531             if ( p2.getNode( "1" ) == null ) {
9532                 return false;
9533             }
9534             if ( p2.getNode( "2" ) == null ) {
9535                 return false;
9536             }
9537         }
9538         catch ( final Exception e ) {
9539             e.printStackTrace( System.out );
9540             System.exit( -1 );
9541             return false;
9542         }
9543         return true;
9544     }
9545
9546     private static boolean testNHXParsingQuotes() {
9547         try {
9548             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9549             final NHXParser p = new NHXParser();
9550             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9551             if ( phylogenies_0.length != 5 ) {
9552                 return false;
9553             }
9554             final Phylogeny phy = phylogenies_0[ 4 ];
9555             if ( phy.getNumberOfExternalNodes() != 7 ) {
9556                 return false;
9557             }
9558             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9559                 return false;
9560             }
9561             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9562                 return false;
9563             }
9564             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9565                     .getScientificName().equals( "hsapiens" ) ) {
9566                 return false;
9567             }
9568             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9569                 return false;
9570             }
9571             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9572                 return false;
9573             }
9574             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9575                 return false;
9576             }
9577             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9578                 return false;
9579             }
9580             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9581                 return false;
9582             }
9583             final NHXParser p1p = new NHXParser();
9584             p1p.setIgnoreQuotes( true );
9585             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9586             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9587                 return false;
9588             }
9589             final NHXParser p2p = new NHXParser();
9590             p1p.setIgnoreQuotes( false );
9591             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9592             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9593                 return false;
9594             }
9595             final NHXParser p3p = new NHXParser();
9596             p3p.setIgnoreQuotes( false );
9597             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9598             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9599                 return false;
9600             }
9601             final NHXParser p4p = new NHXParser();
9602             p4p.setIgnoreQuotes( false );
9603             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9604             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9605                 return false;
9606             }
9607             final Phylogeny p10 = factory
9608                     .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]",
9609                              new NHXParser() )[ 0 ];
9610             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]";
9611             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9612                 return false;
9613             }
9614             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9615             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9616                 return false;
9617             }
9618             final Phylogeny p12 = factory
9619                     .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]",
9620                              new NHXParser() )[ 0 ];
9621             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]";
9622             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9623                 return false;
9624             }
9625             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9626             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9627                 return false;
9628             }
9629             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;";
9630             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9631                 return false;
9632             }
9633             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9634             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
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 testNodeRemoval() {
9646         try {
9647             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9648             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9649             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9650             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9651                 return false;
9652             }
9653             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9654             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9655             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9656                 return false;
9657             }
9658             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9659             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9660             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9661                 return false;
9662             }
9663         }
9664         catch ( final Exception e ) {
9665             e.printStackTrace( System.out );
9666             return false;
9667         }
9668         return true;
9669     }
9670
9671     private static boolean testPhylogenyBranch() {
9672         try {
9673             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9674             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9675             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9676             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9677             if ( !a1b1.equals( a1b1 ) ) {
9678                 return false;
9679             }
9680             if ( !a1b1.equals( b1a1 ) ) {
9681                 return false;
9682             }
9683             if ( !b1a1.equals( a1b1 ) ) {
9684                 return false;
9685             }
9686             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9687             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9688             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9689             if ( a1_b1.equals( b1_a1 ) ) {
9690                 return false;
9691             }
9692             if ( a1_b1.equals( a1_b1_ ) ) {
9693                 return false;
9694             }
9695             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9696             if ( !a1_b1.equals( b1_a1_ ) ) {
9697                 return false;
9698             }
9699             if ( a1_b1_.equals( b1_a1_ ) ) {
9700                 return false;
9701             }
9702             if ( !a1_b1_.equals( b1_a1 ) ) {
9703                 return false;
9704             }
9705         }
9706         catch ( final Exception e ) {
9707             e.printStackTrace( System.out );
9708             return false;
9709         }
9710         return true;
9711     }
9712
9713     private static boolean testPhyloXMLparsingOfDistributionElement() {
9714         try {
9715             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9716             PhyloXmlParser xml_parser = null;
9717             try {
9718                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9719             }
9720             catch ( final Exception e ) {
9721                 // Do nothing -- means were not running from jar.
9722             }
9723             if ( xml_parser == null ) {
9724                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9725                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9726                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9727                 }
9728                 else {
9729                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9730                 }
9731             }
9732             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9733                                                               xml_parser );
9734             if ( xml_parser.getErrorCount() > 0 ) {
9735                 System.out.println( xml_parser.getErrorMessages().toString() );
9736                 return false;
9737             }
9738             if ( phylogenies_0.length != 1 ) {
9739                 return false;
9740             }
9741             final Phylogeny t1 = phylogenies_0[ 0 ];
9742             PhylogenyNode n = null;
9743             Distribution d = null;
9744             n = t1.getNode( "root node" );
9745             if ( !n.getNodeData().isHasDistribution() ) {
9746                 return false;
9747             }
9748             if ( n.getNodeData().getDistributions().size() != 1 ) {
9749                 return false;
9750             }
9751             d = n.getNodeData().getDistribution();
9752             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9753                 return false;
9754             }
9755             if ( d.getPoints().size() != 1 ) {
9756                 return false;
9757             }
9758             if ( d.getPolygons() != null ) {
9759                 return false;
9760             }
9761             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9762                 return false;
9763             }
9764             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9765                 return false;
9766             }
9767             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9768                 return false;
9769             }
9770             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9771                 return false;
9772             }
9773             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9774                 return false;
9775             }
9776             n = t1.getNode( "node a" );
9777             if ( !n.getNodeData().isHasDistribution() ) {
9778                 return false;
9779             }
9780             if ( n.getNodeData().getDistributions().size() != 2 ) {
9781                 return false;
9782             }
9783             d = n.getNodeData().getDistribution( 1 );
9784             if ( !d.getDesc().equals( "San Diego" ) ) {
9785                 return false;
9786             }
9787             if ( d.getPoints().size() != 1 ) {
9788                 return false;
9789             }
9790             if ( d.getPolygons() != null ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9797                 return false;
9798             }
9799             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9800                 return false;
9801             }
9802             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9803                 return false;
9804             }
9805             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9806                 return false;
9807             }
9808             n = t1.getNode( "node bb" );
9809             if ( !n.getNodeData().isHasDistribution() ) {
9810                 return false;
9811             }
9812             if ( n.getNodeData().getDistributions().size() != 1 ) {
9813                 return false;
9814             }
9815             d = n.getNodeData().getDistribution( 0 );
9816             if ( d.getPoints().size() != 3 ) {
9817                 return false;
9818             }
9819             if ( d.getPolygons().size() != 2 ) {
9820                 return false;
9821             }
9822             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9823                 return false;
9824             }
9825             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9826                 return false;
9827             }
9828             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9829                 return false;
9830             }
9831             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9832                 return false;
9833             }
9834             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9835                 return false;
9836             }
9837             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9838                 return false;
9839             }
9840             Polygon p = d.getPolygons().get( 0 );
9841             if ( p.getPoints().size() != 3 ) {
9842                 return false;
9843             }
9844             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9845                 return false;
9846             }
9847             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9848                 return false;
9849             }
9850             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9851                 return false;
9852             }
9853             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9854                 return false;
9855             }
9856             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9857                 return false;
9858             }
9859             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9860                 return false;
9861             }
9862             p = d.getPolygons().get( 1 );
9863             if ( p.getPoints().size() != 3 ) {
9864                 return false;
9865             }
9866             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9867                 return false;
9868             }
9869             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9870                 return false;
9871             }
9872             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9873                 return false;
9874             }
9875             // Roundtrip:
9876             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9877             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9878             if ( rt.length != 1 ) {
9879                 return false;
9880             }
9881             final Phylogeny t1_rt = rt[ 0 ];
9882             n = t1_rt.getNode( "root node" );
9883             if ( !n.getNodeData().isHasDistribution() ) {
9884                 return false;
9885             }
9886             if ( n.getNodeData().getDistributions().size() != 1 ) {
9887                 return false;
9888             }
9889             d = n.getNodeData().getDistribution();
9890             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9891                 return false;
9892             }
9893             if ( d.getPoints().size() != 1 ) {
9894                 return false;
9895             }
9896             if ( d.getPolygons() != null ) {
9897                 return false;
9898             }
9899             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9900                 return false;
9901             }
9902             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9903                 return false;
9904             }
9905             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9906                 return false;
9907             }
9908             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9909                 return false;
9910             }
9911             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9912                 return false;
9913             }
9914             n = t1_rt.getNode( "node a" );
9915             if ( !n.getNodeData().isHasDistribution() ) {
9916                 return false;
9917             }
9918             if ( n.getNodeData().getDistributions().size() != 2 ) {
9919                 return false;
9920             }
9921             d = n.getNodeData().getDistribution( 1 );
9922             if ( !d.getDesc().equals( "San Diego" ) ) {
9923                 return false;
9924             }
9925             if ( d.getPoints().size() != 1 ) {
9926                 return false;
9927             }
9928             if ( d.getPolygons() != null ) {
9929                 return false;
9930             }
9931             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9935                 return false;
9936             }
9937             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9938                 return false;
9939             }
9940             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9941                 return false;
9942             }
9943             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9944                 return false;
9945             }
9946             n = t1_rt.getNode( "node bb" );
9947             if ( !n.getNodeData().isHasDistribution() ) {
9948                 return false;
9949             }
9950             if ( n.getNodeData().getDistributions().size() != 1 ) {
9951                 return false;
9952             }
9953             d = n.getNodeData().getDistribution( 0 );
9954             if ( d.getPoints().size() != 3 ) {
9955                 return false;
9956             }
9957             if ( d.getPolygons().size() != 2 ) {
9958                 return false;
9959             }
9960             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9961                 return false;
9962             }
9963             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9964                 return false;
9965             }
9966             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9967                 return false;
9968             }
9969             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9970                 return false;
9971             }
9972             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9973                 return false;
9974             }
9975             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9976                 return false;
9977             }
9978             p = d.getPolygons().get( 0 );
9979             if ( p.getPoints().size() != 3 ) {
9980                 return false;
9981             }
9982             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9983                 return false;
9984             }
9985             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9986                 return false;
9987             }
9988             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9989                 return false;
9990             }
9991             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9992                 return false;
9993             }
9994             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9995                 return false;
9996             }
9997             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9998                 return false;
9999             }
10000             p = d.getPolygons().get( 1 );
10001             if ( p.getPoints().size() != 3 ) {
10002                 return false;
10003             }
10004             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10005                 return false;
10006             }
10007             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10008                 return false;
10009             }
10010             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10011                 return false;
10012             }
10013         }
10014         catch ( final Exception e ) {
10015             e.printStackTrace( System.out );
10016             return false;
10017         }
10018         return true;
10019     }
10020
10021     private static boolean testPostOrderIterator() {
10022         try {
10023             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10024             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10025             PhylogenyNodeIterator it0;
10026             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10027                 it0.next();
10028             }
10029             for( it0.reset(); it0.hasNext(); ) {
10030                 it0.next();
10031             }
10032             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10033             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10034             if ( !it.next().getName().equals( "A" ) ) {
10035                 return false;
10036             }
10037             if ( !it.next().getName().equals( "B" ) ) {
10038                 return false;
10039             }
10040             if ( !it.next().getName().equals( "ab" ) ) {
10041                 return false;
10042             }
10043             if ( !it.next().getName().equals( "C" ) ) {
10044                 return false;
10045             }
10046             if ( !it.next().getName().equals( "D" ) ) {
10047                 return false;
10048             }
10049             if ( !it.next().getName().equals( "cd" ) ) {
10050                 return false;
10051             }
10052             if ( !it.next().getName().equals( "abcd" ) ) {
10053                 return false;
10054             }
10055             if ( !it.next().getName().equals( "E" ) ) {
10056                 return false;
10057             }
10058             if ( !it.next().getName().equals( "F" ) ) {
10059                 return false;
10060             }
10061             if ( !it.next().getName().equals( "ef" ) ) {
10062                 return false;
10063             }
10064             if ( !it.next().getName().equals( "G" ) ) {
10065                 return false;
10066             }
10067             if ( !it.next().getName().equals( "H" ) ) {
10068                 return false;
10069             }
10070             if ( !it.next().getName().equals( "gh" ) ) {
10071                 return false;
10072             }
10073             if ( !it.next().getName().equals( "efgh" ) ) {
10074                 return false;
10075             }
10076             if ( !it.next().getName().equals( "r" ) ) {
10077                 return false;
10078             }
10079             if ( it.hasNext() ) {
10080                 return false;
10081             }
10082         }
10083         catch ( final Exception e ) {
10084             e.printStackTrace( System.out );
10085             return false;
10086         }
10087         return true;
10088     }
10089
10090     private static boolean testPreOrderIterator() {
10091         try {
10092             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10093             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10094             PhylogenyNodeIterator it0;
10095             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10096                 it0.next();
10097             }
10098             for( it0.reset(); it0.hasNext(); ) {
10099                 it0.next();
10100             }
10101             PhylogenyNodeIterator it = t0.iteratorPreorder();
10102             if ( !it.next().getName().equals( "r" ) ) {
10103                 return false;
10104             }
10105             if ( !it.next().getName().equals( "ab" ) ) {
10106                 return false;
10107             }
10108             if ( !it.next().getName().equals( "A" ) ) {
10109                 return false;
10110             }
10111             if ( !it.next().getName().equals( "B" ) ) {
10112                 return false;
10113             }
10114             if ( !it.next().getName().equals( "cd" ) ) {
10115                 return false;
10116             }
10117             if ( !it.next().getName().equals( "C" ) ) {
10118                 return false;
10119             }
10120             if ( !it.next().getName().equals( "D" ) ) {
10121                 return false;
10122             }
10123             if ( it.hasNext() ) {
10124                 return false;
10125             }
10126             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10127             it = t1.iteratorPreorder();
10128             if ( !it.next().getName().equals( "r" ) ) {
10129                 return false;
10130             }
10131             if ( !it.next().getName().equals( "abcd" ) ) {
10132                 return false;
10133             }
10134             if ( !it.next().getName().equals( "ab" ) ) {
10135                 return false;
10136             }
10137             if ( !it.next().getName().equals( "A" ) ) {
10138                 return false;
10139             }
10140             if ( !it.next().getName().equals( "B" ) ) {
10141                 return false;
10142             }
10143             if ( !it.next().getName().equals( "cd" ) ) {
10144                 return false;
10145             }
10146             if ( !it.next().getName().equals( "C" ) ) {
10147                 return false;
10148             }
10149             if ( !it.next().getName().equals( "D" ) ) {
10150                 return false;
10151             }
10152             if ( !it.next().getName().equals( "efgh" ) ) {
10153                 return false;
10154             }
10155             if ( !it.next().getName().equals( "ef" ) ) {
10156                 return false;
10157             }
10158             if ( !it.next().getName().equals( "E" ) ) {
10159                 return false;
10160             }
10161             if ( !it.next().getName().equals( "F" ) ) {
10162                 return false;
10163             }
10164             if ( !it.next().getName().equals( "gh" ) ) {
10165                 return false;
10166             }
10167             if ( !it.next().getName().equals( "G" ) ) {
10168                 return false;
10169             }
10170             if ( !it.next().getName().equals( "H" ) ) {
10171                 return false;
10172             }
10173             if ( it.hasNext() ) {
10174                 return false;
10175             }
10176         }
10177         catch ( final Exception e ) {
10178             e.printStackTrace( System.out );
10179             return false;
10180         }
10181         return true;
10182     }
10183
10184     private static boolean testPropertiesMap() {
10185         try {
10186             final PropertiesMap pm = new PropertiesMap();
10187             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10188             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10189             final Property p2 = new Property( "something:else",
10190                                               "?",
10191                                               "improbable:research",
10192                                               "xsd:decimal",
10193                                               AppliesTo.NODE );
10194             pm.addProperty( p0 );
10195             pm.addProperty( p1 );
10196             pm.addProperty( p2 );
10197             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10198                 return false;
10199             }
10200             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10201                 return false;
10202             }
10203             if ( pm.getProperties().size() != 3 ) {
10204                 return false;
10205             }
10206             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10207                 return false;
10208             }
10209             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10210                 return false;
10211             }
10212             if ( pm.getProperties().size() != 3 ) {
10213                 return false;
10214             }
10215             pm.removeProperty( "dimensions:diameter" );
10216             if ( pm.getProperties().size() != 2 ) {
10217                 return false;
10218             }
10219             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10220                 return false;
10221             }
10222             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10223                 return false;
10224             }
10225         }
10226         catch ( final Exception e ) {
10227             e.printStackTrace( System.out );
10228             return false;
10229         }
10230         return true;
10231     }
10232
10233     private static boolean testProteinId() {
10234         try {
10235             final ProteinId id1 = new ProteinId( "a" );
10236             final ProteinId id2 = new ProteinId( "a" );
10237             final ProteinId id3 = new ProteinId( "A" );
10238             final ProteinId id4 = new ProteinId( "b" );
10239             if ( !id1.equals( id1 ) ) {
10240                 return false;
10241             }
10242             if ( id1.getId().equals( "x" ) ) {
10243                 return false;
10244             }
10245             if ( id1.getId().equals( null ) ) {
10246                 return false;
10247             }
10248             if ( !id1.equals( id2 ) ) {
10249                 return false;
10250             }
10251             if ( id1.equals( id3 ) ) {
10252                 return false;
10253             }
10254             if ( id1.hashCode() != id1.hashCode() ) {
10255                 return false;
10256             }
10257             if ( id1.hashCode() != id2.hashCode() ) {
10258                 return false;
10259             }
10260             if ( id1.hashCode() == id3.hashCode() ) {
10261                 return false;
10262             }
10263             if ( id1.compareTo( id1 ) != 0 ) {
10264                 return false;
10265             }
10266             if ( id1.compareTo( id2 ) != 0 ) {
10267                 return false;
10268             }
10269             if ( id1.compareTo( id3 ) != 0 ) {
10270                 return false;
10271             }
10272             if ( id1.compareTo( id4 ) >= 0 ) {
10273                 return false;
10274             }
10275             if ( id4.compareTo( id1 ) <= 0 ) {
10276                 return false;
10277             }
10278             if ( !id4.getId().equals( "b" ) ) {
10279                 return false;
10280             }
10281             final ProteinId id5 = new ProteinId( " C " );
10282             if ( !id5.getId().equals( "C" ) ) {
10283                 return false;
10284             }
10285             if ( id5.equals( id1 ) ) {
10286                 return false;
10287             }
10288         }
10289         catch ( final Exception e ) {
10290             e.printStackTrace( System.out );
10291             return false;
10292         }
10293         return true;
10294     }
10295
10296     private static boolean testReIdMethods() {
10297         try {
10298             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10299             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10300             final long count = PhylogenyNode.getNodeCount();
10301             p.levelOrderReID();
10302             if ( p.getNode( "r" ).getId() != count ) {
10303                 return false;
10304             }
10305             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10306                 return false;
10307             }
10308             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10309                 return false;
10310             }
10311             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10312                 return false;
10313             }
10314             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10315                 return false;
10316             }
10317             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10318                 return false;
10319             }
10320             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10321                 return false;
10322             }
10323             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10324                 return false;
10325             }
10326             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10327                 return false;
10328             }
10329             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10330                 return false;
10331             }
10332             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10333                 return false;
10334             }
10335             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10336                 return false;
10337             }
10338             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10339                 return false;
10340             }
10341             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10342                 return false;
10343             }
10344             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10345                 return false;
10346             }
10347         }
10348         catch ( final Exception e ) {
10349             e.printStackTrace( System.out );
10350             return false;
10351         }
10352         return true;
10353     }
10354
10355     private static boolean testRerooting() {
10356         try {
10357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10358             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",
10359                                                  new NHXParser() )[ 0 ];
10360             if ( !t1.isRooted() ) {
10361                 return false;
10362             }
10363             t1.reRoot( t1.getNode( "D" ) );
10364             t1.reRoot( t1.getNode( "CD" ) );
10365             t1.reRoot( t1.getNode( "A" ) );
10366             t1.reRoot( t1.getNode( "B" ) );
10367             t1.reRoot( t1.getNode( "AB" ) );
10368             t1.reRoot( t1.getNode( "D" ) );
10369             t1.reRoot( t1.getNode( "C" ) );
10370             t1.reRoot( t1.getNode( "CD" ) );
10371             t1.reRoot( t1.getNode( "A" ) );
10372             t1.reRoot( t1.getNode( "B" ) );
10373             t1.reRoot( t1.getNode( "AB" ) );
10374             t1.reRoot( t1.getNode( "D" ) );
10375             t1.reRoot( t1.getNode( "D" ) );
10376             t1.reRoot( t1.getNode( "C" ) );
10377             t1.reRoot( t1.getNode( "A" ) );
10378             t1.reRoot( t1.getNode( "B" ) );
10379             t1.reRoot( t1.getNode( "AB" ) );
10380             t1.reRoot( t1.getNode( "C" ) );
10381             t1.reRoot( t1.getNode( "D" ) );
10382             t1.reRoot( t1.getNode( "CD" ) );
10383             t1.reRoot( t1.getNode( "D" ) );
10384             t1.reRoot( t1.getNode( "A" ) );
10385             t1.reRoot( t1.getNode( "B" ) );
10386             t1.reRoot( t1.getNode( "AB" ) );
10387             t1.reRoot( t1.getNode( "C" ) );
10388             t1.reRoot( t1.getNode( "D" ) );
10389             t1.reRoot( t1.getNode( "CD" ) );
10390             t1.reRoot( t1.getNode( "D" ) );
10391             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10392                 return false;
10393             }
10394             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10395                 return false;
10396             }
10397             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10398                 return false;
10399             }
10400             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10401                 return false;
10402             }
10403             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10404                 return false;
10405             }
10406             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10407                 return false;
10408             }
10409             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",
10410                                                  new NHXParser() )[ 0 ];
10411             t2.reRoot( t2.getNode( "A" ) );
10412             t2.reRoot( t2.getNode( "D" ) );
10413             t2.reRoot( t2.getNode( "ABC" ) );
10414             t2.reRoot( t2.getNode( "A" ) );
10415             t2.reRoot( t2.getNode( "B" ) );
10416             t2.reRoot( t2.getNode( "D" ) );
10417             t2.reRoot( t2.getNode( "C" ) );
10418             t2.reRoot( t2.getNode( "ABC" ) );
10419             t2.reRoot( t2.getNode( "A" ) );
10420             t2.reRoot( t2.getNode( "B" ) );
10421             t2.reRoot( t2.getNode( "AB" ) );
10422             t2.reRoot( t2.getNode( "AB" ) );
10423             t2.reRoot( t2.getNode( "D" ) );
10424             t2.reRoot( t2.getNode( "C" ) );
10425             t2.reRoot( t2.getNode( "B" ) );
10426             t2.reRoot( t2.getNode( "AB" ) );
10427             t2.reRoot( t2.getNode( "D" ) );
10428             t2.reRoot( t2.getNode( "D" ) );
10429             t2.reRoot( t2.getNode( "ABC" ) );
10430             t2.reRoot( t2.getNode( "A" ) );
10431             t2.reRoot( t2.getNode( "B" ) );
10432             t2.reRoot( t2.getNode( "AB" ) );
10433             t2.reRoot( t2.getNode( "D" ) );
10434             t2.reRoot( t2.getNode( "C" ) );
10435             t2.reRoot( t2.getNode( "ABC" ) );
10436             t2.reRoot( t2.getNode( "A" ) );
10437             t2.reRoot( t2.getNode( "B" ) );
10438             t2.reRoot( t2.getNode( "AB" ) );
10439             t2.reRoot( t2.getNode( "D" ) );
10440             t2.reRoot( t2.getNode( "D" ) );
10441             t2.reRoot( t2.getNode( "C" ) );
10442             t2.reRoot( t2.getNode( "A" ) );
10443             t2.reRoot( t2.getNode( "B" ) );
10444             t2.reRoot( t2.getNode( "AB" ) );
10445             t2.reRoot( t2.getNode( "C" ) );
10446             t2.reRoot( t2.getNode( "D" ) );
10447             t2.reRoot( t2.getNode( "ABC" ) );
10448             t2.reRoot( t2.getNode( "D" ) );
10449             t2.reRoot( t2.getNode( "A" ) );
10450             t2.reRoot( t2.getNode( "B" ) );
10451             t2.reRoot( t2.getNode( "AB" ) );
10452             t2.reRoot( t2.getNode( "C" ) );
10453             t2.reRoot( t2.getNode( "D" ) );
10454             t2.reRoot( t2.getNode( "ABC" ) );
10455             t2.reRoot( t2.getNode( "D" ) );
10456             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10457                 return false;
10458             }
10459             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10460                 return false;
10461             }
10462             t2.reRoot( t2.getNode( "ABC" ) );
10463             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10464                 return false;
10465             }
10466             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10467                 return false;
10468             }
10469             t2.reRoot( t2.getNode( "AB" ) );
10470             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10471                 return false;
10472             }
10473             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10474                 return false;
10475             }
10476             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10477                 return false;
10478             }
10479             t2.reRoot( t2.getNode( "AB" ) );
10480             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10481                 return false;
10482             }
10483             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10484                 return false;
10485             }
10486             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10487                 return false;
10488             }
10489             t2.reRoot( t2.getNode( "D" ) );
10490             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10491                 return false;
10492             }
10493             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10494                 return false;
10495             }
10496             t2.reRoot( t2.getNode( "ABC" ) );
10497             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10498                 return false;
10499             }
10500             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10501                 return false;
10502             }
10503             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10504                                                  new NHXParser() )[ 0 ];
10505             t3.reRoot( t3.getNode( "B" ) );
10506             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10507                 return false;
10508             }
10509             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10510                 return false;
10511             }
10512             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10513                 return false;
10514             }
10515             t3.reRoot( t3.getNode( "B" ) );
10516             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10517                 return false;
10518             }
10519             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10520                 return false;
10521             }
10522             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10523                 return false;
10524             }
10525             t3.reRoot( t3.getRoot() );
10526             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10527                 return false;
10528             }
10529             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10530                 return false;
10531             }
10532             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10533                 return false;
10534             }
10535         }
10536         catch ( final Exception e ) {
10537             e.printStackTrace( System.out );
10538             return false;
10539         }
10540         return true;
10541     }
10542
10543     private static boolean testSDIse() {
10544         try {
10545             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10546             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10547             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10548             gene1.setRooted( true );
10549             species1.setRooted( true );
10550             final SDI sdi = new SDI( gene1, species1 );
10551             if ( !gene1.getRoot().isDuplication() ) {
10552                 return false;
10553             }
10554             final Phylogeny species2 = factory
10555                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10556                              new NHXParser() )[ 0 ];
10557             final Phylogeny gene2 = factory
10558                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10559                              new NHXParser() )[ 0 ];
10560             species2.setRooted( true );
10561             gene2.setRooted( true );
10562             final SDI sdi2 = new SDI( gene2, species2 );
10563             if ( sdi2.getDuplicationsSum() != 0 ) {
10564                 return false;
10565             }
10566             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10567                 return false;
10568             }
10569             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10570                 return false;
10571             }
10572             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10573                 return false;
10574             }
10575             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10576                 return false;
10577             }
10578             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10579                 return false;
10580             }
10581             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10582                 return false;
10583             }
10584             final Phylogeny species3 = factory
10585                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10586                              new NHXParser() )[ 0 ];
10587             final Phylogeny gene3 = factory
10588                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10589                              new NHXParser() )[ 0 ];
10590             species3.setRooted( true );
10591             gene3.setRooted( true );
10592             final SDI sdi3 = new SDI( gene3, species3 );
10593             if ( sdi3.getDuplicationsSum() != 1 ) {
10594                 return false;
10595             }
10596             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10597                 return false;
10598             }
10599             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10600                 return false;
10601             }
10602             final Phylogeny species4 = factory
10603                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10604                              new NHXParser() )[ 0 ];
10605             final Phylogeny gene4 = factory
10606                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10607                              new NHXParser() )[ 0 ];
10608             species4.setRooted( true );
10609             gene4.setRooted( true );
10610             final SDI sdi4 = new SDI( gene4, species4 );
10611             if ( sdi4.getDuplicationsSum() != 1 ) {
10612                 return false;
10613             }
10614             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10615                 return false;
10616             }
10617             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10618                 return false;
10619             }
10620             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10621                 return false;
10622             }
10623             if ( species4.getNumberOfExternalNodes() != 6 ) {
10624                 return false;
10625             }
10626             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10627                 return false;
10628             }
10629             final Phylogeny species5 = factory
10630                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10631                              new NHXParser() )[ 0 ];
10632             final Phylogeny gene5 = factory
10633                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10634                              new NHXParser() )[ 0 ];
10635             species5.setRooted( true );
10636             gene5.setRooted( true );
10637             final SDI sdi5 = new SDI( gene5, species5 );
10638             if ( sdi5.getDuplicationsSum() != 2 ) {
10639                 return false;
10640             }
10641             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10642                 return false;
10643             }
10644             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10645                 return false;
10646             }
10647             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10648                 return false;
10649             }
10650             if ( species5.getNumberOfExternalNodes() != 6 ) {
10651                 return false;
10652             }
10653             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10654                 return false;
10655             }
10656             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10657             // Conjecture for Comparing Molecular Phylogenies"
10658             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10659             final Phylogeny species6 = factory
10660                     .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,"
10661                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10662                             new NHXParser() )[ 0 ];
10663             final Phylogeny gene6 = factory
10664                     .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,"
10665                             + "((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,"
10666                             + "(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;",
10667                             new NHXParser() )[ 0 ];
10668             species6.setRooted( true );
10669             gene6.setRooted( true );
10670             final SDI sdi6 = new SDI( gene6, species6 );
10671             if ( sdi6.getDuplicationsSum() != 3 ) {
10672                 return false;
10673             }
10674             if ( !gene6.getNode( "r" ).isDuplication() ) {
10675                 return false;
10676             }
10677             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10678                 return false;
10679             }
10680             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10681                 return false;
10682             }
10683             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10684                 return false;
10685             }
10686             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10687                 return false;
10688             }
10689             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10690                 return false;
10691             }
10692             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10693                 return false;
10694             }
10695             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10696                 return false;
10697             }
10698             sdi6.computeMappingCostL();
10699             if ( sdi6.computeMappingCostL() != 17 ) {
10700                 return false;
10701             }
10702             if ( species6.getNumberOfExternalNodes() != 9 ) {
10703                 return false;
10704             }
10705             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10706                 return false;
10707             }
10708             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10709                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10710                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10711                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10712                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10713             species7.setRooted( true );
10714             final Phylogeny gene7_1 = Test
10715                     .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])" );
10716             gene7_1.setRooted( true );
10717             final SDI sdi7 = new SDI( gene7_1, species7 );
10718             if ( sdi7.getDuplicationsSum() != 0 ) {
10719                 return false;
10720             }
10721             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10722                 return false;
10723             }
10724             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10725                 return false;
10726             }
10727             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10728                 return false;
10729             }
10730             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10731                 return false;
10732             }
10733             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10734                 return false;
10735             }
10736             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10737                 return false;
10738             }
10739             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10740                 return false;
10741             }
10742             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10743                 return false;
10744             }
10745             final Phylogeny gene7_2 = Test
10746                     .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])" );
10747             gene7_2.setRooted( true );
10748             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10749             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10750                 return false;
10751             }
10752             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10753                 return false;
10754             }
10755             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10756                 return false;
10757             }
10758             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10759                 return false;
10760             }
10761             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10762                 return false;
10763             }
10764             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10765                 return false;
10766             }
10767             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10768                 return false;
10769             }
10770             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10771                 return false;
10772             }
10773             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10774                 return false;
10775             }
10776             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10777                 return false;
10778             }
10779         }
10780         catch ( final Exception e ) {
10781             return false;
10782         }
10783         return true;
10784     }
10785
10786     private static boolean testSDIunrooted() {
10787         try {
10788             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10789             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10790             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10791             final Iterator<PhylogenyBranch> iter = l.iterator();
10792             PhylogenyBranch br = iter.next();
10793             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10794                 return false;
10795             }
10796             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10797                 return false;
10798             }
10799             br = iter.next();
10800             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10801                 return false;
10802             }
10803             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10804                 return false;
10805             }
10806             br = iter.next();
10807             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10808                 return false;
10809             }
10810             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10811                 return false;
10812             }
10813             br = iter.next();
10814             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10815                 return false;
10816             }
10817             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10818                 return false;
10819             }
10820             br = iter.next();
10821             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10822                 return false;
10823             }
10824             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10825                 return false;
10826             }
10827             br = iter.next();
10828             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10829                 return false;
10830             }
10831             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10832                 return false;
10833             }
10834             br = iter.next();
10835             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10836                 return false;
10837             }
10838             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10839                 return false;
10840             }
10841             br = iter.next();
10842             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10843                 return false;
10844             }
10845             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10846                 return false;
10847             }
10848             br = iter.next();
10849             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10850                 return false;
10851             }
10852             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10853                 return false;
10854             }
10855             br = iter.next();
10856             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10857                 return false;
10858             }
10859             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10860                 return false;
10861             }
10862             br = iter.next();
10863             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10864                 return false;
10865             }
10866             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10867                 return false;
10868             }
10869             br = iter.next();
10870             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10871                 return false;
10872             }
10873             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10874                 return false;
10875             }
10876             br = iter.next();
10877             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10878                 return false;
10879             }
10880             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10881                 return false;
10882             }
10883             br = iter.next();
10884             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10885                 return false;
10886             }
10887             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10888                 return false;
10889             }
10890             br = iter.next();
10891             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10892                 return false;
10893             }
10894             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10895                 return false;
10896             }
10897             if ( iter.hasNext() ) {
10898                 return false;
10899             }
10900             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10901             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10902             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10903             br = iter1.next();
10904             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10905                 return false;
10906             }
10907             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10908                 return false;
10909             }
10910             br = iter1.next();
10911             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10912                 return false;
10913             }
10914             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10915                 return false;
10916             }
10917             br = iter1.next();
10918             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10919                 return false;
10920             }
10921             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10922                 return false;
10923             }
10924             if ( iter1.hasNext() ) {
10925                 return false;
10926             }
10927             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10928             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10929             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10930             br = iter2.next();
10931             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10932                 return false;
10933             }
10934             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10935                 return false;
10936             }
10937             br = iter2.next();
10938             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10939                 return false;
10940             }
10941             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10942                 return false;
10943             }
10944             br = iter2.next();
10945             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10946                 return false;
10947             }
10948             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10949                 return false;
10950             }
10951             if ( iter2.hasNext() ) {
10952                 return false;
10953             }
10954             final Phylogeny species0 = factory
10955                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10956                              new NHXParser() )[ 0 ];
10957             final Phylogeny gene1 = factory
10958                     .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])",
10959                              new NHXParser() )[ 0 ];
10960             species0.setRooted( true );
10961             gene1.setRooted( true );
10962             final SDIR sdi_unrooted = new SDIR();
10963             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10964             if ( sdi_unrooted.getCount() != 1 ) {
10965                 return false;
10966             }
10967             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10968                 return false;
10969             }
10970             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10971                 return false;
10972             }
10973             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10974                 return false;
10975             }
10976             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10977                 return false;
10978             }
10979             final Phylogeny gene2 = factory
10980                     .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])",
10981                              new NHXParser() )[ 0 ];
10982             gene2.setRooted( true );
10983             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10984             if ( sdi_unrooted.getCount() != 1 ) {
10985                 return false;
10986             }
10987             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10988                 return false;
10989             }
10990             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10991                 return false;
10992             }
10993             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10994                 return false;
10995             }
10996             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10997                 return false;
10998             }
10999             final Phylogeny species6 = factory
11000                     .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,"
11001                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11002                             new NHXParser() )[ 0 ];
11003             final Phylogeny gene6 = factory
11004                     .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],"
11005                             + "(((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],"
11006                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11007                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11008                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11009                             new NHXParser() )[ 0 ];
11010             species6.setRooted( true );
11011             gene6.setRooted( true );
11012             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11013             if ( sdi_unrooted.getCount() != 1 ) {
11014                 return false;
11015             }
11016             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11017                 return false;
11018             }
11019             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11020                 return false;
11021             }
11022             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11023                 return false;
11024             }
11025             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11026                 return false;
11027             }
11028             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11029                 return false;
11030             }
11031             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11032                 return false;
11033             }
11034             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11035                 return false;
11036             }
11037             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11038                 return false;
11039             }
11040             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11041                 return false;
11042             }
11043             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11044                 return false;
11045             }
11046             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11047                 return false;
11048             }
11049             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11050                 return false;
11051             }
11052             p6 = null;
11053             final Phylogeny species7 = factory
11054                     .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,"
11055                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11056                             new NHXParser() )[ 0 ];
11057             final Phylogeny gene7 = factory
11058                     .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],"
11059                             + "(((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],"
11060                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11061                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11062                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11063                             new NHXParser() )[ 0 ];
11064             species7.setRooted( true );
11065             gene7.setRooted( true );
11066             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11067             if ( sdi_unrooted.getCount() != 1 ) {
11068                 return false;
11069             }
11070             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11071                 return false;
11072             }
11073             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11074                 return false;
11075             }
11076             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11077                 return false;
11078             }
11079             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11080                 return false;
11081             }
11082             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11083                 return false;
11084             }
11085             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11086                 return false;
11087             }
11088             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11089                 return false;
11090             }
11091             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11092                 return false;
11093             }
11094             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11095                 return false;
11096             }
11097             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11098                 return false;
11099             }
11100             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11101                 return false;
11102             }
11103             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11104                 return false;
11105             }
11106             p7 = null;
11107             final Phylogeny species8 = factory
11108                     .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,"
11109                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11110                             new NHXParser() )[ 0 ];
11111             final Phylogeny gene8 = factory
11112                     .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],"
11113                             + "(((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],"
11114                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11115                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11116                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11117                             new NHXParser() )[ 0 ];
11118             species8.setRooted( true );
11119             gene8.setRooted( true );
11120             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11121             if ( sdi_unrooted.getCount() != 1 ) {
11122                 return false;
11123             }
11124             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11125                 return false;
11126             }
11127             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11128                 return false;
11129             }
11130             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11131                 return false;
11132             }
11133             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11134                 return false;
11135             }
11136             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11137                 return false;
11138             }
11139             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11140                 return false;
11141             }
11142             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11143                 return false;
11144             }
11145             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11146                 return false;
11147             }
11148             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11149                 return false;
11150             }
11151             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11152                 return false;
11153             }
11154             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11155                 return false;
11156             }
11157             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11158                 return false;
11159             }
11160             p8 = null;
11161         }
11162         catch ( final Exception e ) {
11163             e.printStackTrace( System.out );
11164             return false;
11165         }
11166         return true;
11167     }
11168
11169     private static boolean testSequenceDbWsTools1() {
11170         try {
11171             final PhylogenyNode n = new PhylogenyNode();
11172             n.setName( "NP_001025424" );
11173             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11174             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11175                     || !acc.getValue().equals( "NP_001025424" ) ) {
11176                 return false;
11177             }
11178             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11179             acc = SequenceDbWsTools.obtainSeqAccession( n );
11180             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11181                     || !acc.getValue().equals( "NP_001025424" ) ) {
11182                 return false;
11183             }
11184             n.setName( "NP_001025424.1" );
11185             acc = SequenceDbWsTools.obtainSeqAccession( n );
11186             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11187                     || !acc.getValue().equals( "NP_001025424" ) ) {
11188                 return false;
11189             }
11190             n.setName( "NM_001030253" );
11191             acc = SequenceDbWsTools.obtainSeqAccession( n );
11192             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11193                     || !acc.getValue().equals( "NM_001030253" ) ) {
11194                 return false;
11195             }
11196             n.setName( "BCL2_HUMAN" );
11197             acc = SequenceDbWsTools.obtainSeqAccession( n );
11198             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11199                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11200                 System.out.println( acc.toString() );
11201                 return false;
11202             }
11203             n.setName( "P10415" );
11204             acc = SequenceDbWsTools.obtainSeqAccession( n );
11205             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11206                     || !acc.getValue().equals( "P10415" ) ) {
11207                 System.out.println( acc.toString() );
11208                 return false;
11209             }
11210             n.setName( " P10415 " );
11211             acc = SequenceDbWsTools.obtainSeqAccession( n );
11212             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11213                     || !acc.getValue().equals( "P10415" ) ) {
11214                 System.out.println( acc.toString() );
11215                 return false;
11216             }
11217             n.setName( "_P10415|" );
11218             acc = SequenceDbWsTools.obtainSeqAccession( n );
11219             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11220                     || !acc.getValue().equals( "P10415" ) ) {
11221                 System.out.println( acc.toString() );
11222                 return false;
11223             }
11224             n.setName( "AY695820" );
11225             acc = SequenceDbWsTools.obtainSeqAccession( n );
11226             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11227                     || !acc.getValue().equals( "AY695820" ) ) {
11228                 System.out.println( acc.toString() );
11229                 return false;
11230             }
11231             n.setName( "_AY695820_" );
11232             acc = SequenceDbWsTools.obtainSeqAccession( n );
11233             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11234                     || !acc.getValue().equals( "AY695820" ) ) {
11235                 System.out.println( acc.toString() );
11236                 return false;
11237             }
11238             n.setName( "AAA59452" );
11239             acc = SequenceDbWsTools.obtainSeqAccession( n );
11240             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11241                     || !acc.getValue().equals( "AAA59452" ) ) {
11242                 System.out.println( acc.toString() );
11243                 return false;
11244             }
11245             n.setName( "_AAA59452_" );
11246             acc = SequenceDbWsTools.obtainSeqAccession( n );
11247             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11248                     || !acc.getValue().equals( "AAA59452" ) ) {
11249                 System.out.println( acc.toString() );
11250                 return false;
11251             }
11252             n.setName( "AAA59452.1" );
11253             acc = SequenceDbWsTools.obtainSeqAccession( n );
11254             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11255                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11256                 System.out.println( acc.toString() );
11257                 return false;
11258             }
11259             n.setName( "_AAA59452.1_" );
11260             acc = SequenceDbWsTools.obtainSeqAccession( n );
11261             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11262                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11263                 System.out.println( acc.toString() );
11264                 return false;
11265             }
11266             n.setName( "GI:94894583" );
11267             acc = SequenceDbWsTools.obtainSeqAccession( n );
11268             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11269                     || !acc.getValue().equals( "94894583" ) ) {
11270                 System.out.println( acc.toString() );
11271                 return false;
11272             }
11273             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11274             acc = SequenceDbWsTools.obtainSeqAccession( n );
11275             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11276                     || !acc.getValue().equals( "71845847" ) ) {
11277                 System.out.println( acc.toString() );
11278                 return false;
11279             }
11280             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11281             acc = SequenceDbWsTools.obtainSeqAccession( n );
11282             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11283                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11284                 System.out.println( acc.toString() );
11285                 return false;
11286             }
11287         }
11288         catch ( final Exception e ) {
11289             return false;
11290         }
11291         return true;
11292     }
11293
11294     private static boolean testSequenceDbWsTools2() {
11295         try {
11296             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11297             SequenceDbWsTools.obtainSeqInformation( n1 );
11298             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11299                 return false;
11300             }
11301             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11302                 return false;
11303             }
11304             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11305                 return false;
11306             }
11307             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11308                 return false;
11309             }
11310             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11311             SequenceDbWsTools.obtainSeqInformation( n2 );
11312             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11313                 return false;
11314             }
11315             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11316                 return false;
11317             }
11318             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11319                 return false;
11320             }
11321             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11322                 return false;
11323             }
11324             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11325             SequenceDbWsTools.obtainSeqInformation( n3 );
11326             if ( !n3.getNodeData().getSequence().getName()
11327                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11328                 return false;
11329             }
11330             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11331                 return false;
11332             }
11333             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11334                 return false;
11335             }
11336             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11337                 return false;
11338             }
11339         }
11340         catch ( final IOException e ) {
11341             System.out.println();
11342             System.out.println( "the following might be due to absence internet connection:" );
11343             e.printStackTrace( System.out );
11344             return true;
11345         }
11346         catch ( final Exception e ) {
11347             e.printStackTrace();
11348             return false;
11349         }
11350         return true;
11351     }
11352
11353     private static boolean testSequenceIdParsing() {
11354         try {
11355             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11356             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11357                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11358                 if ( id != null ) {
11359                     System.out.println( "value   =" + id.getValue() );
11360                     System.out.println( "provider=" + id.getSource() );
11361                 }
11362                 return false;
11363             }
11364             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11365             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11366                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11367                 if ( id != null ) {
11368                     System.out.println( "value   =" + id.getValue() );
11369                     System.out.println( "provider=" + id.getSource() );
11370                 }
11371                 return false;
11372             }
11373             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11374             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11375                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11376                 if ( id != null ) {
11377                     System.out.println( "value   =" + id.getValue() );
11378                     System.out.println( "provider=" + id.getSource() );
11379                 }
11380                 return false;
11381             }
11382             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11383             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11384                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11385                 if ( id != null ) {
11386                     System.out.println( "value   =" + id.getValue() );
11387                     System.out.println( "provider=" + id.getSource() );
11388                 }
11389                 return false;
11390             }
11391             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11392             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11393                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11394                 if ( id != null ) {
11395                     System.out.println( "value   =" + id.getValue() );
11396                     System.out.println( "provider=" + id.getSource() );
11397                 }
11398                 return false;
11399             }
11400             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11401             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11402                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11403                 if ( id != null ) {
11404                     System.out.println( "value   =" + id.getValue() );
11405                     System.out.println( "provider=" + id.getSource() );
11406                 }
11407                 return false;
11408             }
11409             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11410             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11411                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11412                 if ( id != null ) {
11413                     System.out.println( "value   =" + id.getValue() );
11414                     System.out.println( "provider=" + id.getSource() );
11415                 }
11416                 return false;
11417             }
11418             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11419             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11420                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11421                 if ( id != null ) {
11422                     System.out.println( "value   =" + id.getValue() );
11423                     System.out.println( "provider=" + id.getSource() );
11424                 }
11425                 return false;
11426             }
11427             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11428             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11429                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11430                 if ( id != null ) {
11431                     System.out.println( "value   =" + id.getValue() );
11432                     System.out.println( "provider=" + id.getSource() );
11433                 }
11434                 return false;
11435             }
11436             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11437             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11438                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11439                 if ( id != null ) {
11440                     System.out.println( "value   =" + id.getValue() );
11441                     System.out.println( "provider=" + id.getSource() );
11442                 }
11443                 return false;
11444             }
11445             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11446             if ( id != null ) {
11447                 System.out.println( "value   =" + id.getValue() );
11448                 System.out.println( "provider=" + id.getSource() );
11449                 return false;
11450             }
11451             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11452             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11453                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11454                 if ( id != null ) {
11455                     System.out.println( "value   =" + id.getValue() );
11456                     System.out.println( "provider=" + id.getSource() );
11457                 }
11458                 return false;
11459             }
11460             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11461             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11462                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11463                 if ( id != null ) {
11464                     System.out.println( "value   =" + id.getValue() );
11465                     System.out.println( "provider=" + id.getSource() );
11466                 }
11467                 return false;
11468             }
11469             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11470             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11471                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11472                 if ( id != null ) {
11473                     System.out.println( "value   =" + id.getValue() );
11474                     System.out.println( "provider=" + id.getSource() );
11475                 }
11476                 return false;
11477             }
11478             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11479             if ( id != null ) {
11480                 System.out.println( "value   =" + id.getValue() );
11481                 System.out.println( "provider=" + id.getSource() );
11482                 return false;
11483             }
11484         }
11485         catch ( final Exception e ) {
11486             e.printStackTrace( System.out );
11487             return false;
11488         }
11489         return true;
11490     }
11491
11492     private static boolean testSequenceWriter() {
11493         try {
11494             final String n = ForesterUtil.LINE_SEPARATOR;
11495             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11496                 return false;
11497             }
11498             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11499                 return false;
11500             }
11501             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11502                 return false;
11503             }
11504             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11505                 return false;
11506             }
11507             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11508                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11509                 return false;
11510             }
11511             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11512                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11513                 return false;
11514             }
11515         }
11516         catch ( final Exception e ) {
11517             e.printStackTrace();
11518             return false;
11519         }
11520         return true;
11521     }
11522
11523     private static boolean testSpecies() {
11524         try {
11525             final Species s1 = new BasicSpecies( "a" );
11526             final Species s2 = new BasicSpecies( "a" );
11527             final Species s3 = new BasicSpecies( "A" );
11528             final Species s4 = new BasicSpecies( "b" );
11529             if ( !s1.equals( s1 ) ) {
11530                 return false;
11531             }
11532             if ( s1.getSpeciesId().equals( "x" ) ) {
11533                 return false;
11534             }
11535             if ( s1.getSpeciesId().equals( null ) ) {
11536                 return false;
11537             }
11538             if ( !s1.equals( s2 ) ) {
11539                 return false;
11540             }
11541             if ( s1.equals( s3 ) ) {
11542                 return false;
11543             }
11544             if ( s1.hashCode() != s1.hashCode() ) {
11545                 return false;
11546             }
11547             if ( s1.hashCode() != s2.hashCode() ) {
11548                 return false;
11549             }
11550             if ( s1.hashCode() == s3.hashCode() ) {
11551                 return false;
11552             }
11553             if ( s1.compareTo( s1 ) != 0 ) {
11554                 return false;
11555             }
11556             if ( s1.compareTo( s2 ) != 0 ) {
11557                 return false;
11558             }
11559             if ( s1.compareTo( s3 ) != 0 ) {
11560                 return false;
11561             }
11562             if ( s1.compareTo( s4 ) >= 0 ) {
11563                 return false;
11564             }
11565             if ( s4.compareTo( s1 ) <= 0 ) {
11566                 return false;
11567             }
11568             if ( !s4.getSpeciesId().equals( "b" ) ) {
11569                 return false;
11570             }
11571             final Species s5 = new BasicSpecies( " C " );
11572             if ( !s5.getSpeciesId().equals( "C" ) ) {
11573                 return false;
11574             }
11575             if ( s5.equals( s1 ) ) {
11576                 return false;
11577             }
11578         }
11579         catch ( final Exception e ) {
11580             e.printStackTrace( System.out );
11581             return false;
11582         }
11583         return true;
11584     }
11585
11586     private static boolean testSplit() {
11587         try {
11588             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11589             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11590             //Archaeopteryx.createApplication( p0 );
11591             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11592             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11593             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11594             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11595             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11596             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11597             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11598             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11599             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11600             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11601             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11602             // System.out.println( s0.toString() );
11603             //
11604             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11607             if ( s0.match( query_nodes ) ) {
11608                 return false;
11609             }
11610             query_nodes = new HashSet<PhylogenyNode>();
11611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11618             if ( !s0.match( query_nodes ) ) {
11619                 return false;
11620             }
11621             //
11622             query_nodes = new HashSet<PhylogenyNode>();
11623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11626             if ( !s0.match( query_nodes ) ) {
11627                 return false;
11628             }
11629             //
11630             query_nodes = new HashSet<PhylogenyNode>();
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11635             if ( !s0.match( query_nodes ) ) {
11636                 return false;
11637             }
11638             //
11639             query_nodes = new HashSet<PhylogenyNode>();
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11644             if ( !s0.match( query_nodes ) ) {
11645                 return false;
11646             }
11647             //
11648             query_nodes = new HashSet<PhylogenyNode>();
11649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11652             if ( !s0.match( query_nodes ) ) {
11653                 return false;
11654             }
11655             query_nodes = new HashSet<PhylogenyNode>();
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11658             if ( !s0.match( query_nodes ) ) {
11659                 return false;
11660             }
11661             query_nodes = new HashSet<PhylogenyNode>();
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11667             if ( !s0.match( query_nodes ) ) {
11668                 return false;
11669             }
11670             query_nodes = new HashSet<PhylogenyNode>();
11671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11674             if ( !s0.match( query_nodes ) ) {
11675                 return false;
11676             }
11677             query_nodes = new HashSet<PhylogenyNode>();
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11682             if ( !s0.match( query_nodes ) ) {
11683                 return false;
11684             }
11685             query_nodes = new HashSet<PhylogenyNode>();
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11688             if ( s0.match( query_nodes ) ) {
11689                 return false;
11690             }
11691             query_nodes = new HashSet<PhylogenyNode>();
11692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11696             if ( s0.match( query_nodes ) ) {
11697                 return false;
11698             }
11699             query_nodes = new HashSet<PhylogenyNode>();
11700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11705             if ( s0.match( query_nodes ) ) {
11706                 return false;
11707             }
11708             query_nodes = new HashSet<PhylogenyNode>();
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11712             if ( s0.match( query_nodes ) ) {
11713                 return false;
11714             }
11715             query_nodes = new HashSet<PhylogenyNode>();
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11718             if ( s0.match( query_nodes ) ) {
11719                 return false;
11720             }
11721             query_nodes = new HashSet<PhylogenyNode>();
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11724             if ( s0.match( query_nodes ) ) {
11725                 return false;
11726             }
11727             query_nodes = new HashSet<PhylogenyNode>();
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11730             if ( s0.match( query_nodes ) ) {
11731                 return false;
11732             }
11733             query_nodes = new HashSet<PhylogenyNode>();
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11736             if ( s0.match( query_nodes ) ) {
11737                 return false;
11738             }
11739             query_nodes = new HashSet<PhylogenyNode>();
11740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11742             if ( s0.match( query_nodes ) ) {
11743                 return false;
11744             }
11745             query_nodes = new HashSet<PhylogenyNode>();
11746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11748             if ( s0.match( query_nodes ) ) {
11749                 return false;
11750             }
11751             query_nodes = new HashSet<PhylogenyNode>();
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11755             if ( s0.match( query_nodes ) ) {
11756                 return false;
11757             }
11758             query_nodes = new HashSet<PhylogenyNode>();
11759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11762             if ( s0.match( query_nodes ) ) {
11763                 return false;
11764             }
11765             query_nodes = new HashSet<PhylogenyNode>();
11766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11769             if ( s0.match( query_nodes ) ) {
11770                 return false;
11771             }
11772             query_nodes = new HashSet<PhylogenyNode>();
11773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11777             if ( s0.match( query_nodes ) ) {
11778                 return false;
11779             }
11780             /////////
11781             //            query_nodes = new HashSet<PhylogenyNode>();
11782             //            query_nodes.add( new PhylogenyNode( "X" ) );
11783             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11784             //            query_nodes.add( new PhylogenyNode( "A" ) );
11785             //            query_nodes.add( new PhylogenyNode( "B" ) );
11786             //            query_nodes.add( new PhylogenyNode( "C" ) );
11787             //            query_nodes.add( new PhylogenyNode( "D" ) );
11788             //            query_nodes.add( new PhylogenyNode( "E" ) );
11789             //            query_nodes.add( new PhylogenyNode( "F" ) );
11790             //            query_nodes.add( new PhylogenyNode( "G" ) );
11791             //            if ( !s0.match( query_nodes ) ) {
11792             //                return false;
11793             //            }
11794             //            query_nodes = new HashSet<PhylogenyNode>();
11795             //            query_nodes.add( new PhylogenyNode( "X" ) );
11796             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11797             //            query_nodes.add( new PhylogenyNode( "A" ) );
11798             //            query_nodes.add( new PhylogenyNode( "B" ) );
11799             //            query_nodes.add( new PhylogenyNode( "C" ) );
11800             //            if ( !s0.match( query_nodes ) ) {
11801             //                return false;
11802             //            }
11803             //            //
11804             //            query_nodes = new HashSet<PhylogenyNode>();
11805             //            query_nodes.add( new PhylogenyNode( "X" ) );
11806             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11807             //            query_nodes.add( new PhylogenyNode( "D" ) );
11808             //            query_nodes.add( new PhylogenyNode( "E" ) );
11809             //            query_nodes.add( new PhylogenyNode( "F" ) );
11810             //            query_nodes.add( new PhylogenyNode( "G" ) );
11811             //            if ( !s0.match( query_nodes ) ) {
11812             //                return false;
11813             //            }
11814             //            //
11815             //            query_nodes = new HashSet<PhylogenyNode>();
11816             //            query_nodes.add( new PhylogenyNode( "X" ) );
11817             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11818             //            query_nodes.add( new PhylogenyNode( "A" ) );
11819             //            query_nodes.add( new PhylogenyNode( "B" ) );
11820             //            query_nodes.add( new PhylogenyNode( "C" ) );
11821             //            query_nodes.add( new PhylogenyNode( "D" ) );
11822             //            if ( !s0.match( query_nodes ) ) {
11823             //                return false;
11824             //            }
11825             //            //
11826             //            query_nodes = new HashSet<PhylogenyNode>();
11827             //            query_nodes.add( new PhylogenyNode( "X" ) );
11828             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11829             //            query_nodes.add( new PhylogenyNode( "E" ) );
11830             //            query_nodes.add( new PhylogenyNode( "F" ) );
11831             //            query_nodes.add( new PhylogenyNode( "G" ) );
11832             //            if ( !s0.match( query_nodes ) ) {
11833             //                return false;
11834             //            }
11835             //            //
11836             //            query_nodes = new HashSet<PhylogenyNode>();
11837             //            query_nodes.add( new PhylogenyNode( "X" ) );
11838             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11839             //            query_nodes.add( new PhylogenyNode( "F" ) );
11840             //            query_nodes.add( new PhylogenyNode( "G" ) );
11841             //            if ( !s0.match( query_nodes ) ) {
11842             //                return false;
11843             //            }
11844             //
11845             query_nodes = new HashSet<PhylogenyNode>();
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11850             if ( s0.match( query_nodes ) ) {
11851                 return false;
11852             }
11853             //
11854             query_nodes = new HashSet<PhylogenyNode>();
11855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11859             if ( s0.match( query_nodes ) ) {
11860                 return false;
11861             }
11862             ///////////////////////////
11863             //
11864             query_nodes = new HashSet<PhylogenyNode>();
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11869             if ( s0.match( query_nodes ) ) {
11870                 return false;
11871             }
11872             //
11873             query_nodes = new HashSet<PhylogenyNode>();
11874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11878             if ( s0.match( query_nodes ) ) {
11879                 return false;
11880             }
11881             //
11882             query_nodes = new HashSet<PhylogenyNode>();
11883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "E" ) );
11896             if ( s0.match( query_nodes ) ) {
11897                 return false;
11898             }
11899             //
11900             query_nodes = new HashSet<PhylogenyNode>();
11901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11905             if ( s0.match( query_nodes ) ) {
11906                 return false;
11907             }
11908             //
11909             query_nodes = new HashSet<PhylogenyNode>();
11910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11913             if ( s0.match( query_nodes ) ) {
11914                 return false;
11915             }
11916             //
11917             query_nodes = new HashSet<PhylogenyNode>();
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11923             if ( s0.match( query_nodes ) ) {
11924                 return false;
11925             }
11926             //
11927             query_nodes = new HashSet<PhylogenyNode>();
11928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11933             if ( s0.match( query_nodes ) ) {
11934                 return false;
11935             }
11936             //
11937             query_nodes = new HashSet<PhylogenyNode>();
11938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11943             if ( s0.match( query_nodes ) ) {
11944                 return false;
11945             }
11946             //
11947             query_nodes = new HashSet<PhylogenyNode>();
11948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11954             if ( s0.match( query_nodes ) ) {
11955                 return false;
11956             }
11957         }
11958         catch ( final Exception e ) {
11959             e.printStackTrace();
11960             return false;
11961         }
11962         return true;
11963     }
11964
11965     private static boolean testSplitStrict() {
11966         try {
11967             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11968             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11969             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11970             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11971             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11972             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11973             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11974             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11975             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11976             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11977             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11978             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11981             if ( s0.match( query_nodes ) ) {
11982                 return false;
11983             }
11984             query_nodes = new HashSet<PhylogenyNode>();
11985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11992             if ( !s0.match( query_nodes ) ) {
11993                 return false;
11994             }
11995             //
11996             query_nodes = new HashSet<PhylogenyNode>();
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12000             if ( !s0.match( query_nodes ) ) {
12001                 return false;
12002             }
12003             //
12004             query_nodes = new HashSet<PhylogenyNode>();
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12009             if ( !s0.match( query_nodes ) ) {
12010                 return false;
12011             }
12012             //
12013             query_nodes = new HashSet<PhylogenyNode>();
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12018             if ( !s0.match( query_nodes ) ) {
12019                 return false;
12020             }
12021             //
12022             query_nodes = new HashSet<PhylogenyNode>();
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12026             if ( !s0.match( query_nodes ) ) {
12027                 return false;
12028             }
12029             //
12030             query_nodes = new HashSet<PhylogenyNode>();
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12033             if ( !s0.match( query_nodes ) ) {
12034                 return false;
12035             }
12036             //
12037             query_nodes = new HashSet<PhylogenyNode>();
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12043             if ( !s0.match( query_nodes ) ) {
12044                 return false;
12045             }
12046             //
12047             query_nodes = new HashSet<PhylogenyNode>();
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12051             if ( !s0.match( query_nodes ) ) {
12052                 return false;
12053             }
12054             //
12055             query_nodes = new HashSet<PhylogenyNode>();
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12060             if ( !s0.match( query_nodes ) ) {
12061                 return false;
12062             }
12063             //
12064             query_nodes = new HashSet<PhylogenyNode>();
12065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12067             if ( s0.match( query_nodes ) ) {
12068                 return false;
12069             }
12070             //
12071             query_nodes = new HashSet<PhylogenyNode>();
12072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12076             if ( s0.match( query_nodes ) ) {
12077                 return false;
12078             }
12079             //
12080             query_nodes = new HashSet<PhylogenyNode>();
12081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12086             if ( s0.match( query_nodes ) ) {
12087                 return false;
12088             }
12089             //
12090             query_nodes = new HashSet<PhylogenyNode>();
12091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12093             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12094             if ( s0.match( query_nodes ) ) {
12095                 return false;
12096             }
12097             //
12098             query_nodes = new HashSet<PhylogenyNode>();
12099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12101             if ( s0.match( query_nodes ) ) {
12102                 return false;
12103             }
12104             //
12105             query_nodes = new HashSet<PhylogenyNode>();
12106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12108             if ( s0.match( query_nodes ) ) {
12109                 return false;
12110             }
12111             //
12112             query_nodes = new HashSet<PhylogenyNode>();
12113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12115             if ( s0.match( query_nodes ) ) {
12116                 return false;
12117             }
12118             //
12119             query_nodes = new HashSet<PhylogenyNode>();
12120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12122             if ( s0.match( query_nodes ) ) {
12123                 return false;
12124             }
12125             //
12126             query_nodes = new HashSet<PhylogenyNode>();
12127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12129             if ( s0.match( query_nodes ) ) {
12130                 return false;
12131             }
12132             //
12133             query_nodes = new HashSet<PhylogenyNode>();
12134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12136             if ( s0.match( query_nodes ) ) {
12137                 return false;
12138             }
12139             //
12140             query_nodes = new HashSet<PhylogenyNode>();
12141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12144             if ( s0.match( query_nodes ) ) {
12145                 return false;
12146             }
12147             //
12148             query_nodes = new HashSet<PhylogenyNode>();
12149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12152             if ( s0.match( query_nodes ) ) {
12153                 return false;
12154             }
12155             //
12156             query_nodes = new HashSet<PhylogenyNode>();
12157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12160             if ( s0.match( query_nodes ) ) {
12161                 return false;
12162             }
12163             //
12164             query_nodes = new HashSet<PhylogenyNode>();
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12169             if ( s0.match( query_nodes ) ) {
12170                 return false;
12171             }
12172         }
12173         catch ( final Exception e ) {
12174             e.printStackTrace();
12175             return false;
12176         }
12177         return true;
12178     }
12179
12180     private static boolean testSubtreeDeletion() {
12181         try {
12182             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12183             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12184             t1.deleteSubtree( t1.getNode( "A" ), false );
12185             if ( t1.getNumberOfExternalNodes() != 5 ) {
12186                 return false;
12187             }
12188             t1.toNewHampshireX();
12189             t1.deleteSubtree( t1.getNode( "E" ), false );
12190             if ( t1.getNumberOfExternalNodes() != 4 ) {
12191                 return false;
12192             }
12193             t1.toNewHampshireX();
12194             t1.deleteSubtree( t1.getNode( "F" ), false );
12195             if ( t1.getNumberOfExternalNodes() != 3 ) {
12196                 return false;
12197             }
12198             t1.toNewHampshireX();
12199             t1.deleteSubtree( t1.getNode( "D" ), false );
12200             t1.toNewHampshireX();
12201             if ( t1.getNumberOfExternalNodes() != 3 ) {
12202                 return false;
12203             }
12204             t1.deleteSubtree( t1.getNode( "def" ), false );
12205             t1.toNewHampshireX();
12206             if ( t1.getNumberOfExternalNodes() != 2 ) {
12207                 return false;
12208             }
12209             t1.deleteSubtree( t1.getNode( "B" ), false );
12210             t1.toNewHampshireX();
12211             if ( t1.getNumberOfExternalNodes() != 1 ) {
12212                 return false;
12213             }
12214             t1.deleteSubtree( t1.getNode( "C" ), false );
12215             t1.toNewHampshireX();
12216             if ( t1.getNumberOfExternalNodes() != 1 ) {
12217                 return false;
12218             }
12219             t1.deleteSubtree( t1.getNode( "abc" ), false );
12220             t1.toNewHampshireX();
12221             if ( t1.getNumberOfExternalNodes() != 1 ) {
12222                 return false;
12223             }
12224             t1.deleteSubtree( t1.getNode( "r" ), false );
12225             if ( t1.getNumberOfExternalNodes() != 0 ) {
12226                 return false;
12227             }
12228             if ( !t1.isEmpty() ) {
12229                 return false;
12230             }
12231             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12232             t2.deleteSubtree( t2.getNode( "A" ), false );
12233             t2.toNewHampshireX();
12234             if ( t2.getNumberOfExternalNodes() != 5 ) {
12235                 return false;
12236             }
12237             t2.deleteSubtree( t2.getNode( "abc" ), false );
12238             t2.toNewHampshireX();
12239             if ( t2.getNumberOfExternalNodes() != 3 ) {
12240                 return false;
12241             }
12242             t2.deleteSubtree( t2.getNode( "def" ), false );
12243             t2.toNewHampshireX();
12244             if ( t2.getNumberOfExternalNodes() != 1 ) {
12245                 return false;
12246             }
12247         }
12248         catch ( final Exception e ) {
12249             e.printStackTrace( System.out );
12250             return false;
12251         }
12252         return true;
12253     }
12254
12255     private static boolean testSupportCount() {
12256         try {
12257             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12258             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12259             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12260                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12261                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12262                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12263                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12264                     new NHXParser() );
12265             SupportCount.count( t0_1, phylogenies_1, true, false );
12266             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12267             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12268                     + "(((((A,B),C),D),E),((F,G),X))"
12269                     + "(((((A,Y),B),C),D),((F,G),E))"
12270                     + "(((((A,B),C),D),E),(F,G))"
12271                     + "(((((A,B),C),D),E),(F,G))"
12272                     + "(((((A,B),C),D),E),(F,G))"
12273                     + "(((((A,B),C),D),E),(F,G),Z)"
12274                     + "(((((A,B),C),D),E),(F,G))"
12275                     + "((((((A,B),C),D),E),F),G)"
12276                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12277                     new NHXParser() );
12278             SupportCount.count( t0_2, phylogenies_2, true, false );
12279             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12280             while ( it.hasNext() ) {
12281                 final PhylogenyNode n = it.next();
12282                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12283                     return false;
12284                 }
12285             }
12286             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12287             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12288                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12289             SupportCount.count( t0_3, phylogenies_3, true, false );
12290             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12291             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12292                 return false;
12293             }
12294             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12295                 return false;
12296             }
12297             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12298                 return false;
12299             }
12300             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12301                 return false;
12302             }
12303             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12304                 return false;
12305             }
12306             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12307                 return false;
12308             }
12309             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12310                 return false;
12311             }
12312             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12313                 return false;
12314             }
12315             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12316                 return false;
12317             }
12318             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12319                 return false;
12320             }
12321             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12322             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12323                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12324             SupportCount.count( t0_4, phylogenies_4, true, false );
12325             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12326             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12327                 return false;
12328             }
12329             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12330                 return false;
12331             }
12332             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12333                 return false;
12334             }
12335             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12336                 return false;
12337             }
12338             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12339                 return false;
12340             }
12341             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12342                 return false;
12343             }
12344             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12345                 return false;
12346             }
12347             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12348                 return false;
12349             }
12350             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12351                 return false;
12352             }
12353             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12354                 return false;
12355             }
12356             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12357             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12358             double d = SupportCount.compare( b1, a, true, true, true );
12359             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12360                 return false;
12361             }
12362             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12363             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12364             d = SupportCount.compare( b2, a, true, true, true );
12365             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12366                 return false;
12367             }
12368             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12369             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12370             d = SupportCount.compare( b3, a, true, true, true );
12371             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12372                 return false;
12373             }
12374             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12375             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12376             d = SupportCount.compare( b4, a, true, true, false );
12377             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12378                 return false;
12379             }
12380         }
12381         catch ( final Exception e ) {
12382             e.printStackTrace( System.out );
12383             return false;
12384         }
12385         return true;
12386     }
12387
12388     private static boolean testSupportTransfer() {
12389         try {
12390             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12391             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)",
12392                                                  new NHXParser() )[ 0 ];
12393             final Phylogeny p2 = factory
12394                     .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 ];
12395             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12396                 return false;
12397             }
12398             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12399                 return false;
12400             }
12401             support_transfer.moveBranchLengthsToBootstrap( p1 );
12402             support_transfer.transferSupportValues( p1, p2 );
12403             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12404                 return false;
12405             }
12406             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12407                 return false;
12408             }
12409             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12410                 return false;
12411             }
12412             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12413                 return false;
12414             }
12415             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12416                 return false;
12417             }
12418             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12419                 return false;
12420             }
12421             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12422                 return false;
12423             }
12424             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12425                 return false;
12426             }
12427         }
12428         catch ( final Exception e ) {
12429             e.printStackTrace( System.out );
12430             return false;
12431         }
12432         return true;
12433     }
12434
12435     private static boolean testTaxonomyExtraction() {
12436         try {
12437             final PhylogenyNode n0 = PhylogenyNode
12438                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12439             if ( n0.getNodeData().isHasTaxonomy() ) {
12440                 return false;
12441             }
12442             final PhylogenyNode n1 = PhylogenyNode
12443                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12444             if ( n1.getNodeData().isHasTaxonomy() ) {
12445                 System.out.println( n1.toString() );
12446                 return false;
12447             }
12448             final PhylogenyNode n2x = PhylogenyNode
12449                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12450             if ( n2x.getNodeData().isHasTaxonomy() ) {
12451                 return false;
12452             }
12453             final PhylogenyNode n3 = PhylogenyNode
12454                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12455             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12456                 System.out.println( n3.toString() );
12457                 return false;
12458             }
12459             final PhylogenyNode n4 = PhylogenyNode
12460                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12461             if ( n4.getNodeData().isHasTaxonomy() ) {
12462                 System.out.println( n4.toString() );
12463                 return false;
12464             }
12465             final PhylogenyNode n5 = PhylogenyNode
12466                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12467             if ( n5.getNodeData().isHasTaxonomy() ) {
12468                 System.out.println( n5.toString() );
12469                 return false;
12470             }
12471             final PhylogenyNode n6 = PhylogenyNode
12472                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12473             if ( n6.getNodeData().isHasTaxonomy() ) {
12474                 System.out.println( n6.toString() );
12475                 return false;
12476             }
12477             final PhylogenyNode n7 = PhylogenyNode
12478                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12479             if ( n7.getNodeData().isHasTaxonomy() ) {
12480                 System.out.println( n7.toString() );
12481                 return false;
12482             }
12483             final PhylogenyNode n8 = PhylogenyNode
12484                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12485             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12486                 System.out.println( n8.toString() );
12487                 return false;
12488             }
12489             final PhylogenyNode n9 = PhylogenyNode
12490                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12491             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12492                 System.out.println( n9.toString() );
12493                 return false;
12494             }
12495             final PhylogenyNode n10x = PhylogenyNode
12496                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12497             if ( n10x.getNodeData().isHasTaxonomy() ) {
12498                 System.out.println( n10x.toString() );
12499                 return false;
12500             }
12501             final PhylogenyNode n10xx = PhylogenyNode
12502                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12503             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12504                 System.out.println( n10xx.toString() );
12505                 return false;
12506             }
12507             final PhylogenyNode n10 = PhylogenyNode
12508                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12509             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12510                 System.out.println( n10.toString() );
12511                 return false;
12512             }
12513             final PhylogenyNode n11 = PhylogenyNode
12514                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12515             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12516                 System.out.println( n11.toString() );
12517                 return false;
12518             }
12519             final PhylogenyNode n12 = PhylogenyNode
12520                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12521                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12522             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12523                 System.out.println( n12.toString() );
12524                 return false;
12525             }
12526             final PhylogenyNode n13 = PhylogenyNode
12527                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12528             if ( n13.getNodeData().isHasTaxonomy() ) {
12529                 System.out.println( n13.toString() );
12530                 return false;
12531             }
12532             final PhylogenyNode n14 = PhylogenyNode
12533                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12534             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12535                 System.out.println( n14.toString() );
12536                 return false;
12537             }
12538             final PhylogenyNode n15 = PhylogenyNode
12539                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12540             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12541                 System.out.println( n15.toString() );
12542                 return false;
12543             }
12544             final PhylogenyNode n16 = PhylogenyNode
12545                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12546             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12547                 System.out.println( n16.toString() );
12548                 return false;
12549             }
12550             final PhylogenyNode n17 = PhylogenyNode
12551                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12552             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12553                 System.out.println( n17.toString() );
12554                 return false;
12555             }
12556             final PhylogenyNode n18 = PhylogenyNode
12557                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12558             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12559                 System.out.println( n18.toString() );
12560                 return false;
12561             }
12562             final PhylogenyNode n19 = PhylogenyNode
12563                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12564                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12565             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12566                 System.out.println( n19.toString() );
12567                 return false;
12568             }
12569             final PhylogenyNode n20 = PhylogenyNode
12570                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12571             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12572                 System.out.println( n20.toString() );
12573                 return false;
12574             }
12575             final PhylogenyNode n21 = PhylogenyNode
12576                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12577                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12578             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12579                 System.out.println( n21.toString() );
12580                 return false;
12581             }
12582             final PhylogenyNode n23 = PhylogenyNode
12583                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12584                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12585             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12586                 System.out.println( n23.toString() );
12587                 return false;
12588             }
12589             final PhylogenyNode n24 = PhylogenyNode
12590                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12591             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12592                 System.out.println( n24.toString() );
12593                 return false;
12594             }
12595             //
12596             final PhylogenyNode n25 = PhylogenyNode
12597                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12598                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12599             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12600                 System.out.println( n25.toString() );
12601                 return false;
12602             }
12603             final PhylogenyNode n26 = PhylogenyNode
12604                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12605                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12606             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12607                 System.out.println( n26.toString() );
12608                 return false;
12609             }
12610             final PhylogenyNode n27 = PhylogenyNode
12611                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12612             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12613                 System.out.println( n27.toString() );
12614                 return false;
12615             }
12616         }
12617         catch ( final Exception e ) {
12618             e.printStackTrace( System.out );
12619             return false;
12620         }
12621         return true;
12622     }
12623
12624     private static boolean testTreeCopy() {
12625         try {
12626             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12627             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12628             final Phylogeny t1 = t0.copy();
12629             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12630                 return false;
12631             }
12632             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12633                 return false;
12634             }
12635             t0.deleteSubtree( t0.getNode( "c" ), true );
12636             t0.deleteSubtree( t0.getNode( "a" ), true );
12637             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12638             t0.getNode( "b" ).setName( "Bee" );
12639             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12640                 return false;
12641             }
12642             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12643                 return false;
12644             }
12645             t0.deleteSubtree( t0.getNode( "e" ), true );
12646             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12647             t0.deleteSubtree( t0.getNode( "d" ), true );
12648             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12649                 return false;
12650             }
12651         }
12652         catch ( final Exception e ) {
12653             e.printStackTrace();
12654             return false;
12655         }
12656         return true;
12657     }
12658
12659     private static boolean testTreeMethods() {
12660         try {
12661             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12662             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12663             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12664             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12665                 System.out.println( t0.toNewHampshireX() );
12666                 return false;
12667             }
12668             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12669             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12670             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12671                 return false;
12672             }
12673             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12674                 return false;
12675             }
12676             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12677                 return false;
12678             }
12679         }
12680         catch ( final Exception e ) {
12681             e.printStackTrace( System.out );
12682             return false;
12683         }
12684         return true;
12685     }
12686
12687     private static boolean testUniprotEntryRetrieval() {
12688         try {
12689             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12690             if ( !entry.getAccession().equals( "P12345" ) ) {
12691                 return false;
12692             }
12693             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12694                 return false;
12695             }
12696             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12697                 return false;
12698             }
12699             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12700                 return false;
12701             }
12702             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12703                 return false;
12704             }
12705             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12706                 return false;
12707             }
12708             if ( entry.getMolecularSequence() == null ) {
12709                 return false;
12710             }
12711             if ( !entry
12712                     .getMolecularSequence()
12713                     .getMolecularSequenceAsString()
12714                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12715                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12716                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12717                 System.out.println( "expected something else." );
12718                 return false;
12719             }
12720         }
12721         catch ( final IOException e ) {
12722             System.out.println();
12723             System.out.println( "the following might be due to absence internet connection:" );
12724             e.printStackTrace( System.out );
12725             return true;
12726         }
12727         catch ( final NullPointerException f ) {
12728             f.printStackTrace( System.out );
12729             return false;
12730         }
12731         catch ( final Exception e ) {
12732             return false;
12733         }
12734         return true;
12735     }
12736
12737     private static boolean testUniprotTaxonomySearch() {
12738         try {
12739             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12740                                                                                                  10 );
12741             if ( results.size() != 1 ) {
12742                 return false;
12743             }
12744             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12745                 return false;
12746             }
12747             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12748                 return false;
12749             }
12750             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12751                 return false;
12752             }
12753             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12754                 return false;
12755             }
12756             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12757                 return false;
12758             }
12759             results = null;
12760             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12761             if ( results.size() != 1 ) {
12762                 return false;
12763             }
12764             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12765                 return false;
12766             }
12767             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12771                 return false;
12772             }
12773             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12774                 return false;
12775             }
12776             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12777                 return false;
12778             }
12779             results = null;
12780             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12781             if ( results.size() != 1 ) {
12782                 return false;
12783             }
12784             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12785                 return false;
12786             }
12787             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12788                 return false;
12789             }
12790             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12791                 return false;
12792             }
12793             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12794                 return false;
12795             }
12796             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12797                 return false;
12798             }
12799             results = null;
12800             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12801             if ( results.size() != 1 ) {
12802                 return false;
12803             }
12804             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12805                 return false;
12806             }
12807             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12808                 return false;
12809             }
12810             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12811                 return false;
12812             }
12813             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12814                 return false;
12815             }
12816             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12817                 return false;
12818             }
12819             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12820                 return false;
12821             }
12822             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12823                 return false;
12824             }
12825             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12826                     .equals( "Nematostella vectensis" ) ) {
12827                 System.out.println( results.get( 0 ).getLineage() );
12828                 return false;
12829             }
12830             //
12831             results = null;
12832             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12833             if ( results.size() != 1 ) {
12834                 return false;
12835             }
12836             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12837                 return false;
12838             }
12839             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12840                 return false;
12841             }
12842             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12843                 return false;
12844             }
12845             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12846                 return false;
12847             }
12848             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12849                 return false;
12850             }
12851             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12852                     .equals( "Xenopus tropicalis" ) ) {
12853                 System.out.println( results.get( 0 ).getLineage() );
12854                 return false;
12855             }
12856             //
12857             results = null;
12858             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12859             if ( results.size() != 1 ) {
12860                 return false;
12861             }
12862             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12863                 return false;
12864             }
12865             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12866                 return false;
12867             }
12868             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12869                 return false;
12870             }
12871             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12872                 return false;
12873             }
12874             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12875                 return false;
12876             }
12877             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12878                     .equals( "Xenopus tropicalis" ) ) {
12879                 System.out.println( results.get( 0 ).getLineage() );
12880                 return false;
12881             }
12882             //
12883             results = null;
12884             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12885             if ( results.size() != 1 ) {
12886                 return false;
12887             }
12888             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12889                 return false;
12890             }
12891             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12892                 return false;
12893             }
12894             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12895                 return false;
12896             }
12897             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12898                 return false;
12899             }
12900             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12901                 return false;
12902             }
12903             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12904                     .equals( "Xenopus tropicalis" ) ) {
12905                 System.out.println( results.get( 0 ).getLineage() );
12906                 return false;
12907             }
12908         }
12909         catch ( final IOException e ) {
12910             System.out.println();
12911             System.out.println( "the following might be due to absence internet connection:" );
12912             e.printStackTrace( System.out );
12913             return true;
12914         }
12915         catch ( final Exception e ) {
12916             return false;
12917         }
12918         return true;
12919     }
12920
12921     private static boolean testWabiTxSearch() {
12922         try {
12923             String result = "";
12924             result = TxSearch.searchSimple( "nematostella" );
12925             result = TxSearch.getTxId( "nematostella" );
12926             if ( !result.equals( "45350" ) ) {
12927                 return false;
12928             }
12929             result = TxSearch.getTxName( "45350" );
12930             if ( !result.equals( "Nematostella" ) ) {
12931                 return false;
12932             }
12933             result = TxSearch.getTxId( "nematostella vectensis" );
12934             if ( !result.equals( "45351" ) ) {
12935                 return false;
12936             }
12937             result = TxSearch.getTxName( "45351" );
12938             if ( !result.equals( "Nematostella vectensis" ) ) {
12939                 return false;
12940             }
12941             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12942             if ( !result.equals( "536089" ) ) {
12943                 return false;
12944             }
12945             result = TxSearch.getTxName( "536089" );
12946             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12947                 return false;
12948             }
12949             final List<String> queries = new ArrayList<String>();
12950             queries.add( "Campylobacter coli" );
12951             queries.add( "Escherichia coli" );
12952             queries.add( "Arabidopsis" );
12953             queries.add( "Trichoplax" );
12954             queries.add( "Samanea saman" );
12955             queries.add( "Kluyveromyces marxianus" );
12956             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12957             queries.add( "Bornavirus parrot/PDD/2008" );
12958             final List<RANKS> ranks = new ArrayList<RANKS>();
12959             ranks.add( RANKS.SUPERKINGDOM );
12960             ranks.add( RANKS.KINGDOM );
12961             ranks.add( RANKS.FAMILY );
12962             ranks.add( RANKS.GENUS );
12963             ranks.add( RANKS.TRIBE );
12964             result = TxSearch.searchLineage( queries, ranks );
12965             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12966             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12967         }
12968         catch ( final Exception e ) {
12969             System.out.println();
12970             System.out.println( "the following might be due to absence internet connection:" );
12971             e.printStackTrace( System.out );
12972             return false;
12973         }
12974         return true;
12975     }
12976 }