in progress
[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.net.URL;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39 import java.util.SortedSet;
40
41 import org.forester.application.support_transfer;
42 import org.forester.archaeopteryx.TreePanelUtil;
43 import org.forester.archaeopteryx.webservices.WebserviceUtil;
44 import org.forester.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.DeleteableMsa;
65 import org.forester.msa.Mafft;
66 import org.forester.msa.Msa;
67 import org.forester.msa.MsaInferrer;
68 import org.forester.msa.MsaMethods;
69 import org.forester.pccx.TestPccx;
70 import org.forester.phylogeny.Phylogeny;
71 import org.forester.phylogeny.PhylogenyBranch;
72 import org.forester.phylogeny.PhylogenyMethods;
73 import org.forester.phylogeny.PhylogenyNode;
74 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
75 import org.forester.phylogeny.data.Accession;
76 import org.forester.phylogeny.data.Accession.Source;
77 import org.forester.phylogeny.data.BinaryCharacters;
78 import org.forester.phylogeny.data.BranchWidth;
79 import org.forester.phylogeny.data.Confidence;
80 import org.forester.phylogeny.data.Distribution;
81 import org.forester.phylogeny.data.DomainArchitecture;
82 import org.forester.phylogeny.data.Event;
83 import org.forester.phylogeny.data.Identifier;
84 import org.forester.phylogeny.data.PhylogenyData;
85 import org.forester.phylogeny.data.PhylogenyDataUtil;
86 import org.forester.phylogeny.data.Polygon;
87 import org.forester.phylogeny.data.PropertiesMap;
88 import org.forester.phylogeny.data.Property;
89 import org.forester.phylogeny.data.Property.AppliesTo;
90 import org.forester.phylogeny.data.ProteinDomain;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.protein.BasicDomain;
96 import org.forester.protein.BasicProtein;
97 import org.forester.protein.Domain;
98 import org.forester.protein.Protein;
99 import org.forester.protein.ProteinId;
100 import org.forester.rio.TestRIO;
101 import org.forester.sdi.SDI;
102 import org.forester.sdi.SDIR;
103 import org.forester.sdi.TestGSDI;
104 import org.forester.sequence.BasicSequence;
105 import org.forester.sequence.Sequence;
106 import org.forester.species.BasicSpecies;
107 import org.forester.species.Species;
108 import org.forester.surfacing.TestSurfacing;
109 import org.forester.tools.ConfidenceAssessor;
110 import org.forester.tools.SupportCount;
111 import org.forester.tools.TreeSplitMatrix;
112 import org.forester.util.AsciiHistogram;
113 import org.forester.util.BasicDescriptiveStatistics;
114 import org.forester.util.BasicTable;
115 import org.forester.util.BasicTableParser;
116 import org.forester.util.DescriptiveStatistics;
117 import org.forester.util.ForesterConstants;
118 import org.forester.util.ForesterUtil;
119 import org.forester.util.GeneralTable;
120 import org.forester.util.SequenceAccessionTools;
121 import org.forester.ws.seqdb.SequenceDatabaseEntry;
122 import org.forester.ws.seqdb.SequenceDbWsTools;
123 import org.forester.ws.seqdb.UniProtTaxonomy;
124 import org.forester.ws.wabi.TxSearch;
125 import org.forester.ws.wabi.TxSearch.RANKS;
126 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
127 import org.forester.ws.wabi.TxSearch.TAX_RANK;
128
129 @SuppressWarnings( "unused")
130 public final class Test {
131
132     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "resources"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "test_data"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean PERFORM_DB_TESTS          = false;
139     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
140     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
141                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_XSD;
143     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
147     private final static double  ZERO_DIFF                 = 1.0E-9;
148
149     public static boolean isEqual( final double a, final double b ) {
150         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
151     }
152
153     public static void main( final String[] args ) {
154         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
155         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
156                 + "]" );
157         Locale.setDefault( Locale.US );
158         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
159         int failed = 0;
160         int succeeded = 0;
161         System.out.print( "[Test if directory with files for testing exists/is readable: " );
162         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
163             System.out.println( "OK.]" );
164         }
165         else {
166             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
167             System.out.println( "Testing aborted." );
168             System.exit( -1 );
169         }
170         System.out.print( "[Test if resources directory exists/is readable: " );
171         if ( testDir( PATH_TO_RESOURCES ) ) {
172             System.out.println( "OK.]" );
173         }
174         else {
175             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
176             System.out.println( "Testing aborted." );
177             System.exit( -1 );
178         }
179         final long start_time = new Date().getTime();
180         System.out.print( "Basic node methods: " );
181         if ( Test.testBasicNodeMethods() ) {
182             System.out.println( "OK." );
183             succeeded++;
184         }
185         else {
186             System.out.println( "failed." );
187             failed++;
188         }
189         System.out.print( "Protein id: " );
190         if ( !testProteinId() ) {
191             System.out.println( "failed." );
192             failed++;
193         }
194         else {
195             succeeded++;
196         }
197         System.out.println( "OK." );
198         System.out.print( "Species: " );
199         if ( !testSpecies() ) {
200             System.out.println( "failed." );
201             failed++;
202         }
203         else {
204             succeeded++;
205         }
206         System.out.println( "OK." );
207         System.out.print( "Basic domain: " );
208         if ( !testBasicDomain() ) {
209             System.out.println( "failed." );
210             failed++;
211         }
212         else {
213             succeeded++;
214         }
215         System.out.println( "OK." );
216         System.out.print( "Basic protein: " );
217         if ( !testBasicProtein() ) {
218             System.out.println( "failed." );
219             failed++;
220         }
221         else {
222             succeeded++;
223         }
224         System.out.println( "OK." );
225         System.out.print( "Sequence writer: " );
226         if ( testSequenceWriter() ) {
227             System.out.println( "OK." );
228             succeeded++;
229         }
230         else {
231             System.out.println( "failed." );
232             failed++;
233         }
234         System.out.print( "Sequence id parsing: " );
235         if ( testSequenceIdParsing() ) {
236             System.out.println( "OK." );
237             succeeded++;
238         }
239         else {
240             System.out.println( "failed." );
241             failed++;
242         }
243         System.out.print( "UniProtKB id extraction: " );
244         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
245             System.out.println( "OK." );
246             succeeded++;
247         }
248         else {
249             System.out.println( "failed." );
250             failed++;
251         }
252         System.out.print( "Sequence DB tools 1: " );
253         if ( testSequenceDbWsTools1() ) {
254             System.out.println( "OK." );
255             succeeded++;
256         }
257         else {
258             System.out.println( "failed." );
259             failed++;
260         }
261         System.out.print( "Hmmscan output parser: " );
262         if ( testHmmscanOutputParser() ) {
263             System.out.println( "OK." );
264             succeeded++;
265         }
266         else {
267             System.out.println( "failed." );
268             failed++;
269         }
270         System.out.print( "Overlap removal: " );
271         if ( !org.forester.test.Test.testOverlapRemoval() ) {
272             System.out.println( "failed." );
273             failed++;
274         }
275         else {
276             succeeded++;
277         }
278         System.out.println( "OK." );
279         System.out.print( "Engulfing overlap removal: " );
280         if ( !Test.testEngulfingOverlapRemoval() ) {
281             System.out.println( "failed." );
282             failed++;
283         }
284         else {
285             succeeded++;
286         }
287         System.out.println( "OK." );
288         System.out.print( "Taxonomy code extraction: " );
289         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
290             System.out.println( "OK." );
291             succeeded++;
292         }
293         else {
294             System.out.println( "failed." );
295             failed++;
296         }
297         System.out.print( "SN extraction: " );
298         if ( Test.testExtractSNFromNodeName() ) {
299             System.out.println( "OK." );
300             succeeded++;
301         }
302         else {
303             System.out.println( "failed." );
304             failed++;
305         }
306         System.out.print( "Taxonomy extraction (general): " );
307         if ( Test.testTaxonomyExtraction() ) {
308             System.out.println( "OK." );
309             succeeded++;
310         }
311         else {
312             System.out.println( "failed." );
313             failed++;
314         }
315         System.out.print( "Uri for Aptx web sequence accession: " );
316         if ( Test.testCreateUriForSeqWeb() ) {
317             System.out.println( "OK." );
318             succeeded++;
319         }
320         else {
321             System.out.println( "failed." );
322             failed++;
323         }
324         System.out.print( "Basic node construction and parsing of NHX (node level): " );
325         if ( Test.testNHXNodeParsing() ) {
326             System.out.println( "OK." );
327             succeeded++;
328         }
329         else {
330             System.out.println( "failed." );
331             failed++;
332         }
333         System.out.print( "NHX parsing iterating: " );
334         if ( Test.testNHParsingIter() ) {
335             System.out.println( "OK." );
336             succeeded++;
337         }
338         else {
339             System.out.println( "failed." );
340             failed++;
341         }
342         System.out.print( "NH parsing: " );
343         if ( Test.testNHParsing() ) {
344             System.out.println( "OK." );
345             succeeded++;
346         }
347         else {
348             System.out.println( "failed." );
349             failed++;
350         }
351         System.out.print( "Conversion to NHX (node level): " );
352         if ( Test.testNHXconversion() ) {
353             System.out.println( "OK." );
354             succeeded++;
355         }
356         else {
357             System.out.println( "failed." );
358             failed++;
359         }
360         System.out.print( "NHX parsing: " );
361         if ( Test.testNHXParsing() ) {
362             System.out.println( "OK." );
363             succeeded++;
364         }
365         else {
366             System.out.println( "failed." );
367             failed++;
368         }
369         System.out.print( "NHX parsing with quotes: " );
370         if ( Test.testNHXParsingQuotes() ) {
371             System.out.println( "OK." );
372             succeeded++;
373         }
374         else {
375             System.out.println( "failed." );
376             failed++;
377         }
378         System.out.print( "NHX parsing (MrBayes): " );
379         if ( Test.testNHXParsingMB() ) {
380             System.out.println( "OK." );
381             succeeded++;
382         }
383         else {
384             System.out.println( "failed." );
385             failed++;
386         }
387         System.out.print( "Nexus characters parsing: " );
388         if ( Test.testNexusCharactersParsing() ) {
389             System.out.println( "OK." );
390             succeeded++;
391         }
392         else {
393             System.out.println( "failed." );
394             failed++;
395         }
396         System.out.print( "Nexus tree parsing iterating: " );
397         if ( Test.testNexusTreeParsingIterating() ) {
398             System.out.println( "OK." );
399             succeeded++;
400         }
401         else {
402             System.out.println( "failed." );
403             failed++;
404         }
405         System.out.print( "Nexus tree parsing: " );
406         if ( Test.testNexusTreeParsing() ) {
407             System.out.println( "OK." );
408             succeeded++;
409         }
410         else {
411             System.out.println( "failed." );
412             failed++;
413         }
414         System.out.print( "Nexus tree parsing (translating): " );
415         if ( Test.testNexusTreeParsingTranslating() ) {
416             System.out.println( "OK." );
417             succeeded++;
418         }
419         else {
420             System.out.println( "failed." );
421             failed++;
422         }
423         System.out.print( "Nexus matrix parsing: " );
424         if ( Test.testNexusMatrixParsing() ) {
425             System.out.println( "OK." );
426             succeeded++;
427         }
428         else {
429             System.out.println( "failed." );
430             failed++;
431         }
432         System.out.print( "Basic phyloXML parsing: " );
433         if ( Test.testBasicPhyloXMLparsing() ) {
434             System.out.println( "OK." );
435             succeeded++;
436         }
437         else {
438             System.out.println( "failed." );
439             failed++;
440         }
441         System.out.print( "Basic phyloXML parsing (validating against schema): " );
442         if ( testBasicPhyloXMLparsingValidating() ) {
443             System.out.println( "OK." );
444             succeeded++;
445         }
446         else {
447             System.out.println( "failed." );
448             failed++;
449         }
450         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
451         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
452             System.out.println( "OK." );
453             succeeded++;
454         }
455         else {
456             System.out.println( "failed." );
457             failed++;
458         }
459         System.out.print( "phyloXML Distribution Element: " );
460         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
461             System.out.println( "OK." );
462             succeeded++;
463         }
464         else {
465             System.out.println( "failed." );
466             failed++;
467         }
468         System.out.print( "Tol XML parsing: " );
469         if ( Test.testBasicTolXMLparsing() ) {
470             System.out.println( "OK." );
471             succeeded++;
472         }
473         else {
474             System.out.println( "failed." );
475             failed++;
476         }
477         System.out.print( "Copying of node data: " );
478         if ( Test.testCopyOfNodeData() ) {
479             System.out.println( "OK." );
480             succeeded++;
481         }
482         else {
483             System.out.println( "failed." );
484             failed++;
485         }
486         System.out.print( "Tree copy: " );
487         if ( Test.testTreeCopy() ) {
488             System.out.println( "OK." );
489             succeeded++;
490         }
491         else {
492             System.out.println( "failed." );
493             failed++;
494         }
495         System.out.print( "Basic tree methods: " );
496         if ( Test.testBasicTreeMethods() ) {
497             System.out.println( "OK." );
498             succeeded++;
499         }
500         else {
501             System.out.println( "failed." );
502             failed++;
503         }
504         System.out.print( "Tree methods: " );
505         if ( Test.testTreeMethods() ) {
506             System.out.println( "OK." );
507             succeeded++;
508         }
509         else {
510             System.out.println( "failed." );
511             failed++;
512         }
513         System.out.print( "Postorder Iterator: " );
514         if ( Test.testPostOrderIterator() ) {
515             System.out.println( "OK." );
516             succeeded++;
517         }
518         else {
519             System.out.println( "failed." );
520             failed++;
521         }
522         System.out.print( "Preorder Iterator: " );
523         if ( Test.testPreOrderIterator() ) {
524             System.out.println( "OK." );
525             succeeded++;
526         }
527         else {
528             System.out.println( "failed." );
529             failed++;
530         }
531         System.out.print( "Levelorder Iterator: " );
532         if ( Test.testLevelOrderIterator() ) {
533             System.out.println( "OK." );
534             succeeded++;
535         }
536         else {
537             System.out.println( "failed." );
538             failed++;
539         }
540         System.out.print( "Re-id methods: " );
541         if ( Test.testReIdMethods() ) {
542             System.out.println( "OK." );
543             succeeded++;
544         }
545         else {
546             System.out.println( "failed." );
547             failed++;
548         }
549         System.out.print( "Methods on last external nodes: " );
550         if ( Test.testLastExternalNodeMethods() ) {
551             System.out.println( "OK." );
552             succeeded++;
553         }
554         else {
555             System.out.println( "failed." );
556             failed++;
557         }
558         System.out.print( "Methods on external nodes: " );
559         if ( Test.testExternalNodeRelatedMethods() ) {
560             System.out.println( "OK." );
561             succeeded++;
562         }
563         else {
564             System.out.println( "failed." );
565             failed++;
566         }
567         System.out.print( "Deletion of external nodes: " );
568         if ( Test.testDeletionOfExternalNodes() ) {
569             System.out.println( "OK." );
570             succeeded++;
571         }
572         else {
573             System.out.println( "failed." );
574             failed++;
575         }
576         System.out.print( "Subtree deletion: " );
577         if ( Test.testSubtreeDeletion() ) {
578             System.out.println( "OK." );
579             succeeded++;
580         }
581         else {
582             System.out.println( "failed." );
583             failed++;
584         }
585         System.out.print( "Phylogeny branch: " );
586         if ( Test.testPhylogenyBranch() ) {
587             System.out.println( "OK." );
588             succeeded++;
589         }
590         else {
591             System.out.println( "failed." );
592             failed++;
593         }
594         System.out.print( "Rerooting: " );
595         if ( Test.testRerooting() ) {
596             System.out.println( "OK." );
597             succeeded++;
598         }
599         else {
600             System.out.println( "failed." );
601             failed++;
602         }
603         System.out.print( "Mipoint rooting: " );
604         if ( Test.testMidpointrooting() ) {
605             System.out.println( "OK." );
606             succeeded++;
607         }
608         else {
609             System.out.println( "failed." );
610             failed++;
611         }
612         System.out.print( "Node removal: " );
613         if ( Test.testNodeRemoval() ) {
614             System.out.println( "OK." );
615             succeeded++;
616         }
617         else {
618             System.out.println( "failed." );
619             failed++;
620         }
621         System.out.print( "Support count: " );
622         if ( Test.testSupportCount() ) {
623             System.out.println( "OK." );
624             succeeded++;
625         }
626         else {
627             System.out.println( "failed." );
628             failed++;
629         }
630         System.out.print( "Support transfer: " );
631         if ( Test.testSupportTransfer() ) {
632             System.out.println( "OK." );
633             succeeded++;
634         }
635         else {
636             System.out.println( "failed." );
637             failed++;
638         }
639         System.out.print( "Finding of LCA: " );
640         if ( Test.testGetLCA() ) {
641             System.out.println( "OK." );
642             succeeded++;
643         }
644         else {
645             System.out.println( "failed." );
646             failed++;
647         }
648         System.out.print( "Finding of LCA 2: " );
649         if ( Test.testGetLCA2() ) {
650             System.out.println( "OK." );
651             succeeded++;
652         }
653         else {
654             System.out.println( "failed." );
655             failed++;
656         }
657         System.out.print( "Calculation of distance between nodes: " );
658         if ( Test.testGetDistance() ) {
659             System.out.println( "OK." );
660             succeeded++;
661         }
662         else {
663             System.out.println( "failed." );
664             failed++;
665         }
666         System.out.print( "Descriptive statistics: " );
667         if ( Test.testDescriptiveStatistics() ) {
668             System.out.println( "OK." );
669             succeeded++;
670         }
671         else {
672             System.out.println( "failed." );
673             failed++;
674         }
675         System.out.print( "Data objects and methods: " );
676         if ( Test.testDataObjects() ) {
677             System.out.println( "OK." );
678             succeeded++;
679         }
680         else {
681             System.out.println( "failed." );
682             failed++;
683         }
684         System.out.print( "Properties map: " );
685         if ( Test.testPropertiesMap() ) {
686             System.out.println( "OK." );
687             succeeded++;
688         }
689         else {
690             System.out.println( "failed." );
691             failed++;
692         }
693         System.out.print( "SDIse: " );
694         if ( Test.testSDIse() ) {
695             System.out.println( "OK." );
696             succeeded++;
697         }
698         else {
699             System.out.println( "failed." );
700             failed++;
701         }
702         System.out.print( "SDIunrooted: " );
703         if ( Test.testSDIunrooted() ) {
704             System.out.println( "OK." );
705             succeeded++;
706         }
707         else {
708             System.out.println( "failed." );
709             failed++;
710         }
711         System.out.print( "GSDI: " );
712         if ( TestGSDI.test() ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "RIO: " );
721         if ( TestRIO.test() ) {
722             System.out.println( "OK." );
723             succeeded++;
724         }
725         else {
726             System.out.println( "failed." );
727             failed++;
728         }
729         System.out.print( "Phylogeny reconstruction:" );
730         System.out.println();
731         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
732             System.out.println( "OK." );
733             succeeded++;
734         }
735         else {
736             System.out.println( "failed." );
737             failed++;
738         }
739         System.out.print( "Analysis of domain architectures: " );
740         System.out.println();
741         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
742             System.out.println( "OK." );
743             succeeded++;
744         }
745         else {
746             System.out.println( "failed." );
747             failed++;
748         }
749         System.out.print( "GO: " );
750         System.out.println();
751         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
752             System.out.println( "OK." );
753             succeeded++;
754         }
755         else {
756             System.out.println( "failed." );
757             failed++;
758         }
759         System.out.print( "Modeling tools: " );
760         if ( TestPccx.test() ) {
761             System.out.println( "OK." );
762             succeeded++;
763         }
764         else {
765             System.out.println( "failed." );
766             failed++;
767         }
768         System.out.print( "Split Matrix strict: " );
769         if ( Test.testSplitStrict() ) {
770             System.out.println( "OK." );
771             succeeded++;
772         }
773         else {
774             System.out.println( "failed." );
775             failed++;
776         }
777         System.out.print( "Split Matrix: " );
778         if ( Test.testSplit() ) {
779             System.out.println( "OK." );
780             succeeded++;
781         }
782         else {
783             System.out.println( "failed." );
784             failed++;
785         }
786         System.out.print( "Confidence Assessor: " );
787         if ( Test.testConfidenceAssessor() ) {
788             System.out.println( "OK." );
789             succeeded++;
790         }
791         else {
792             System.out.println( "failed." );
793             failed++;
794         }
795         System.out.print( "Basic table: " );
796         if ( Test.testBasicTable() ) {
797             System.out.println( "OK." );
798             succeeded++;
799         }
800         else {
801             System.out.println( "failed." );
802             failed++;
803         }
804         System.out.print( "General table: " );
805         if ( Test.testGeneralTable() ) {
806             System.out.println( "OK." );
807             succeeded++;
808         }
809         else {
810             System.out.println( "failed." );
811             failed++;
812         }
813         System.out.print( "Amino acid sequence: " );
814         if ( Test.testAminoAcidSequence() ) {
815             System.out.println( "OK." );
816             succeeded++;
817         }
818         else {
819             System.out.println( "failed." );
820             failed++;
821         }
822         System.out.print( "General MSA parser: " );
823         if ( Test.testGeneralMsaParser() ) {
824             System.out.println( "OK." );
825             succeeded++;
826         }
827         else {
828             System.out.println( "failed." );
829             failed++;
830         }
831         System.out.print( "Fasta parser for msa: " );
832         if ( Test.testFastaParser() ) {
833             System.out.println( "OK." );
834             succeeded++;
835         }
836         else {
837             System.out.println( "failed." );
838             failed++;
839         }
840         System.out.print( "Creation of balanced phylogeny: " );
841         if ( Test.testCreateBalancedPhylogeny() ) {
842             System.out.println( "OK." );
843             succeeded++;
844         }
845         else {
846             System.out.println( "failed." );
847             failed++;
848         }
849         System.out.print( "Genbank accessor parsing: " );
850         if ( Test.testGenbankAccessorParsing() ) {
851             System.out.println( "OK." );
852             succeeded++;
853         }
854         else {
855             System.out.println( "failed." );
856             failed++;
857         }
858         String path = "";
859         final String os = ForesterUtil.OS_NAME.toLowerCase();
860         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
861             path = "/usr/local/bin/mafft";
862         }
863         else if ( os.indexOf( "win" ) >= 0 ) {
864             path = "C:\\Program Files\\mafft-win\\mafft.bat";
865         }
866         else {
867             path = "mafft";
868             if ( !MsaInferrer.isInstalled( path ) ) {
869                 path = "/usr/bin/mafft";
870             }
871             if ( !MsaInferrer.isInstalled( path ) ) {
872                 path = "/usr/local/bin/mafft";
873             }
874         }
875         if ( MsaInferrer.isInstalled( path ) ) {
876             System.out.print( "MAFFT (external program): " );
877             if ( Test.testMafft( path ) ) {
878                 System.out.println( "OK." );
879                 succeeded++;
880             }
881             else {
882                 System.out.println( "failed [will not count towards failed tests]" );
883             }
884         }
885         System.out.print( "Next nodes with collapsed: " );
886         if ( Test.testNextNodeWithCollapsing() ) {
887             System.out.println( "OK." );
888             succeeded++;
889         }
890         else {
891             System.out.println( "failed." );
892             failed++;
893         }
894         System.out.print( "Simple MSA quality: " );
895         if ( Test.testMsaQualityMethod() ) {
896             System.out.println( "OK." );
897             succeeded++;
898         }
899         else {
900             System.out.println( "failed." );
901             failed++;
902         }
903         System.out.print( "Deleteable MSA: " );
904         if ( Test.testDeleteableMsa() ) {
905             System.out.println( "OK." );
906             succeeded++;
907         }
908         else {
909             System.out.println( "failed." );
910             failed++;
911         }
912         System.exit(  0 );
913         if ( PERFORM_DB_TESTS ) {
914             System.out.print( "Uniprot Entry Retrieval: " );
915             if ( Test.testUniprotEntryRetrieval() ) {
916                 System.out.println( "OK." );
917                 succeeded++;
918             }
919             else {
920                 System.out.println( "failed." );
921                 failed++;
922             }
923             System.out.print( "Ebi Entry Retrieval: " );
924             if ( Test.testEbiEntryRetrieval() ) {
925                 System.out.println( "OK." );
926                 succeeded++;
927             }
928             else {
929                 System.out.println( "failed." );
930                 failed++;
931             }
932             System.out.print( "Sequence DB tools 2: " );
933             if ( testSequenceDbWsTools2() ) {
934                 System.out.println( "OK." );
935                 succeeded++;
936             }
937             else {
938                 System.out.println( "failed." );
939                 failed++;
940                 System.exit( -1 );
941             }
942             System.out.print( "Uniprot Taxonomy Search: " );
943             if ( Test.testUniprotTaxonomySearch() ) {
944                 System.out.println( "OK." );
945                 succeeded++;
946             }
947             else {
948                 System.out.println( "failed." );
949                 failed++;
950             }
951         }
952         if ( PERFORM_WEB_TREE_ACCESS ) {
953             System.out.print( "NHX parsing from URL: " );
954             if ( Test.testNHXparsingFromURL() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961             }
962             System.out.print( "phyloXML parsing from URL: " );
963             if ( Test.testPhyloXMLparsingFromURL() ) {
964                 System.out.println( "OK." );
965                 succeeded++;
966             }
967             else {
968                 System.out.println( "failed." );
969                 failed++;
970             }
971             System.out.print( "TreeBase acccess: " );
972             if ( Test.testTreeBaseReading() ) {
973                 System.out.println( "OK." );
974                 succeeded++;
975             }
976             else {
977                 System.out.println( "failed." );
978                 failed++;
979             }
980             //
981             System.out.print( "ToL access: " );
982             if ( Test.testToLReading() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990             //
991             System.out.print( "TreeFam access: " );
992             if ( Test.testTreeFamReading() ) {
993                 System.out.println( "OK." );
994                 succeeded++;
995             }
996             else {
997                 System.out.println( "failed." );
998                 failed++;
999             }
1000             //
1001             //
1002             System.out.print( "Pfam tree access: " );
1003             if ( Test.testPfamTreeReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011         }
1012         System.out.println();
1013         final Runtime rt = java.lang.Runtime.getRuntime();
1014         final long free_memory = rt.freeMemory() / 1000000;
1015         final long total_memory = rt.totalMemory() / 1000000;
1016         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1017                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1018         System.out.println();
1019         System.out.println( "Successful tests: " + succeeded );
1020         System.out.println( "Failed     tests: " + failed );
1021         System.out.println();
1022         if ( failed < 1 ) {
1023             System.out.println( "OK." );
1024         }
1025         else {
1026             System.out.println( "Not OK." );
1027         }
1028     }
1029
1030     public static boolean testEngulfingOverlapRemoval() {
1031         try {
1032             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1033             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1034             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1035             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1036             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1037             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1038             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1039             final List<Boolean> covered = new ArrayList<Boolean>();
1040             covered.add( true ); // 0
1041             covered.add( false ); // 1
1042             covered.add( true ); // 2
1043             covered.add( false ); // 3
1044             covered.add( true ); // 4
1045             covered.add( true ); // 5
1046             covered.add( false ); // 6
1047             covered.add( true ); // 7
1048             covered.add( true ); // 8
1049             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1050                 return false;
1051             }
1052             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1053                 return false;
1054             }
1055             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1056                 return false;
1057             }
1058             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1059                 return false;
1060             }
1061             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1062                 return false;
1063             }
1064             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1065                 return false;
1066             }
1067             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1068                 return false;
1069             }
1070             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1071             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1072             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1073             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1074             abc.addProteinDomain( a );
1075             abc.addProteinDomain( b );
1076             abc.addProteinDomain( c );
1077             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1078             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1079             if ( abc.getNumberOfProteinDomains() != 3 ) {
1080                 return false;
1081             }
1082             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1083                 return false;
1084             }
1085             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1086                 return false;
1087             }
1088             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1089                 return false;
1090             }
1091             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1092                 return false;
1093             }
1094             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1095             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1096             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1097             final Protein def = new BasicProtein( "def", "nemve", 0 );
1098             def.addProteinDomain( d );
1099             def.addProteinDomain( e );
1100             def.addProteinDomain( f );
1101             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1102             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1103             if ( def.getNumberOfProteinDomains() != 3 ) {
1104                 return false;
1105             }
1106             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1107                 return false;
1108             }
1109             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1113                 return false;
1114             }
1115             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1116                 return false;
1117             }
1118             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1119                 return false;
1120             }
1121         }
1122         catch ( final Exception e ) {
1123             e.printStackTrace( System.out );
1124             return false;
1125         }
1126         return true;
1127     }
1128
1129     public static final boolean testNHXparsingFromURL() {
1130         try {
1131             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1132             final URL u = new URL( s );
1133             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1134             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1135             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1136                 return false;
1137             }
1138             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1139                 System.out.println( phys[ 0 ].toNewHampshire() );
1140                 return false;
1141             }
1142             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1143                 System.out.println( phys[ 1 ].toNewHampshire() );
1144                 return false;
1145             }
1146             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1147             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1148                 return false;
1149             }
1150             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1151                 System.out.println( phys2[ 0 ].toNewHampshire() );
1152                 return false;
1153             }
1154             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1155             final NHXParser p = new NHXParser();
1156             final URL u2 = new URL( s );
1157             p.setSource( u2 );
1158             if ( !p.hasNext() ) {
1159                 return false;
1160             }
1161             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1162                 return false;
1163             }
1164             if ( !p.hasNext() ) {
1165                 return false;
1166             }
1167             p.reset();
1168             if ( !p.hasNext() ) {
1169                 return false;
1170             }
1171             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1172                 return false;
1173             }
1174             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1175                 return false;
1176             }
1177             p.reset();
1178             if ( !p.hasNext() ) {
1179                 return false;
1180             }
1181             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1182                 return false;
1183             }
1184             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1185                 return false;
1186             }
1187         }
1188         catch ( final Exception e ) {
1189             e.printStackTrace();
1190         }
1191         return true;
1192     }
1193
1194     public static boolean testOverlapRemoval() {
1195         try {
1196             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1197             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1198             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1199             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1200             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1201             final List<Boolean> covered = new ArrayList<Boolean>();
1202             covered.add( true ); // 0
1203             covered.add( false ); // 1
1204             covered.add( true ); // 2
1205             covered.add( false ); // 3
1206             covered.add( true ); // 4
1207             covered.add( true ); // 5
1208             covered.add( false ); // 6
1209             covered.add( true ); // 7
1210             covered.add( true ); // 8
1211             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1212                 return false;
1213             }
1214             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1215                 return false;
1216             }
1217             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1218                 return false;
1219             }
1220             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1221                 return false;
1222             }
1223             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1224                 return false;
1225             }
1226             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1227             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1228             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1229             ab.addProteinDomain( a );
1230             ab.addProteinDomain( b );
1231             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1232             if ( ab.getNumberOfProteinDomains() != 2 ) {
1233                 return false;
1234             }
1235             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1236                 return false;
1237             }
1238             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1239                 return false;
1240             }
1241             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1242             if ( ab.getNumberOfProteinDomains() != 2 ) {
1243                 return false;
1244             }
1245             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1246                 return false;
1247             }
1248             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1249             final Domain d = new BasicDomain( "d",
1250                                               ( short ) 10000,
1251                                               ( short ) 10500,
1252                                               ( short ) 1,
1253                                               ( short ) 1,
1254                                               0.0000001,
1255                                               1 );
1256             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1257             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1258             cde.addProteinDomain( c );
1259             cde.addProteinDomain( d );
1260             cde.addProteinDomain( e );
1261             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1262             if ( cde.getNumberOfProteinDomains() != 3 ) {
1263                 return false;
1264             }
1265             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1266                 return false;
1267             }
1268             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1269             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1270             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1271             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1272             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1273             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1274             fghi.addProteinDomain( f );
1275             fghi.addProteinDomain( g );
1276             fghi.addProteinDomain( h );
1277             fghi.addProteinDomain( i );
1278             fghi.addProteinDomain( i );
1279             fghi.addProteinDomain( i );
1280             fghi.addProteinDomain( i2 );
1281             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1282             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1283                 return false;
1284             }
1285             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1286                 return false;
1287             }
1288             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1289                 return false;
1290             }
1291             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1292             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1293                 return false;
1294             }
1295             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1296                 return false;
1297             }
1298             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1299             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1300             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1301             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1302             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1303             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1304             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1305             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1306             jklm.addProteinDomain( j );
1307             jklm.addProteinDomain( k );
1308             jklm.addProteinDomain( l );
1309             jklm.addProteinDomain( m );
1310             jklm.addProteinDomain( m0 );
1311             jklm.addProteinDomain( m1 );
1312             jklm.addProteinDomain( m2 );
1313             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1314             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1315                 return false;
1316             }
1317             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1318                 return false;
1319             }
1320             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1321                 return false;
1322             }
1323             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1324             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1325                 return false;
1326             }
1327             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1328                 return false;
1329             }
1330             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1331             final Protein od = new BasicProtein( "od", "varanus", 0 );
1332             od.addProteinDomain( only );
1333             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1334             if ( od.getNumberOfProteinDomains() != 1 ) {
1335                 return false;
1336             }
1337             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1338                 return false;
1339             }
1340         }
1341         catch ( final Exception e ) {
1342             e.printStackTrace( System.out );
1343             return false;
1344         }
1345         return true;
1346     }
1347
1348     public static final boolean testPfamTreeReading() {
1349         try {
1350             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1351             final NHXParser parser = new NHXParser();
1352             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1353             parser.setReplaceUnderscores( false );
1354             parser.setGuessRootedness( true );
1355             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1356             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1357             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1358                 return false;
1359             }
1360             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1361                 return false;
1362             }
1363         }
1364         catch ( final Exception e ) {
1365             e.printStackTrace();
1366         }
1367         return true;
1368     }
1369
1370     public static final boolean testPhyloXMLparsingFromURL() {
1371         try {
1372             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1373             final URL u = new URL( s );
1374             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1375             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1376             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1377                 return false;
1378             }
1379         }
1380         catch ( final Exception e ) {
1381             e.printStackTrace();
1382         }
1383         return true;
1384     }
1385
1386     public static final boolean testToLReading() {
1387         try {
1388             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1389             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1390             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1391             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1392                 return false;
1393             }
1394             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1395                 return false;
1396             }
1397             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1398                 return false;
1399             }
1400             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1401                 return false;
1402             }
1403         }
1404         catch ( final Exception e ) {
1405             e.printStackTrace();
1406         }
1407         return true;
1408     }
1409
1410     public static final boolean testTreeBaseReading() {
1411         try {
1412             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1413             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1414             parser.setReplaceUnderscores( true );
1415             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1416             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1417             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1418                 return false;
1419             }
1420             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1421             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1422             parser2.setReplaceUnderscores( true );
1423             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1424             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1425             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1426                 return false;
1427             }
1428         }
1429         catch ( final Exception e ) {
1430             e.printStackTrace();
1431         }
1432         return true;
1433     }
1434
1435     public static final boolean testTreeFamReading() {
1436         try {
1437             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1438             final NHXParser parser = new NHXParser();
1439             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1440             parser.setReplaceUnderscores( false );
1441             parser.setGuessRootedness( true );
1442             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1443             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1444             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1445                 return false;
1446             }
1447             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1448                 return false;
1449             }
1450         }
1451         catch ( final Exception e ) {
1452             e.printStackTrace();
1453         }
1454         return true;
1455     }
1456
1457     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1458         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1459         return p;
1460     }
1461
1462     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1463         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1464     }
1465
1466     private static boolean testAminoAcidSequence() {
1467         try {
1468             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1469             if ( aa1.getLength() != 13 ) {
1470                 return false;
1471             }
1472             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1473                 return false;
1474             }
1475             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1476                 return false;
1477             }
1478             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1479                 return false;
1480             }
1481             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1482             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1483                 return false;
1484             }
1485             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1486             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1487                 return false;
1488             }
1489             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1490             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1491                 return false;
1492             }
1493         }
1494         catch ( final Exception e ) {
1495             e.printStackTrace();
1496             return false;
1497         }
1498         return true;
1499     }
1500
1501     private static boolean testBasicDomain() {
1502         try {
1503             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1504             if ( !pd.getDomainId().equals( "id" ) ) {
1505                 return false;
1506             }
1507             if ( pd.getNumber() != 1 ) {
1508                 return false;
1509             }
1510             if ( pd.getTotalCount() != 4 ) {
1511                 return false;
1512             }
1513             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1514                 return false;
1515             }
1516             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1517             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1518             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1519             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1520             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1521             if ( !a1.equals( a1 ) ) {
1522                 return false;
1523             }
1524             if ( !a1.equals( a1_copy ) ) {
1525                 return false;
1526             }
1527             if ( !a1.equals( a1_equal ) ) {
1528                 return false;
1529             }
1530             if ( !a1.equals( a2 ) ) {
1531                 return false;
1532             }
1533             if ( a1.equals( a3 ) ) {
1534                 return false;
1535             }
1536             if ( a1.compareTo( a1 ) != 0 ) {
1537                 return false;
1538             }
1539             if ( a1.compareTo( a1_copy ) != 0 ) {
1540                 return false;
1541             }
1542             if ( a1.compareTo( a1_equal ) != 0 ) {
1543                 return false;
1544             }
1545             if ( a1.compareTo( a2 ) != 0 ) {
1546                 return false;
1547             }
1548             if ( a1.compareTo( a3 ) == 0 ) {
1549                 return false;
1550             }
1551         }
1552         catch ( final Exception e ) {
1553             e.printStackTrace( System.out );
1554             return false;
1555         }
1556         return true;
1557     }
1558
1559     private static boolean testBasicNodeMethods() {
1560         try {
1561             if ( PhylogenyNode.getNodeCount() != 0 ) {
1562                 return false;
1563             }
1564             final PhylogenyNode n1 = new PhylogenyNode();
1565             final PhylogenyNode n2 = PhylogenyNode
1566                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1567             final PhylogenyNode n3 = PhylogenyNode
1568                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1569             final PhylogenyNode n4 = PhylogenyNode
1570                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1571             if ( n1.isHasAssignedEvent() ) {
1572                 return false;
1573             }
1574             if ( PhylogenyNode.getNodeCount() != 4 ) {
1575                 return false;
1576             }
1577             if ( n3.getIndicator() != 0 ) {
1578                 return false;
1579             }
1580             if ( n3.getNumberOfExternalNodes() != 1 ) {
1581                 return false;
1582             }
1583             if ( !n3.isExternal() ) {
1584                 return false;
1585             }
1586             if ( !n3.isRoot() ) {
1587                 return false;
1588             }
1589             if ( !n4.getName().equals( "n4" ) ) {
1590                 return false;
1591             }
1592         }
1593         catch ( final Exception e ) {
1594             e.printStackTrace( System.out );
1595             return false;
1596         }
1597         return true;
1598     }
1599
1600     private static boolean testBasicPhyloXMLparsing() {
1601         try {
1602             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1603             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1604             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1605                                                               xml_parser );
1606             if ( xml_parser.getErrorCount() > 0 ) {
1607                 System.out.println( xml_parser.getErrorMessages().toString() );
1608                 return false;
1609             }
1610             if ( phylogenies_0.length != 4 ) {
1611                 return false;
1612             }
1613             final Phylogeny t1 = phylogenies_0[ 0 ];
1614             final Phylogeny t2 = phylogenies_0[ 1 ];
1615             final Phylogeny t3 = phylogenies_0[ 2 ];
1616             final Phylogeny t4 = phylogenies_0[ 3 ];
1617             if ( t1.getNumberOfExternalNodes() != 1 ) {
1618                 return false;
1619             }
1620             if ( !t1.isRooted() ) {
1621                 return false;
1622             }
1623             if ( t1.isRerootable() ) {
1624                 return false;
1625             }
1626             if ( !t1.getType().equals( "gene_tree" ) ) {
1627                 return false;
1628             }
1629             if ( t2.getNumberOfExternalNodes() != 2 ) {
1630                 return false;
1631             }
1632             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1633                 return false;
1634             }
1635             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1636                 return false;
1637             }
1638             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1639                 return false;
1640             }
1641             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1642                 return false;
1643             }
1644             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1645                 return false;
1646             }
1647             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1648                 return false;
1649             }
1650             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1651                     .startsWith( "actgtgggggt" ) ) {
1652                 return false;
1653             }
1654             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1655                     .startsWith( "ctgtgatgcat" ) ) {
1656                 return false;
1657             }
1658             if ( t3.getNumberOfExternalNodes() != 4 ) {
1659                 return false;
1660             }
1661             if ( !t1.getName().equals( "t1" ) ) {
1662                 return false;
1663             }
1664             if ( !t2.getName().equals( "t2" ) ) {
1665                 return false;
1666             }
1667             if ( !t3.getName().equals( "t3" ) ) {
1668                 return false;
1669             }
1670             if ( !t4.getName().equals( "t4" ) ) {
1671                 return false;
1672             }
1673             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1674                 return false;
1675             }
1676             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1677                 return false;
1678             }
1679             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1680                 return false;
1681             }
1682             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1683                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1684                 return false;
1685             }
1686             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1687                 return false;
1688             }
1689             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1690                 return false;
1691             }
1692             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1693                 return false;
1694             }
1695             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1696                     .equals( "apoptosis" ) ) {
1697                 return false;
1698             }
1699             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1700                     .equals( "GO:0006915" ) ) {
1701                 return false;
1702             }
1703             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1704                     .equals( "UniProtKB" ) ) {
1705                 return false;
1706             }
1707             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1708                     .equals( "experimental" ) ) {
1709                 return false;
1710             }
1711             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1712                     .equals( "function" ) ) {
1713                 return false;
1714             }
1715             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1716                     .getValue() != 1 ) {
1717                 return false;
1718             }
1719             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1720                     .getType().equals( "ml" ) ) {
1721                 return false;
1722             }
1723             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1724                     .equals( "apoptosis" ) ) {
1725                 return false;
1726             }
1727             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1728                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1729                 return false;
1730             }
1731             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1732                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1733                 return false;
1734             }
1735             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1736                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1737                 return false;
1738             }
1739             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1740                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1741                 return false;
1742             }
1743             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1744                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1745                 return false;
1746             }
1747             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1748                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1749                 return false;
1750             }
1751             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1752                     .equals( "GO:0005829" ) ) {
1753                 return false;
1754             }
1755             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1756                     .equals( "intracellular organelle" ) ) {
1757                 return false;
1758             }
1759             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1760                 return false;
1761             }
1762             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1763                     .equals( "UniProt link" ) ) ) {
1764                 return false;
1765             }
1766             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1767                 return false;
1768             }
1769             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1770             if ( x.size() != 4 ) {
1771                 return false;
1772             }
1773             int c = 0;
1774             for( final Accession acc : x ) {
1775                 if ( c == 0 ) {
1776                     if ( !acc.getSource().equals( "KEGG" ) ) {
1777                         return false;
1778                     }
1779                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1780                         return false;
1781                     }
1782                 }
1783                 c++;
1784             }
1785         }
1786         catch ( final Exception e ) {
1787             e.printStackTrace( System.out );
1788             return false;
1789         }
1790         return true;
1791     }
1792
1793     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1794         try {
1795             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1796             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1797             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1798                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1799             }
1800             else {
1801                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1802             }
1803             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1804                                                               xml_parser );
1805             if ( xml_parser.getErrorCount() > 0 ) {
1806                 System.out.println( xml_parser.getErrorMessages().toString() );
1807                 return false;
1808             }
1809             if ( phylogenies_0.length != 4 ) {
1810                 return false;
1811             }
1812             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1813             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1814             if ( phylogenies_t1.length != 1 ) {
1815                 return false;
1816             }
1817             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1818             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1819                 return false;
1820             }
1821             if ( !t1_rt.isRooted() ) {
1822                 return false;
1823             }
1824             if ( t1_rt.isRerootable() ) {
1825                 return false;
1826             }
1827             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1828                 return false;
1829             }
1830             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1831             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1832             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1833             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1834                 return false;
1835             }
1836             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1837                 return false;
1838             }
1839             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1840                 return false;
1841             }
1842             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1843                 return false;
1844             }
1845             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1846                     .startsWith( "actgtgggggt" ) ) {
1847                 return false;
1848             }
1849             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1850                     .startsWith( "ctgtgatgcat" ) ) {
1851                 return false;
1852             }
1853             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1854             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1855             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1856             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1857             if ( phylogenies_1.length != 1 ) {
1858                 return false;
1859             }
1860             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1861             if ( !t3_rt.getName().equals( "t3" ) ) {
1862                 return false;
1863             }
1864             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1865                 return false;
1866             }
1867             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1868                 return false;
1869             }
1870             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1871                 return false;
1872             }
1873             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1874                 return false;
1875             }
1876             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1877                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1878                 return false;
1879             }
1880             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1881                 return false;
1882             }
1883             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1884                 return false;
1885             }
1886             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1887                     .equals( "UniProtKB" ) ) {
1888                 return false;
1889             }
1890             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1891                     .equals( "apoptosis" ) ) {
1892                 return false;
1893             }
1894             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1895                     .equals( "GO:0006915" ) ) {
1896                 return false;
1897             }
1898             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1899                     .equals( "UniProtKB" ) ) {
1900                 return false;
1901             }
1902             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1903                     .equals( "experimental" ) ) {
1904                 return false;
1905             }
1906             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1907                     .equals( "function" ) ) {
1908                 return false;
1909             }
1910             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1911                     .getValue() != 1 ) {
1912                 return false;
1913             }
1914             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1915                     .getType().equals( "ml" ) ) {
1916                 return false;
1917             }
1918             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1919                     .equals( "apoptosis" ) ) {
1920                 return false;
1921             }
1922             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1923                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1924                 return false;
1925             }
1926             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1927                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1928                 return false;
1929             }
1930             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1931                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1932                 return false;
1933             }
1934             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1935                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1936                 return false;
1937             }
1938             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1939                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1940                 return false;
1941             }
1942             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1943                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1944                 return false;
1945             }
1946             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1947                     .equals( "GO:0005829" ) ) {
1948                 return false;
1949             }
1950             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1951                     .equals( "intracellular organelle" ) ) {
1952                 return false;
1953             }
1954             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1955                 return false;
1956             }
1957             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1958                     .equals( "UniProt link" ) ) ) {
1959                 return false;
1960             }
1961             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1962                 return false;
1963             }
1964             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1965                 return false;
1966             }
1967             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1968                     .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." ) ) ) {
1969                 return false;
1970             }
1971             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1972                 return false;
1973             }
1974             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1975                 return false;
1976             }
1977             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1978                 return false;
1979             }
1980             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1981                 return false;
1982             }
1983             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1984                     .equals( "ncbi" ) ) {
1985                 return false;
1986             }
1987             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1988                 return false;
1989             }
1990             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1991                     .getName().equals( "B" ) ) {
1992                 return false;
1993             }
1994             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1995                     .getFrom() != 21 ) {
1996                 return false;
1997             }
1998             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1999                 return false;
2000             }
2001             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2002                     .getLength() != 24 ) {
2003                 return false;
2004             }
2005             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2006                     .getConfidence() != 2144 ) {
2007                 return false;
2008             }
2009             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2010                     .equals( "pfam" ) ) {
2011                 return false;
2012             }
2013             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2014                 return false;
2015             }
2016             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2017                 return false;
2018             }
2019             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2020                 return false;
2021             }
2022             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2023                 return false;
2024             }
2025             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2026             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2027                 return false;
2028             }
2029             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2030                 return false;
2031             }
2032             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2033                 return false;
2034             }
2035             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2036                 return false;
2037             }
2038             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2039                 return false;
2040             }
2041             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2042                 return false;
2043             }
2044             if ( taxbb.getSynonyms().size() != 2 ) {
2045                 return false;
2046             }
2047             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2048                 return false;
2049             }
2050             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2051                 return false;
2052             }
2053             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2054                 return false;
2055             }
2056             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2057                 return false;
2058             }
2059             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2060                 return false;
2061             }
2062             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2063                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2064                 return false;
2065             }
2066             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2067                 return false;
2068             }
2069             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2070                 return false;
2071             }
2072             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2073                 return false;
2074             }
2075             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2076                 return false;
2077             }
2078             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2079                 return false;
2080             }
2081             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2082                 return false;
2083             }
2084             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2085                 return false;
2086             }
2087             //
2088             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2089                 return false;
2090             }
2091             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2092                     .equalsIgnoreCase( "435" ) ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2096                 return false;
2097             }
2098             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2099                     .equalsIgnoreCase( "443.7" ) ) {
2100                 return false;
2101             }
2102             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2103                 return false;
2104             }
2105             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2106                 return false;
2107             }
2108             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2109                     .equalsIgnoreCase( "433" ) ) {
2110                 return false;
2111             }
2112             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2113                     .getCrossReferences();
2114             if ( x.size() != 4 ) {
2115                 return false;
2116             }
2117             int c = 0;
2118             for( final Accession acc : x ) {
2119                 if ( c == 0 ) {
2120                     if ( !acc.getSource().equals( "KEGG" ) ) {
2121                         return false;
2122                     }
2123                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2124                         return false;
2125                     }
2126                 }
2127                 c++;
2128             }
2129         }
2130         catch ( final Exception e ) {
2131             e.printStackTrace( System.out );
2132             return false;
2133         }
2134         return true;
2135     }
2136
2137     private static boolean testBasicPhyloXMLparsingValidating() {
2138         try {
2139             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2140             PhyloXmlParser xml_parser = null;
2141             try {
2142                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2143             }
2144             catch ( final Exception e ) {
2145                 // Do nothing -- means were not running from jar.
2146             }
2147             if ( xml_parser == null ) {
2148                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2149                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2150                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2151                 }
2152                 else {
2153                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2154                 }
2155             }
2156             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2157                                                               xml_parser );
2158             if ( xml_parser.getErrorCount() > 0 ) {
2159                 System.out.println( xml_parser.getErrorMessages().toString() );
2160                 return false;
2161             }
2162             if ( phylogenies_0.length != 4 ) {
2163                 return false;
2164             }
2165             final Phylogeny t1 = phylogenies_0[ 0 ];
2166             final Phylogeny t2 = phylogenies_0[ 1 ];
2167             final Phylogeny t3 = phylogenies_0[ 2 ];
2168             final Phylogeny t4 = phylogenies_0[ 3 ];
2169             if ( !t1.getName().equals( "t1" ) ) {
2170                 return false;
2171             }
2172             if ( !t2.getName().equals( "t2" ) ) {
2173                 return false;
2174             }
2175             if ( !t3.getName().equals( "t3" ) ) {
2176                 return false;
2177             }
2178             if ( !t4.getName().equals( "t4" ) ) {
2179                 return false;
2180             }
2181             if ( t1.getNumberOfExternalNodes() != 1 ) {
2182                 return false;
2183             }
2184             if ( t2.getNumberOfExternalNodes() != 2 ) {
2185                 return false;
2186             }
2187             if ( t3.getNumberOfExternalNodes() != 4 ) {
2188                 return false;
2189             }
2190             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2191             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2192             if ( xml_parser.getErrorCount() > 0 ) {
2193                 System.out.println( "errors:" );
2194                 System.out.println( xml_parser.getErrorMessages().toString() );
2195                 return false;
2196             }
2197             if ( phylogenies_1.length != 4 ) {
2198                 return false;
2199             }
2200             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2201                                                               xml_parser );
2202             if ( xml_parser.getErrorCount() > 0 ) {
2203                 System.out.println( "errors:" );
2204                 System.out.println( xml_parser.getErrorMessages().toString() );
2205                 return false;
2206             }
2207             if ( phylogenies_2.length != 1 ) {
2208                 return false;
2209             }
2210             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2211                 return false;
2212             }
2213             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2214                                                               xml_parser );
2215             if ( xml_parser.getErrorCount() > 0 ) {
2216                 System.out.println( xml_parser.getErrorMessages().toString() );
2217                 return false;
2218             }
2219             if ( phylogenies_3.length != 2 ) {
2220                 return false;
2221             }
2222             final Phylogeny a = phylogenies_3[ 0 ];
2223             if ( !a.getName().equals( "tree 4" ) ) {
2224                 return false;
2225             }
2226             if ( a.getNumberOfExternalNodes() != 3 ) {
2227                 return false;
2228             }
2229             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2230                 return false;
2231             }
2232             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2233                 return false;
2234             }
2235             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2236                                                               xml_parser );
2237             if ( xml_parser.getErrorCount() > 0 ) {
2238                 System.out.println( xml_parser.getErrorMessages().toString() );
2239                 return false;
2240             }
2241             if ( phylogenies_4.length != 1 ) {
2242                 return false;
2243             }
2244             final Phylogeny s = phylogenies_4[ 0 ];
2245             if ( s.getNumberOfExternalNodes() != 6 ) {
2246                 return false;
2247             }
2248             s.getNode( "first" );
2249             s.getNode( "<>" );
2250             s.getNode( "\"<a'b&c'd\">\"" );
2251             s.getNode( "'''\"" );
2252             s.getNode( "\"\"\"" );
2253             s.getNode( "dick & doof" );
2254         }
2255         catch ( final Exception e ) {
2256             e.printStackTrace( System.out );
2257             return false;
2258         }
2259         return true;
2260     }
2261
2262     private static boolean testBasicProtein() {
2263         try {
2264             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2265             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2266             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2267             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2268             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2269             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2270             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2271             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2272             p0.addProteinDomain( y );
2273             p0.addProteinDomain( e );
2274             p0.addProteinDomain( b );
2275             p0.addProteinDomain( c );
2276             p0.addProteinDomain( d );
2277             p0.addProteinDomain( a );
2278             p0.addProteinDomain( x );
2279             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2280                 return false;
2281             }
2282             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2283                 return false;
2284             }
2285             //
2286             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2287             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2288             aa0.addProteinDomain( a1 );
2289             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2290                 return false;
2291             }
2292             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2293                 return false;
2294             }
2295             //
2296             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2297             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2298             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2299             aa1.addProteinDomain( a11 );
2300             aa1.addProteinDomain( a12 );
2301             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2302                 return false;
2303             }
2304             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2305                 return false;
2306             }
2307             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2308             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2309                 return false;
2310             }
2311             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2312                 return false;
2313             }
2314             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2315                 return false;
2316             }
2317             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2318             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2319                 return false;
2320             }
2321             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2322                 return false;
2323             }
2324             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2325                 return false;
2326             }
2327             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2328                 return false;
2329             }
2330             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2331             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2332                 return false;
2333             }
2334             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2335                 return false;
2336             }
2337             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2338                 return false;
2339             }
2340             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2341                 return false;
2342             }
2343             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2344             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2345                 return false;
2346             }
2347             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2348                 return false;
2349             }
2350             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2351                 return false;
2352             }
2353             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2354                 return false;
2355             }
2356             //
2357             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2358             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2360             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             p00.addProteinDomain( y0 );
2379             p00.addProteinDomain( e0 );
2380             p00.addProteinDomain( b0 );
2381             p00.addProteinDomain( c0 );
2382             p00.addProteinDomain( d0 );
2383             p00.addProteinDomain( a0 );
2384             p00.addProteinDomain( x0 );
2385             p00.addProteinDomain( y1 );
2386             p00.addProteinDomain( y2 );
2387             p00.addProteinDomain( y3 );
2388             p00.addProteinDomain( e1 );
2389             p00.addProteinDomain( e2 );
2390             p00.addProteinDomain( e3 );
2391             p00.addProteinDomain( e4 );
2392             p00.addProteinDomain( e5 );
2393             p00.addProteinDomain( z0 );
2394             p00.addProteinDomain( z1 );
2395             p00.addProteinDomain( z2 );
2396             p00.addProteinDomain( zz0 );
2397             p00.addProteinDomain( zz1 );
2398             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2399                 return false;
2400             }
2401             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2402                 return false;
2403             }
2404             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2405                 return false;
2406             }
2407             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2408                 return false;
2409             }
2410             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" ) ) {
2411                 return false;
2412             }
2413             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2414             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2415             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2416             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2417             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2418             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2419             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2420             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2421             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2422             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2423             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2424             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2425             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2426             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2427             p.addProteinDomain( B15 );
2428             p.addProteinDomain( C50 );
2429             p.addProteinDomain( A60 );
2430             p.addProteinDomain( A30 );
2431             p.addProteinDomain( C70 );
2432             p.addProteinDomain( B35 );
2433             p.addProteinDomain( B40 );
2434             p.addProteinDomain( A0 );
2435             p.addProteinDomain( A10 );
2436             p.addProteinDomain( A20 );
2437             p.addProteinDomain( B25 );
2438             p.addProteinDomain( D80 );
2439             List<String> domains_ids = new ArrayList<String>();
2440             domains_ids.add( "A" );
2441             domains_ids.add( "B" );
2442             domains_ids.add( "C" );
2443             if ( !p.contains( domains_ids, false ) ) {
2444                 return false;
2445             }
2446             if ( !p.contains( domains_ids, true ) ) {
2447                 return false;
2448             }
2449             domains_ids.add( "X" );
2450             if ( p.contains( domains_ids, false ) ) {
2451                 return false;
2452             }
2453             if ( p.contains( domains_ids, true ) ) {
2454                 return false;
2455             }
2456             domains_ids = new ArrayList<String>();
2457             domains_ids.add( "A" );
2458             domains_ids.add( "C" );
2459             domains_ids.add( "D" );
2460             if ( !p.contains( domains_ids, false ) ) {
2461                 return false;
2462             }
2463             if ( !p.contains( domains_ids, true ) ) {
2464                 return false;
2465             }
2466             domains_ids = new ArrayList<String>();
2467             domains_ids.add( "A" );
2468             domains_ids.add( "D" );
2469             domains_ids.add( "C" );
2470             if ( !p.contains( domains_ids, false ) ) {
2471                 return false;
2472             }
2473             if ( p.contains( domains_ids, true ) ) {
2474                 return false;
2475             }
2476             domains_ids = new ArrayList<String>();
2477             domains_ids.add( "A" );
2478             domains_ids.add( "A" );
2479             domains_ids.add( "B" );
2480             if ( !p.contains( domains_ids, false ) ) {
2481                 return false;
2482             }
2483             if ( !p.contains( domains_ids, true ) ) {
2484                 return false;
2485             }
2486             domains_ids = new ArrayList<String>();
2487             domains_ids.add( "A" );
2488             domains_ids.add( "A" );
2489             domains_ids.add( "A" );
2490             domains_ids.add( "B" );
2491             domains_ids.add( "B" );
2492             if ( !p.contains( domains_ids, false ) ) {
2493                 return false;
2494             }
2495             if ( !p.contains( domains_ids, true ) ) {
2496                 return false;
2497             }
2498             domains_ids = new ArrayList<String>();
2499             domains_ids.add( "A" );
2500             domains_ids.add( "A" );
2501             domains_ids.add( "B" );
2502             domains_ids.add( "A" );
2503             domains_ids.add( "B" );
2504             domains_ids.add( "B" );
2505             domains_ids.add( "A" );
2506             domains_ids.add( "B" );
2507             domains_ids.add( "C" );
2508             domains_ids.add( "A" );
2509             domains_ids.add( "C" );
2510             domains_ids.add( "D" );
2511             if ( !p.contains( domains_ids, false ) ) {
2512                 return false;
2513             }
2514             if ( p.contains( domains_ids, true ) ) {
2515                 return false;
2516             }
2517         }
2518         catch ( final Exception e ) {
2519             e.printStackTrace( System.out );
2520             return false;
2521         }
2522         return true;
2523     }
2524
2525     private static boolean testBasicTable() {
2526         try {
2527             final BasicTable<String> t0 = new BasicTable<String>();
2528             if ( t0.getNumberOfColumns() != 0 ) {
2529                 return false;
2530             }
2531             if ( t0.getNumberOfRows() != 0 ) {
2532                 return false;
2533             }
2534             t0.setValue( 3, 2, "23" );
2535             t0.setValue( 10, 1, "error" );
2536             t0.setValue( 10, 1, "110" );
2537             t0.setValue( 9, 1, "19" );
2538             t0.setValue( 1, 10, "101" );
2539             t0.setValue( 10, 10, "1010" );
2540             t0.setValue( 100, 10, "10100" );
2541             t0.setValue( 0, 0, "00" );
2542             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2543                 return false;
2544             }
2545             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2546                 return false;
2547             }
2548             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2549                 return false;
2550             }
2551             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2552                 return false;
2553             }
2554             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2555                 return false;
2556             }
2557             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2558                 return false;
2559             }
2560             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2561                 return false;
2562             }
2563             if ( t0.getNumberOfColumns() != 101 ) {
2564                 return false;
2565             }
2566             if ( t0.getNumberOfRows() != 11 ) {
2567                 return false;
2568             }
2569             if ( t0.getValueAsString( 49, 4 ) != null ) {
2570                 return false;
2571             }
2572             final String l = ForesterUtil.getLineSeparator();
2573             final StringBuffer source = new StringBuffer();
2574             source.append( "" + l );
2575             source.append( "# 1 1 1 1 1 1 1 1" + l );
2576             source.append( " 00 01 02 03" + l );
2577             source.append( "   10 11 12 13  " + l );
2578             source.append( "20 21 22 23 " + l );
2579             source.append( "    30  31    32 33" + l );
2580             source.append( "40 41 42 43" + l );
2581             source.append( "  # 1 1 1 1 1 " + l );
2582             source.append( "50 51 52 53 54" + l );
2583             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2584             if ( t1.getNumberOfColumns() != 5 ) {
2585                 return false;
2586             }
2587             if ( t1.getNumberOfRows() != 6 ) {
2588                 return false;
2589             }
2590             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2591                 return false;
2592             }
2593             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2594                 return false;
2595             }
2596             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2597                 return false;
2598             }
2599             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2600                 return false;
2601             }
2602             final StringBuffer source1 = new StringBuffer();
2603             source1.append( "" + l );
2604             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2605             source1.append( " 00; 01 ;02;03" + l );
2606             source1.append( "   10; 11; 12; 13  " + l );
2607             source1.append( "20; 21; 22; 23 " + l );
2608             source1.append( "    30;  31;    32; 33" + l );
2609             source1.append( "40;41;42;43" + l );
2610             source1.append( "  # 1 1 1 1 1 " + l );
2611             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2612             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2613             if ( t2.getNumberOfColumns() != 5 ) {
2614                 return false;
2615             }
2616             if ( t2.getNumberOfRows() != 6 ) {
2617                 return false;
2618             }
2619             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2620                 return false;
2621             }
2622             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2623                 return false;
2624             }
2625             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2626                 return false;
2627             }
2628             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2629                 return false;
2630             }
2631             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2632                 return false;
2633             }
2634             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2635                 return false;
2636             }
2637             final StringBuffer source2 = new StringBuffer();
2638             source2.append( "" + l );
2639             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2640             source2.append( " 00; 01 ;02;03" + l );
2641             source2.append( "   10; 11; 12; 13  " + l );
2642             source2.append( "20; 21; 22; 23 " + l );
2643             source2.append( "                     " + l );
2644             source2.append( "    30;  31;    32; 33" + l );
2645             source2.append( "40;41;42;43" + l );
2646             source2.append( "  comment: 1 1 1 1 1 " + l );
2647             source2.append( ";;;50  ;   52; 53;;54   " + l );
2648             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2649                                                                         ';',
2650                                                                         false,
2651                                                                         false,
2652                                                                         "comment:",
2653                                                                         false );
2654             if ( tl.size() != 2 ) {
2655                 return false;
2656             }
2657             final BasicTable<String> t3 = tl.get( 0 );
2658             final BasicTable<String> t4 = tl.get( 1 );
2659             if ( t3.getNumberOfColumns() != 4 ) {
2660                 return false;
2661             }
2662             if ( t3.getNumberOfRows() != 3 ) {
2663                 return false;
2664             }
2665             if ( t4.getNumberOfColumns() != 4 ) {
2666                 return false;
2667             }
2668             if ( t4.getNumberOfRows() != 3 ) {
2669                 return false;
2670             }
2671             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2672                 return false;
2673             }
2674             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2675                 return false;
2676             }
2677         }
2678         catch ( final Exception e ) {
2679             e.printStackTrace( System.out );
2680             return false;
2681         }
2682         return true;
2683     }
2684
2685     private static boolean testBasicTolXMLparsing() {
2686         try {
2687             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2688             final TolParser parser = new TolParser();
2689             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2690             if ( parser.getErrorCount() > 0 ) {
2691                 System.out.println( parser.getErrorMessages().toString() );
2692                 return false;
2693             }
2694             if ( phylogenies_0.length != 1 ) {
2695                 return false;
2696             }
2697             final Phylogeny t1 = phylogenies_0[ 0 ];
2698             if ( t1.getNumberOfExternalNodes() != 5 ) {
2699                 return false;
2700             }
2701             if ( !t1.isRooted() ) {
2702                 return false;
2703             }
2704             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2705                 return false;
2706             }
2707             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2708                 return false;
2709             }
2710             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2711                 return false;
2712             }
2713             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2714                 return false;
2715             }
2716             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2717             if ( parser.getErrorCount() > 0 ) {
2718                 System.out.println( parser.getErrorMessages().toString() );
2719                 return false;
2720             }
2721             if ( phylogenies_1.length != 1 ) {
2722                 return false;
2723             }
2724             final Phylogeny t2 = phylogenies_1[ 0 ];
2725             if ( t2.getNumberOfExternalNodes() != 664 ) {
2726                 return false;
2727             }
2728             if ( !t2.isRooted() ) {
2729                 return false;
2730             }
2731             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2732                 return false;
2733             }
2734             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2735                 return false;
2736             }
2737             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2738                 return false;
2739             }
2740             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2741                 return false;
2742             }
2743             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2744                 return false;
2745             }
2746             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2747                     .equals( "Aquifex" ) ) {
2748                 return false;
2749             }
2750             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2751             if ( parser.getErrorCount() > 0 ) {
2752                 System.out.println( parser.getErrorMessages().toString() );
2753                 return false;
2754             }
2755             if ( phylogenies_2.length != 1 ) {
2756                 return false;
2757             }
2758             final Phylogeny t3 = phylogenies_2[ 0 ];
2759             if ( t3.getNumberOfExternalNodes() != 184 ) {
2760                 return false;
2761             }
2762             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2763                 return false;
2764             }
2765             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2766                 return false;
2767             }
2768             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2769                 return false;
2770             }
2771             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2772             if ( parser.getErrorCount() > 0 ) {
2773                 System.out.println( parser.getErrorMessages().toString() );
2774                 return false;
2775             }
2776             if ( phylogenies_3.length != 1 ) {
2777                 return false;
2778             }
2779             final Phylogeny t4 = phylogenies_3[ 0 ];
2780             if ( t4.getNumberOfExternalNodes() != 1 ) {
2781                 return false;
2782             }
2783             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2784                 return false;
2785             }
2786             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2787                 return false;
2788             }
2789             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2790                 return false;
2791             }
2792             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2793             if ( parser.getErrorCount() > 0 ) {
2794                 System.out.println( parser.getErrorMessages().toString() );
2795                 return false;
2796             }
2797             if ( phylogenies_4.length != 1 ) {
2798                 return false;
2799             }
2800             final Phylogeny t5 = phylogenies_4[ 0 ];
2801             if ( t5.getNumberOfExternalNodes() != 13 ) {
2802                 return false;
2803             }
2804             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2805                 return false;
2806             }
2807             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2808                 return false;
2809             }
2810             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2811                 return false;
2812             }
2813         }
2814         catch ( final Exception e ) {
2815             e.printStackTrace( System.out );
2816             return false;
2817         }
2818         return true;
2819     }
2820
2821     private static boolean testBasicTreeMethods() {
2822         try {
2823             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2824             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2825             if ( t2.getNumberOfExternalNodes() != 4 ) {
2826                 return false;
2827             }
2828             if ( t2.getHeight() != 8.5 ) {
2829                 return false;
2830             }
2831             if ( !t2.isCompletelyBinary() ) {
2832                 return false;
2833             }
2834             if ( t2.isEmpty() ) {
2835                 return false;
2836             }
2837             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2838             if ( t3.getNumberOfExternalNodes() != 5 ) {
2839                 return false;
2840             }
2841             if ( t3.getHeight() != 11 ) {
2842                 return false;
2843             }
2844             if ( t3.isCompletelyBinary() ) {
2845                 return false;
2846             }
2847             final PhylogenyNode n = t3.getNode( "ABC" );
2848             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 ];
2849             if ( t4.getNumberOfExternalNodes() != 9 ) {
2850                 return false;
2851             }
2852             if ( t4.getHeight() != 11 ) {
2853                 return false;
2854             }
2855             if ( t4.isCompletelyBinary() ) {
2856                 return false;
2857             }
2858             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)" );
2859             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2860             if ( t5.getNumberOfExternalNodes() != 8 ) {
2861                 return false;
2862             }
2863             if ( t5.getHeight() != 15 ) {
2864                 return false;
2865             }
2866             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)" );
2867             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2868             if ( t6.getHeight() != 15 ) {
2869                 return false;
2870             }
2871             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)" );
2872             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2873             if ( t7.getHeight() != 15 ) {
2874                 return false;
2875             }
2876             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)" );
2877             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2878             if ( t8.getNumberOfExternalNodes() != 10 ) {
2879                 return false;
2880             }
2881             if ( t8.getHeight() != 15 ) {
2882                 return false;
2883             }
2884             final char[] a9 = new char[] { 'a' };
2885             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2886             if ( t9.getHeight() != 0 ) {
2887                 return false;
2888             }
2889             final char[] a10 = new char[] { 'a', ':', '6' };
2890             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2891             if ( t10.getHeight() != 6 ) {
2892                 return false;
2893             }
2894         }
2895         catch ( final Exception e ) {
2896             e.printStackTrace( System.out );
2897             return false;
2898         }
2899         return true;
2900     }
2901
2902     private static boolean testConfidenceAssessor() {
2903         try {
2904             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2905             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2906             final Phylogeny[] ev0 = factory
2907                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2908                              new NHXParser() );
2909             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2910             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2911                 return false;
2912             }
2913             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2914                 return false;
2915             }
2916             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2917             final Phylogeny[] ev1 = factory
2918                     .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)));",
2919                              new NHXParser() );
2920             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2921             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2922                 return false;
2923             }
2924             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2925                 return false;
2926             }
2927             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2928             final Phylogeny[] ev_b = factory
2929                     .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",
2930                              new NHXParser() );
2931             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2932             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2933                 return false;
2934             }
2935             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2936                 return false;
2937             }
2938             //
2939             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2940             final Phylogeny[] ev1x = factory
2941                     .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)));",
2942                              new NHXParser() );
2943             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2944             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2945                 return false;
2946             }
2947             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2948                 return false;
2949             }
2950             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2951             final Phylogeny[] ev_bx = factory
2952                     .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",
2953                              new NHXParser() );
2954             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2955             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2956                 return false;
2957             }
2958             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2959                 return false;
2960             }
2961             //
2962             final Phylogeny[] t2 = factory
2963                     .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);",
2964                              new NHXParser() );
2965             final Phylogeny[] ev2 = factory
2966                     .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);",
2967                              new NHXParser() );
2968             for( final Phylogeny target : t2 ) {
2969                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2970             }
2971             //
2972             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2973                                                  new NHXParser() )[ 0 ];
2974             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2975             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2976             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2977                 return false;
2978             }
2979             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2980                 return false;
2981             }
2982             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2983                 return false;
2984             }
2985         }
2986         catch ( final Exception e ) {
2987             e.printStackTrace();
2988             return false;
2989         }
2990         return true;
2991     }
2992
2993     private static boolean testCopyOfNodeData() {
2994         try {
2995             final PhylogenyNode n1 = PhylogenyNode
2996                     .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]" );
2997             final PhylogenyNode n2 = n1.copyNodeData();
2998             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2999                 return false;
3000             }
3001         }
3002         catch ( final Exception e ) {
3003             e.printStackTrace();
3004             return false;
3005         }
3006         return true;
3007     }
3008
3009     private static boolean testCreateBalancedPhylogeny() {
3010         try {
3011             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3012             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3013                 return false;
3014             }
3015             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3016                 return false;
3017             }
3018             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3019             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3020                 return false;
3021             }
3022             if ( p1.getNumberOfExternalNodes() != 100 ) {
3023                 return false;
3024             }
3025         }
3026         catch ( final Exception e ) {
3027             e.printStackTrace();
3028             return false;
3029         }
3030         return true;
3031     }
3032
3033     private static boolean testCreateUriForSeqWeb() {
3034         try {
3035             final PhylogenyNode n = new PhylogenyNode();
3036             n.setName( "tr|B3RJ64" );
3037             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3038                 return false;
3039             }
3040             n.setName( "B0LM41_HUMAN" );
3041             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3042                 return false;
3043             }
3044             n.setName( "NP_001025424" );
3045             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3046                 return false;
3047             }
3048             n.setName( "_NM_001030253-" );
3049             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3050                 return false;
3051             }
3052             n.setName( "XM_002122186" );
3053             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3054                 return false;
3055             }
3056             n.setName( "dgh_AAA34956_gdg" );
3057             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3058                 return false;
3059             }
3060             n.setName( "AAA34956" );
3061             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3062                 return false;
3063             }
3064             n.setName( "GI:394892" );
3065             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3066                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3067                 return false;
3068             }
3069             n.setName( "gi_394892" );
3070             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3071                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3072                 return false;
3073             }
3074             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3075             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3076                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3077                 return false;
3078             }
3079             n.setName( "P12345" );
3080             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3081                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3082                 return false;
3083             }
3084             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3085             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3086                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3087                 return false;
3088             }
3089         }
3090         catch ( final Exception e ) {
3091             e.printStackTrace( System.out );
3092             return false;
3093         }
3094         return true;
3095     }
3096
3097     private static boolean testDataObjects() {
3098         try {
3099             final Confidence s0 = new Confidence();
3100             final Confidence s1 = new Confidence();
3101             if ( !s0.isEqual( s1 ) ) {
3102                 return false;
3103             }
3104             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3105             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3106             if ( s2.isEqual( s1 ) ) {
3107                 return false;
3108             }
3109             if ( !s2.isEqual( s3 ) ) {
3110                 return false;
3111             }
3112             final Confidence s4 = ( Confidence ) s3.copy();
3113             if ( !s4.isEqual( s3 ) ) {
3114                 return false;
3115             }
3116             s3.asSimpleText();
3117             s3.asText();
3118             // Taxonomy
3119             // ----------
3120             final Taxonomy t1 = new Taxonomy();
3121             final Taxonomy t2 = new Taxonomy();
3122             final Taxonomy t3 = new Taxonomy();
3123             final Taxonomy t4 = new Taxonomy();
3124             final Taxonomy t5 = new Taxonomy();
3125             t1.setIdentifier( new Identifier( "ecoli" ) );
3126             t1.setTaxonomyCode( "ECOLI" );
3127             t1.setScientificName( "E. coli" );
3128             t1.setCommonName( "coli" );
3129             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3130             if ( !t1.isEqual( t0 ) ) {
3131                 return false;
3132             }
3133             t2.setIdentifier( new Identifier( "ecoli" ) );
3134             t2.setTaxonomyCode( "OTHER" );
3135             t2.setScientificName( "what" );
3136             t2.setCommonName( "something" );
3137             if ( !t1.isEqual( t2 ) ) {
3138                 return false;
3139             }
3140             t2.setIdentifier( new Identifier( "nemve" ) );
3141             if ( t1.isEqual( t2 ) ) {
3142                 return false;
3143             }
3144             t1.setIdentifier( null );
3145             t3.setTaxonomyCode( "ECOLI" );
3146             t3.setScientificName( "what" );
3147             t3.setCommonName( "something" );
3148             if ( !t1.isEqual( t3 ) ) {
3149                 return false;
3150             }
3151             t1.setIdentifier( null );
3152             t1.setTaxonomyCode( "" );
3153             t4.setScientificName( "E. ColI" );
3154             t4.setCommonName( "something" );
3155             if ( !t1.isEqual( t4 ) ) {
3156                 return false;
3157             }
3158             t4.setScientificName( "B. subtilis" );
3159             t4.setCommonName( "something" );
3160             if ( t1.isEqual( t4 ) ) {
3161                 return false;
3162             }
3163             t1.setIdentifier( null );
3164             t1.setTaxonomyCode( "" );
3165             t1.setScientificName( "" );
3166             t5.setCommonName( "COLI" );
3167             if ( !t1.isEqual( t5 ) ) {
3168                 return false;
3169             }
3170             t5.setCommonName( "vibrio" );
3171             if ( t1.isEqual( t5 ) ) {
3172                 return false;
3173             }
3174             // Identifier
3175             // ----------
3176             final Identifier id0 = new Identifier( "123", "pfam" );
3177             final Identifier id1 = ( Identifier ) id0.copy();
3178             if ( !id1.isEqual( id1 ) ) {
3179                 return false;
3180             }
3181             if ( !id1.isEqual( id0 ) ) {
3182                 return false;
3183             }
3184             if ( !id0.isEqual( id1 ) ) {
3185                 return false;
3186             }
3187             id1.asSimpleText();
3188             id1.asText();
3189             // ProteinDomain
3190             // ---------------
3191             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3192             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3193             if ( !pd1.isEqual( pd1 ) ) {
3194                 return false;
3195             }
3196             if ( !pd1.isEqual( pd0 ) ) {
3197                 return false;
3198             }
3199             pd1.asSimpleText();
3200             pd1.asText();
3201             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3202             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3203             if ( !pd3.isEqual( pd3 ) ) {
3204                 return false;
3205             }
3206             if ( !pd2.isEqual( pd3 ) ) {
3207                 return false;
3208             }
3209             if ( !pd0.isEqual( pd3 ) ) {
3210                 return false;
3211             }
3212             pd3.asSimpleText();
3213             pd3.asText();
3214             // DomainArchitecture
3215             // ------------------
3216             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3217             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3218             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3219             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3220             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3221             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3222             domains0.add( d2 );
3223             domains0.add( d0 );
3224             domains0.add( d3 );
3225             domains0.add( d1 );
3226             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3227             if ( ds0.getNumberOfDomains() != 4 ) {
3228                 return false;
3229             }
3230             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3231             if ( !ds0.isEqual( ds0 ) ) {
3232                 return false;
3233             }
3234             if ( !ds0.isEqual( ds1 ) ) {
3235                 return false;
3236             }
3237             if ( ds1.getNumberOfDomains() != 4 ) {
3238                 return false;
3239             }
3240             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3241             domains1.add( d1 );
3242             domains1.add( d2 );
3243             domains1.add( d4 );
3244             domains1.add( d0 );
3245             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3246             if ( ds0.isEqual( ds2 ) ) {
3247                 return false;
3248             }
3249             ds1.asSimpleText();
3250             ds1.asText();
3251             ds1.toNHX();
3252             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3253             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3254                 System.out.println( ds3.toNHX() );
3255                 return false;
3256             }
3257             if ( ds3.getNumberOfDomains() != 3 ) {
3258                 return false;
3259             }
3260             // Event
3261             // -----
3262             final Event e1 = new Event( Event.EventType.fusion );
3263             if ( e1.isDuplication() ) {
3264                 return false;
3265             }
3266             if ( !e1.isFusion() ) {
3267                 return false;
3268             }
3269             if ( !e1.asText().toString().equals( "fusion" ) ) {
3270                 return false;
3271             }
3272             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3273                 return false;
3274             }
3275             final Event e11 = new Event( Event.EventType.fusion );
3276             if ( !e11.isEqual( e1 ) ) {
3277                 return false;
3278             }
3279             if ( !e11.toNHX().toString().equals( "" ) ) {
3280                 return false;
3281             }
3282             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3283             if ( e2.isDuplication() ) {
3284                 return false;
3285             }
3286             if ( !e2.isSpeciationOrDuplication() ) {
3287                 return false;
3288             }
3289             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3290                 return false;
3291             }
3292             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3293                 return false;
3294             }
3295             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3296                 return false;
3297             }
3298             if ( e11.isEqual( e2 ) ) {
3299                 return false;
3300             }
3301             final Event e2c = ( Event ) e2.copy();
3302             if ( !e2c.isEqual( e2 ) ) {
3303                 return false;
3304             }
3305             Event e3 = new Event( 1, 2, 3 );
3306             if ( e3.isDuplication() ) {
3307                 return false;
3308             }
3309             if ( e3.isSpeciation() ) {
3310                 return false;
3311             }
3312             if ( e3.isGeneLoss() ) {
3313                 return false;
3314             }
3315             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3316                 return false;
3317             }
3318             final Event e3c = ( Event ) e3.copy();
3319             final Event e3cc = ( Event ) e3c.copy();
3320             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3321                 return false;
3322             }
3323             e3 = null;
3324             if ( !e3c.isEqual( e3cc ) ) {
3325                 return false;
3326             }
3327             Event e4 = new Event( 1, 2, 3 );
3328             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3329                 return false;
3330             }
3331             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3332                 return false;
3333             }
3334             final Event e4c = ( Event ) e4.copy();
3335             e4 = null;
3336             final Event e4cc = ( Event ) e4c.copy();
3337             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3338                 return false;
3339             }
3340             if ( !e4c.isEqual( e4cc ) ) {
3341                 return false;
3342             }
3343             final Event e5 = new Event();
3344             if ( !e5.isUnassigned() ) {
3345                 return false;
3346             }
3347             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3348                 return false;
3349             }
3350             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3351                 return false;
3352             }
3353             final Event e6 = new Event( 1, 0, 0 );
3354             if ( !e6.asText().toString().equals( "duplication" ) ) {
3355                 return false;
3356             }
3357             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3358                 return false;
3359             }
3360             final Event e7 = new Event( 0, 1, 0 );
3361             if ( !e7.asText().toString().equals( "speciation" ) ) {
3362                 return false;
3363             }
3364             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3365                 return false;
3366             }
3367             final Event e8 = new Event( 0, 0, 1 );
3368             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3369                 return false;
3370             }
3371             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3372                 return false;
3373             }
3374         }
3375         catch ( final Exception e ) {
3376             e.printStackTrace( System.out );
3377             return false;
3378         }
3379         return true;
3380     }
3381
3382     private static boolean testDeletionOfExternalNodes() {
3383         try {
3384             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3385             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3386             final PhylogenyWriter w = new PhylogenyWriter();
3387             if ( t0.isEmpty() ) {
3388                 return false;
3389             }
3390             if ( t0.getNumberOfExternalNodes() != 1 ) {
3391                 return false;
3392             }
3393             t0.deleteSubtree( t0.getNode( "A" ), false );
3394             if ( t0.getNumberOfExternalNodes() != 0 ) {
3395                 return false;
3396             }
3397             if ( !t0.isEmpty() ) {
3398                 return false;
3399             }
3400             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3401             if ( t1.getNumberOfExternalNodes() != 2 ) {
3402                 return false;
3403             }
3404             t1.deleteSubtree( t1.getNode( "A" ), false );
3405             if ( t1.getNumberOfExternalNodes() != 1 ) {
3406                 return false;
3407             }
3408             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3409                 return false;
3410             }
3411             t1.deleteSubtree( t1.getNode( "B" ), false );
3412             if ( t1.getNumberOfExternalNodes() != 1 ) {
3413                 return false;
3414             }
3415             t1.deleteSubtree( t1.getNode( "r" ), false );
3416             if ( !t1.isEmpty() ) {
3417                 return false;
3418             }
3419             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3420             if ( t2.getNumberOfExternalNodes() != 3 ) {
3421                 return false;
3422             }
3423             t2.deleteSubtree( t2.getNode( "B" ), false );
3424             if ( t2.getNumberOfExternalNodes() != 2 ) {
3425                 return false;
3426             }
3427             t2.toNewHampshireX();
3428             PhylogenyNode n = t2.getNode( "A" );
3429             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3430                 return false;
3431             }
3432             t2.deleteSubtree( t2.getNode( "A" ), false );
3433             if ( t2.getNumberOfExternalNodes() != 2 ) {
3434                 return false;
3435             }
3436             t2.deleteSubtree( t2.getNode( "C" ), true );
3437             if ( t2.getNumberOfExternalNodes() != 1 ) {
3438                 return false;
3439             }
3440             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3441             if ( t3.getNumberOfExternalNodes() != 4 ) {
3442                 return false;
3443             }
3444             t3.deleteSubtree( t3.getNode( "B" ), true );
3445             if ( t3.getNumberOfExternalNodes() != 3 ) {
3446                 return false;
3447             }
3448             n = t3.getNode( "A" );
3449             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3450                 return false;
3451             }
3452             n = n.getNextExternalNode();
3453             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3454                 return false;
3455             }
3456             t3.deleteSubtree( t3.getNode( "A" ), true );
3457             if ( t3.getNumberOfExternalNodes() != 2 ) {
3458                 return false;
3459             }
3460             n = t3.getNode( "C" );
3461             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3462                 return false;
3463             }
3464             t3.deleteSubtree( t3.getNode( "C" ), true );
3465             if ( t3.getNumberOfExternalNodes() != 1 ) {
3466                 return false;
3467             }
3468             t3.deleteSubtree( t3.getNode( "D" ), true );
3469             if ( t3.getNumberOfExternalNodes() != 0 ) {
3470                 return false;
3471             }
3472             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3473             if ( t4.getNumberOfExternalNodes() != 6 ) {
3474                 return false;
3475             }
3476             t4.deleteSubtree( t4.getNode( "B2" ), true );
3477             if ( t4.getNumberOfExternalNodes() != 5 ) {
3478                 return false;
3479             }
3480             String s = w.toNewHampshire( t4, true ).toString();
3481             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3482                 return false;
3483             }
3484             t4.deleteSubtree( t4.getNode( "B11" ), true );
3485             if ( t4.getNumberOfExternalNodes() != 4 ) {
3486                 return false;
3487             }
3488             t4.deleteSubtree( t4.getNode( "C" ), true );
3489             if ( t4.getNumberOfExternalNodes() != 3 ) {
3490                 return false;
3491             }
3492             n = t4.getNode( "A" );
3493             n = n.getNextExternalNode();
3494             if ( !n.getName().equals( "B12" ) ) {
3495                 return false;
3496             }
3497             n = n.getNextExternalNode();
3498             if ( !n.getName().equals( "D" ) ) {
3499                 return false;
3500             }
3501             s = w.toNewHampshire( t4, true ).toString();
3502             if ( !s.equals( "((A,B12),D);" ) ) {
3503                 return false;
3504             }
3505             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3506             t5.deleteSubtree( t5.getNode( "A" ), true );
3507             if ( t5.getNumberOfExternalNodes() != 5 ) {
3508                 return false;
3509             }
3510             s = w.toNewHampshire( t5, true ).toString();
3511             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3512                 return false;
3513             }
3514             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3515             t6.deleteSubtree( t6.getNode( "B11" ), true );
3516             if ( t6.getNumberOfExternalNodes() != 5 ) {
3517                 return false;
3518             }
3519             s = w.toNewHampshire( t6, false ).toString();
3520             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3521                 return false;
3522             }
3523             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3524             t7.deleteSubtree( t7.getNode( "B12" ), true );
3525             if ( t7.getNumberOfExternalNodes() != 5 ) {
3526                 return false;
3527             }
3528             s = w.toNewHampshire( t7, true ).toString();
3529             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3530                 return false;
3531             }
3532             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3533             t8.deleteSubtree( t8.getNode( "B2" ), true );
3534             if ( t8.getNumberOfExternalNodes() != 5 ) {
3535                 return false;
3536             }
3537             s = w.toNewHampshire( t8, false ).toString();
3538             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3539                 return false;
3540             }
3541             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3542             t9.deleteSubtree( t9.getNode( "C" ), true );
3543             if ( t9.getNumberOfExternalNodes() != 5 ) {
3544                 return false;
3545             }
3546             s = w.toNewHampshire( t9, true ).toString();
3547             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3548                 return false;
3549             }
3550             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3551             t10.deleteSubtree( t10.getNode( "D" ), true );
3552             if ( t10.getNumberOfExternalNodes() != 5 ) {
3553                 return false;
3554             }
3555             s = w.toNewHampshire( t10, true ).toString();
3556             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3557                 return false;
3558             }
3559             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3560             t11.deleteSubtree( t11.getNode( "A" ), true );
3561             if ( t11.getNumberOfExternalNodes() != 2 ) {
3562                 return false;
3563             }
3564             s = w.toNewHampshire( t11, true ).toString();
3565             if ( !s.equals( "(B,C);" ) ) {
3566                 return false;
3567             }
3568             t11.deleteSubtree( t11.getNode( "C" ), true );
3569             if ( t11.getNumberOfExternalNodes() != 1 ) {
3570                 return false;
3571             }
3572             s = w.toNewHampshire( t11, false ).toString();
3573             if ( !s.equals( "B;" ) ) {
3574                 return false;
3575             }
3576             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3577             t12.deleteSubtree( t12.getNode( "B2" ), true );
3578             if ( t12.getNumberOfExternalNodes() != 8 ) {
3579                 return false;
3580             }
3581             s = w.toNewHampshire( t12, true ).toString();
3582             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3583                 return false;
3584             }
3585             t12.deleteSubtree( t12.getNode( "B3" ), true );
3586             if ( t12.getNumberOfExternalNodes() != 7 ) {
3587                 return false;
3588             }
3589             s = w.toNewHampshire( t12, true ).toString();
3590             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3591                 return false;
3592             }
3593             t12.deleteSubtree( t12.getNode( "C3" ), true );
3594             if ( t12.getNumberOfExternalNodes() != 6 ) {
3595                 return false;
3596             }
3597             s = w.toNewHampshire( t12, true ).toString();
3598             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3599                 return false;
3600             }
3601             t12.deleteSubtree( t12.getNode( "A1" ), true );
3602             if ( t12.getNumberOfExternalNodes() != 5 ) {
3603                 return false;
3604             }
3605             s = w.toNewHampshire( t12, true ).toString();
3606             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3607                 return false;
3608             }
3609             t12.deleteSubtree( t12.getNode( "B1" ), true );
3610             if ( t12.getNumberOfExternalNodes() != 4 ) {
3611                 return false;
3612             }
3613             s = w.toNewHampshire( t12, true ).toString();
3614             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3615                 return false;
3616             }
3617             t12.deleteSubtree( t12.getNode( "A3" ), true );
3618             if ( t12.getNumberOfExternalNodes() != 3 ) {
3619                 return false;
3620             }
3621             s = w.toNewHampshire( t12, true ).toString();
3622             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3623                 return false;
3624             }
3625             t12.deleteSubtree( t12.getNode( "A2" ), true );
3626             if ( t12.getNumberOfExternalNodes() != 2 ) {
3627                 return false;
3628             }
3629             s = w.toNewHampshire( t12, true ).toString();
3630             if ( !s.equals( "(C1,C2);" ) ) {
3631                 return false;
3632             }
3633             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3634             t13.deleteSubtree( t13.getNode( "D" ), true );
3635             if ( t13.getNumberOfExternalNodes() != 4 ) {
3636                 return false;
3637             }
3638             s = w.toNewHampshire( t13, true ).toString();
3639             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3640                 return false;
3641             }
3642             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3643             t14.deleteSubtree( t14.getNode( "E" ), true );
3644             if ( t14.getNumberOfExternalNodes() != 5 ) {
3645                 return false;
3646             }
3647             s = w.toNewHampshire( t14, true ).toString();
3648             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3649                 return false;
3650             }
3651             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3652             t15.deleteSubtree( t15.getNode( "B2" ), true );
3653             if ( t15.getNumberOfExternalNodes() != 11 ) {
3654                 return false;
3655             }
3656             t15.deleteSubtree( t15.getNode( "B1" ), true );
3657             if ( t15.getNumberOfExternalNodes() != 10 ) {
3658                 return false;
3659             }
3660             t15.deleteSubtree( t15.getNode( "B3" ), true );
3661             if ( t15.getNumberOfExternalNodes() != 9 ) {
3662                 return false;
3663             }
3664             t15.deleteSubtree( t15.getNode( "B4" ), true );
3665             if ( t15.getNumberOfExternalNodes() != 8 ) {
3666                 return false;
3667             }
3668             t15.deleteSubtree( t15.getNode( "A1" ), true );
3669             if ( t15.getNumberOfExternalNodes() != 7 ) {
3670                 return false;
3671             }
3672             t15.deleteSubtree( t15.getNode( "C4" ), true );
3673             if ( t15.getNumberOfExternalNodes() != 6 ) {
3674                 return false;
3675             }
3676         }
3677         catch ( final Exception e ) {
3678             e.printStackTrace( System.out );
3679             return false;
3680         }
3681         return true;
3682     }
3683
3684     private static boolean testDescriptiveStatistics() {
3685         try {
3686             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3687             dss1.addValue( 82 );
3688             dss1.addValue( 78 );
3689             dss1.addValue( 70 );
3690             dss1.addValue( 58 );
3691             dss1.addValue( 42 );
3692             if ( dss1.getN() != 5 ) {
3693                 return false;
3694             }
3695             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3696                 return false;
3697             }
3698             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3699                 return false;
3700             }
3701             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3702                 return false;
3703             }
3704             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3705                 return false;
3706             }
3707             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3708                 return false;
3709             }
3710             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3711                 return false;
3712             }
3713             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3714                 return false;
3715             }
3716             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3717                 return false;
3718             }
3719             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3720                 return false;
3721             }
3722             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3723                 return false;
3724             }
3725             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3726                 return false;
3727             }
3728             dss1.addValue( 123 );
3729             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3730                 return false;
3731             }
3732             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3733                 return false;
3734             }
3735             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3736                 return false;
3737             }
3738             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3739             dss2.addValue( -1.85 );
3740             dss2.addValue( 57.5 );
3741             dss2.addValue( 92.78 );
3742             dss2.addValue( 57.78 );
3743             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3744                 return false;
3745             }
3746             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3747                 return false;
3748             }
3749             final double[] a = dss2.getDataAsDoubleArray();
3750             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3751                 return false;
3752             }
3753             dss2.addValue( -100 );
3754             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3755                 return false;
3756             }
3757             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3758                 return false;
3759             }
3760             final double[] ds = new double[ 14 ];
3761             ds[ 0 ] = 34;
3762             ds[ 1 ] = 23;
3763             ds[ 2 ] = 1;
3764             ds[ 3 ] = 32;
3765             ds[ 4 ] = 11;
3766             ds[ 5 ] = 2;
3767             ds[ 6 ] = 12;
3768             ds[ 7 ] = 33;
3769             ds[ 8 ] = 13;
3770             ds[ 9 ] = 22;
3771             ds[ 10 ] = 21;
3772             ds[ 11 ] = 35;
3773             ds[ 12 ] = 24;
3774             ds[ 13 ] = 31;
3775             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3776             if ( bins.length != 4 ) {
3777                 return false;
3778             }
3779             if ( bins[ 0 ] != 2 ) {
3780                 return false;
3781             }
3782             if ( bins[ 1 ] != 3 ) {
3783                 return false;
3784             }
3785             if ( bins[ 2 ] != 4 ) {
3786                 return false;
3787             }
3788             if ( bins[ 3 ] != 5 ) {
3789                 return false;
3790             }
3791             final double[] ds1 = new double[ 9 ];
3792             ds1[ 0 ] = 10.0;
3793             ds1[ 1 ] = 19.0;
3794             ds1[ 2 ] = 9.999;
3795             ds1[ 3 ] = 0.0;
3796             ds1[ 4 ] = 39.9;
3797             ds1[ 5 ] = 39.999;
3798             ds1[ 6 ] = 30.0;
3799             ds1[ 7 ] = 19.999;
3800             ds1[ 8 ] = 30.1;
3801             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3802             if ( bins1.length != 4 ) {
3803                 return false;
3804             }
3805             if ( bins1[ 0 ] != 2 ) {
3806                 return false;
3807             }
3808             if ( bins1[ 1 ] != 3 ) {
3809                 return false;
3810             }
3811             if ( bins1[ 2 ] != 0 ) {
3812                 return false;
3813             }
3814             if ( bins1[ 3 ] != 4 ) {
3815                 return false;
3816             }
3817             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3818             if ( bins1_1.length != 3 ) {
3819                 return false;
3820             }
3821             if ( bins1_1[ 0 ] != 3 ) {
3822                 return false;
3823             }
3824             if ( bins1_1[ 1 ] != 2 ) {
3825                 return false;
3826             }
3827             if ( bins1_1[ 2 ] != 4 ) {
3828                 return false;
3829             }
3830             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3831             if ( bins1_2.length != 3 ) {
3832                 return false;
3833             }
3834             if ( bins1_2[ 0 ] != 2 ) {
3835                 return false;
3836             }
3837             if ( bins1_2[ 1 ] != 2 ) {
3838                 return false;
3839             }
3840             if ( bins1_2[ 2 ] != 2 ) {
3841                 return false;
3842             }
3843             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3844             dss3.addValue( 1 );
3845             dss3.addValue( 1 );
3846             dss3.addValue( 1 );
3847             dss3.addValue( 2 );
3848             dss3.addValue( 3 );
3849             dss3.addValue( 4 );
3850             dss3.addValue( 5 );
3851             dss3.addValue( 5 );
3852             dss3.addValue( 5 );
3853             dss3.addValue( 6 );
3854             dss3.addValue( 7 );
3855             dss3.addValue( 8 );
3856             dss3.addValue( 9 );
3857             dss3.addValue( 10 );
3858             dss3.addValue( 10 );
3859             dss3.addValue( 10 );
3860             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3861             histo.toStringBuffer( 10, '=', 40, 5 );
3862             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3863         }
3864         catch ( final Exception e ) {
3865             e.printStackTrace( System.out );
3866             return false;
3867         }
3868         return true;
3869     }
3870
3871     private static boolean testDir( final String file ) {
3872         try {
3873             final File f = new File( file );
3874             if ( !f.exists() ) {
3875                 return false;
3876             }
3877             if ( !f.isDirectory() ) {
3878                 return false;
3879             }
3880             if ( !f.canRead() ) {
3881                 return false;
3882             }
3883         }
3884         catch ( final Exception e ) {
3885             return false;
3886         }
3887         return true;
3888     }
3889
3890     private static boolean testEbiEntryRetrieval() {
3891         try {
3892             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3893             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3894                 System.out.println( entry.getAccession() );
3895                 return false;
3896             }
3897             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3898                 System.out.println( entry.getTaxonomyScientificName() );
3899                 return false;
3900             }
3901             if ( !entry.getSequenceName()
3902                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3903                 System.out.println( entry.getSequenceName() );
3904                 return false;
3905             }
3906             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3907             //     System.out.println( entry.getSequenceSymbol() );
3908             //     return false;
3909             // }
3910             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3911                 System.out.println( entry.getGeneName() );
3912                 return false;
3913             }
3914             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3915                 System.out.println( entry.getTaxonomyIdentifier() );
3916                 return false;
3917             }
3918             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3919                 System.out.println( entry.getAnnotations().first().getRefValue() );
3920                 return false;
3921             }
3922             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3923                 System.out.println( entry.getAnnotations().first().getRefSource() );
3924                 return false;
3925             }
3926             if ( entry.getCrossReferences().size() != 5 ) {
3927                 return false;
3928             }
3929             //
3930             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3931             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3932                 return false;
3933             }
3934             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3935                 System.out.println( entry1.getTaxonomyScientificName() );
3936                 return false;
3937             }
3938             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3939                 System.out.println( entry1.getSequenceName() );
3940                 return false;
3941             }
3942             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3943                 System.out.println( entry1.getTaxonomyIdentifier() );
3944                 return false;
3945             }
3946             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3947                 System.out.println( entry1.getGeneName() );
3948                 return false;
3949             }
3950             if ( entry1.getCrossReferences().size() != 6 ) {
3951                 return false;
3952             }
3953             //
3954             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3955             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3956                 return false;
3957             }
3958             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3959                 System.out.println( entry2.getTaxonomyScientificName() );
3960                 return false;
3961             }
3962             if ( !entry2.getSequenceName()
3963                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3964                 System.out.println( entry2.getSequenceName() );
3965                 return false;
3966             }
3967             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3968                 System.out.println( entry2.getTaxonomyIdentifier() );
3969                 return false;
3970             }
3971             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3972                 System.out.println( entry2.getGeneName() );
3973                 return false;
3974             }
3975             if ( entry2.getCrossReferences().size() != 3 ) {
3976                 return false;
3977             }
3978             //
3979             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3980             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3981                 return false;
3982             }
3983             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3984                 System.out.println( entry3.getTaxonomyScientificName() );
3985                 return false;
3986             }
3987             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3988                 System.out.println( entry3.getSequenceName() );
3989                 return false;
3990             }
3991             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3992                 System.out.println( entry3.getTaxonomyIdentifier() );
3993                 return false;
3994             }
3995             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3996                 System.out.println( entry3.getSequenceSymbol() );
3997                 return false;
3998             }
3999             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4000                 return false;
4001             }
4002             if ( entry3.getCrossReferences().size() != 8 ) {
4003                 return false;
4004             }
4005             //
4006             //
4007             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4008             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4009                 return false;
4010             }
4011             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4012                 System.out.println( entry4.getTaxonomyScientificName() );
4013                 return false;
4014             }
4015             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4016                 System.out.println( entry4.getSequenceName() );
4017                 return false;
4018             }
4019             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4020                 System.out.println( entry4.getTaxonomyIdentifier() );
4021                 return false;
4022             }
4023             if ( !entry4.getGeneName().equals( "ras" ) ) {
4024                 System.out.println( entry4.getGeneName() );
4025                 return false;
4026             }
4027             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4028             //     System.out.println( entry4.getChromosome() );
4029             //     return false;
4030             // }
4031             // if ( !entry4.getMap().equals( "ras" ) ) {
4032             //     System.out.println( entry4.getMap() );
4033             //     return false;
4034             // }
4035             //TODO FIXME gi...
4036             //
4037             //TODO fails:
4038             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4039             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4040             //                return false;
4041             //            }
4042             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4043             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4044                 return false;
4045             }
4046             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4047                 System.out.println( entry5.getTaxonomyScientificName() );
4048                 return false;
4049             }
4050             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4051                 System.out.println( entry5.getSequenceName() );
4052                 return false;
4053             }
4054             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4055                 System.out.println( entry5.getTaxonomyIdentifier() );
4056                 return false;
4057             }
4058         }
4059         catch ( final IOException e ) {
4060             System.out.println();
4061             System.out.println( "the following might be due to absence internet connection:" );
4062             e.printStackTrace( System.out );
4063             return true;
4064         }
4065         catch ( final Exception e ) {
4066             e.printStackTrace();
4067             return false;
4068         }
4069         return true;
4070     }
4071
4072     private static boolean testExternalNodeRelatedMethods() {
4073         try {
4074             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4075             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4076             PhylogenyNode n = t1.getNode( "A" );
4077             n = n.getNextExternalNode();
4078             if ( !n.getName().equals( "B" ) ) {
4079                 return false;
4080             }
4081             n = n.getNextExternalNode();
4082             if ( !n.getName().equals( "C" ) ) {
4083                 return false;
4084             }
4085             n = n.getNextExternalNode();
4086             if ( !n.getName().equals( "D" ) ) {
4087                 return false;
4088             }
4089             n = t1.getNode( "B" );
4090             while ( !n.isLastExternalNode() ) {
4091                 n = n.getNextExternalNode();
4092             }
4093             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4094             n = t2.getNode( "A" );
4095             n = n.getNextExternalNode();
4096             if ( !n.getName().equals( "B" ) ) {
4097                 return false;
4098             }
4099             n = n.getNextExternalNode();
4100             if ( !n.getName().equals( "C" ) ) {
4101                 return false;
4102             }
4103             n = n.getNextExternalNode();
4104             if ( !n.getName().equals( "D" ) ) {
4105                 return false;
4106             }
4107             n = t2.getNode( "B" );
4108             while ( !n.isLastExternalNode() ) {
4109                 n = n.getNextExternalNode();
4110             }
4111             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4112             n = t3.getNode( "A" );
4113             n = n.getNextExternalNode();
4114             if ( !n.getName().equals( "B" ) ) {
4115                 return false;
4116             }
4117             n = n.getNextExternalNode();
4118             if ( !n.getName().equals( "C" ) ) {
4119                 return false;
4120             }
4121             n = n.getNextExternalNode();
4122             if ( !n.getName().equals( "D" ) ) {
4123                 return false;
4124             }
4125             n = n.getNextExternalNode();
4126             if ( !n.getName().equals( "E" ) ) {
4127                 return false;
4128             }
4129             n = n.getNextExternalNode();
4130             if ( !n.getName().equals( "F" ) ) {
4131                 return false;
4132             }
4133             n = n.getNextExternalNode();
4134             if ( !n.getName().equals( "G" ) ) {
4135                 return false;
4136             }
4137             n = n.getNextExternalNode();
4138             if ( !n.getName().equals( "H" ) ) {
4139                 return false;
4140             }
4141             n = t3.getNode( "B" );
4142             while ( !n.isLastExternalNode() ) {
4143                 n = n.getNextExternalNode();
4144             }
4145             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4146             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4147                 final PhylogenyNode node = iter.next();
4148             }
4149             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4150             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4151                 final PhylogenyNode node = iter.next();
4152             }
4153             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4154             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4155             if ( !iter.next().getName().equals( "A" ) ) {
4156                 return false;
4157             }
4158             if ( !iter.next().getName().equals( "B" ) ) {
4159                 return false;
4160             }
4161             if ( !iter.next().getName().equals( "C" ) ) {
4162                 return false;
4163             }
4164             if ( !iter.next().getName().equals( "D" ) ) {
4165                 return false;
4166             }
4167             if ( !iter.next().getName().equals( "E" ) ) {
4168                 return false;
4169             }
4170             if ( !iter.next().getName().equals( "F" ) ) {
4171                 return false;
4172             }
4173             if ( iter.hasNext() ) {
4174                 return false;
4175             }
4176         }
4177         catch ( final Exception e ) {
4178             e.printStackTrace( System.out );
4179             return false;
4180         }
4181         return true;
4182     }
4183
4184     private static boolean testExtractSNFromNodeName() {
4185         try {
4186             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4187                 return false;
4188             }
4189             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4190                 return false;
4191             }
4192             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4193                 return false;
4194             }
4195             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4196                     .equals( "Mus musculus musculus" ) ) {
4197                 return false;
4198             }
4199             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4200                     .equals( "Mus musculus musculus" ) ) {
4201                 return false;
4202             }
4203             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4204                     .equals( "Mus musculus musculus" ) ) {
4205                 return false;
4206             }
4207             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4208                     .equals( "Mus musculus musculus" ) ) {
4209                 return false;
4210             }
4211             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4212                 return false;
4213             }
4214             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4215                     .equals( "Mus musculus musculus" ) ) {
4216                 return false;
4217             }
4218             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4219                     .equals( "Mus musculus musculus" ) ) {
4220                 return false;
4221             }
4222             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4223                 return false;
4224             }
4225             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4226                 return false;
4227             }
4228             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4229                 return false;
4230             }
4231             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4232                 return false;
4233             }
4234             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4235                     .equals( "Mus musculus musculus" ) ) {
4236                 return false;
4237             }
4238             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4239                 return false;
4240             }
4241             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4242                 return false;
4243             }
4244             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4245                 return false;
4246             }
4247             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4248                 return false;
4249             }
4250             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4251                 return false;
4252             }
4253             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4254                 return false;
4255             }
4256             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4257                 return false;
4258             }
4259             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4260                 return false;
4261             }
4262             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4263                     .equals( "Mus musculus" ) ) {
4264                 return false;
4265             }
4266             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4267                     .equals( "Mus musculus" ) ) {
4268                 return false;
4269             }
4270             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4271                 return false;
4272             }
4273             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4274                     .equals( "Mus musculus musculus" ) ) {
4275                 return false;
4276             }
4277             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4278                     .equals( "Mus musculus musculus" ) ) {
4279                 return false;
4280             }
4281             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4282                     .equals( "Mus musculus musculus" ) ) {
4283                 return false;
4284             }
4285             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4286                 return false;
4287             }
4288             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4289                     .equals( "Pilostyles mexicana" ) ) {
4290                 return false;
4291             }
4292             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4293                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4294                 return false;
4295             }
4296             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4297                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4298                 return false;
4299             }
4300             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4301                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4302                 return false;
4303             }
4304             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4305                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4309                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4313                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4314                 return false;
4315             }
4316             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4317                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4318                 return false;
4319             }
4320             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4321                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4322                 return false;
4323             }
4324             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4325                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4329                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4330                 return false;
4331             }
4332             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4333                     .equals( "Escherichia coli (strain K12)" ) ) {
4334                 return false;
4335             }
4336             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4337                     .equals( "Escherichia coli (strain K12)" ) ) {
4338                 return false;
4339             }
4340             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4341                     .equals( "Escherichia coli (str. K12)" ) ) {
4342                 return false;
4343             }
4344             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4345                     .equals( "Escherichia coli (str. K12)" ) ) {
4346                 return false;
4347             }
4348             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4349                     .equals( "Escherichia coli (str. K12)" ) ) {
4350                 return false;
4351             }
4352             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4353                     .equals( "Escherichia coli (var. K12)" ) ) {
4354                 return false;
4355             }
4356             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4357                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4361                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4362                 return false;
4363             }
4364             if ( !ParserUtils
4365                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4366                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4367                 return false;
4368             }
4369             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4370                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4371                 return false;
4372             }
4373             if ( !ParserUtils
4374                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4375                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4376                 return false;
4377             }
4378             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4379                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4380                 return false;
4381             }
4382             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4383                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4384                 return false;
4385             }
4386             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4390                 return false;
4391             }
4392             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4396                     .equals( "Macrocera sp." ) ) {
4397                 return false;
4398             }
4399             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4400                 return false;
4401             }
4402             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4403                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4404                 return false;
4405             }
4406             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4407                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4408                 return false;
4409             }
4410             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4411                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4412                 return false;
4413             }
4414             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4415                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4416                 return false;
4417             }
4418         }
4419         catch ( final Exception e ) {
4420             e.printStackTrace( System.out );
4421             return false;
4422         }
4423         return true;
4424     }
4425
4426     private static boolean testExtractTaxonomyCodeFromNodeName() {
4427         try {
4428             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4429                 return false;
4430             }
4431             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4432                     .equals( "SOYBN" ) ) {
4433                 return false;
4434             }
4435             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4436                     .equals( "ARATH" ) ) {
4437                 return false;
4438             }
4439             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4440                     .equals( "ARATH" ) ) {
4441                 return false;
4442             }
4443             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4444                 return false;
4445             }
4446             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4447                 return false;
4448             }
4449             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4450                 return false;
4451             }
4452             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4453                     .equals( "SOYBN" ) ) {
4454                 return false;
4455             }
4456             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4457                     .equals( "SOYBN" ) ) {
4458                 return false;
4459             }
4460             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4461                     .equals( "SOYBN" ) ) {
4462                 return false;
4463             }
4464             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4465                     .equals( "SOYBN" ) ) {
4466                 return false;
4467             }
4468             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4469                     .equals( "SOYBN" ) ) {
4470                 return false;
4471             }
4472             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4473                     .equals( "SOYBN" ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4477                     .equals( "SOYBN" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4481                     .equals( "SOYBN" ) ) {
4482                 return false;
4483             }
4484             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4485                 return false;
4486             }
4487             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4488                     .equals( "SOYBN" ) ) {
4489                 return false;
4490             }
4491             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4492                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4493                 return false;
4494             }
4495             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4496                     .equals( "9YX45" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4500                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4501                     .equals( "MOUSE" ) ) {
4502                 return false;
4503             }
4504             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4505                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4506                     .equals( "MOUSE" ) ) {
4507                 return false;
4508             }
4509             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4510                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4511                     .equals( "MOUSE" ) ) {
4512                 return false;
4513             }
4514             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4515                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4516                 return false;
4517             }
4518             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4519                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4520                 return false;
4521             }
4522             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4523                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4524                 return false;
4525             }
4526             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4527                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4528                 return false;
4529             }
4530             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4531                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4532                 return false;
4533             }
4534             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4535                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4536                 return false;
4537             }
4538             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4539                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4540                 return false;
4541             }
4542             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4543                     .equals( "RAT" ) ) {
4544                 return false;
4545             }
4546             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4547                     .equals( "PIG" ) ) {
4548                 return false;
4549             }
4550             if ( !ParserUtils
4551                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4552                     .equals( "MOUSE" ) ) {
4553                 return false;
4554             }
4555             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4556                     .equals( "MOUSE" ) ) {
4557                 return false;
4558             }
4559             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4560                 return false;
4561             }
4562         }
4563         catch ( final Exception e ) {
4564             e.printStackTrace( System.out );
4565             return false;
4566         }
4567         return true;
4568     }
4569
4570     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4571         try {
4572             PhylogenyNode n = new PhylogenyNode();
4573             n.setName( "tr|B3RJ64" );
4574             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4575                 return false;
4576             }
4577             n.setName( "tr.B3RJ64" );
4578             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4579                 return false;
4580             }
4581             n.setName( "tr=B3RJ64" );
4582             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4583                 return false;
4584             }
4585             n.setName( "tr-B3RJ64" );
4586             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4587                 return false;
4588             }
4589             n.setName( "tr/B3RJ64" );
4590             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4591                 return false;
4592             }
4593             n.setName( "tr\\B3RJ64" );
4594             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4595                 return false;
4596             }
4597             n.setName( "tr_B3RJ64" );
4598             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4599                 return false;
4600             }
4601             n.setName( " tr|B3RJ64 " );
4602             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4603                 return false;
4604             }
4605             n.setName( "-tr|B3RJ64-" );
4606             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4607                 return false;
4608             }
4609             n.setName( "-tr=B3RJ64-" );
4610             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4611                 return false;
4612             }
4613             n.setName( "_tr=B3RJ64_" );
4614             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4615                 return false;
4616             }
4617             n.setName( " tr_tr|B3RJ64_sp|123 " );
4618             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4619                 return false;
4620             }
4621             n.setName( "B3RJ64" );
4622             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4623                 return false;
4624             }
4625             n.setName( "sp|B3RJ64" );
4626             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4627                 return false;
4628             }
4629             n.setName( "sp|B3RJ64C" );
4630             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4631                 return false;
4632             }
4633             n.setName( "sp B3RJ64" );
4634             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4635                 return false;
4636             }
4637             n.setName( "sp|B3RJ6X" );
4638             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4639                 return false;
4640             }
4641             n.setName( "sp|B3RJ6" );
4642             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4643                 return false;
4644             }
4645             n.setName( "K1PYK7_CRAGI" );
4646             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4647                 return false;
4648             }
4649             n.setName( "K1PYK7_PEA" );
4650             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4651                 return false;
4652             }
4653             n.setName( "K1PYK7_RAT" );
4654             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4655                 return false;
4656             }
4657             n.setName( "K1PYK7_PIG" );
4658             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4659                 return false;
4660             }
4661             n.setName( "~K1PYK7_PIG~" );
4662             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4663                 return false;
4664             }
4665             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4666             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4667                 return false;
4668             }
4669             n.setName( "K1PYKX_CRAGI" );
4670             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4671                 return false;
4672             }
4673             n.setName( "XXXXX_CRAGI" );
4674             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4675                 return false;
4676             }
4677             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4678             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4679                 return false;
4680             }
4681             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4682             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4683                 return false;
4684             }
4685             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4686             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4687                 return false;
4688             }
4689             n = new PhylogenyNode();
4690             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4691             seq.setSymbol( "K1PYK7_CRAGI" );
4692             n.getNodeData().addSequence( seq );
4693             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4694                 return false;
4695             }
4696             seq.setSymbol( "tr|B3RJ64" );
4697             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4698                 return false;
4699             }
4700             n = new PhylogenyNode();
4701             seq = new org.forester.phylogeny.data.Sequence();
4702             seq.setName( "K1PYK7_CRAGI" );
4703             n.getNodeData().addSequence( seq );
4704             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4705                 return false;
4706             }
4707             seq.setName( "tr|B3RJ64" );
4708             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4709                 return false;
4710             }
4711             n = new PhylogenyNode();
4712             seq = new org.forester.phylogeny.data.Sequence();
4713             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4714             n.getNodeData().addSequence( seq );
4715             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4716                 return false;
4717             }
4718             n = new PhylogenyNode();
4719             seq = new org.forester.phylogeny.data.Sequence();
4720             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4721             n.getNodeData().addSequence( seq );
4722             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4723                 return false;
4724             }
4725             //
4726             n = new PhylogenyNode();
4727             n.setName( "ACP19736" );
4728             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4729                 return false;
4730             }
4731             n = new PhylogenyNode();
4732             n.setName( "|ACP19736|" );
4733             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4734                 return false;
4735             }
4736         }
4737         catch ( final Exception e ) {
4738             e.printStackTrace( System.out );
4739             return false;
4740         }
4741         return true;
4742     }
4743
4744     private static boolean testFastaParser() {
4745         try {
4746             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4747                 return false;
4748             }
4749             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4750                 return false;
4751             }
4752             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4753             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4754                 return false;
4755             }
4756             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4757                 return false;
4758             }
4759             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4760                 return false;
4761             }
4762             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4763                 return false;
4764             }
4765             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4766                 return false;
4767             }
4768             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4769                 return false;
4770             }
4771         }
4772         catch ( final Exception e ) {
4773             e.printStackTrace();
4774             return false;
4775         }
4776         return true;
4777     }
4778
4779     private static boolean testGenbankAccessorParsing() {
4780         //The format for GenBank Accession numbers are:
4781         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4782         //Protein:    3 letters + 5 numerals
4783         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4784         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4785             return false;
4786         }
4787         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4788             return false;
4789         }
4790         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4791             return false;
4792         }
4793         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4794             return false;
4795         }
4796         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4797             return false;
4798         }
4799         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4800             return false;
4801         }
4802         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4803             return false;
4804         }
4805         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4806             return false;
4807         }
4808         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4809             return false;
4810         }
4811         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4812             return false;
4813         }
4814         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4815             return false;
4816         }
4817         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4818             return false;
4819         }
4820         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4821             return false;
4822         }
4823         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4824             return false;
4825         }
4826         return true;
4827     }
4828
4829     private static boolean testGeneralMsaParser() {
4830         try {
4831             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4832             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4833             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4834             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4835             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4836             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4837             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4838             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4839             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4840                 return false;
4841             }
4842             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4843                 return false;
4844             }
4845             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4846                 return false;
4847             }
4848             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4849                 return false;
4850             }
4851             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4852                 return false;
4853             }
4854             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4855                 return false;
4856             }
4857             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4858                 return false;
4859             }
4860             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4861                 return false;
4862             }
4863             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4864                 return false;
4865             }
4866             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4867                 return false;
4868             }
4869             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4870                 return false;
4871             }
4872             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4873                 return false;
4874             }
4875             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4876             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4877                 return false;
4878             }
4879             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4880                 return false;
4881             }
4882             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4883                 return false;
4884             }
4885             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4886             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4887                 return false;
4888             }
4889             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4890                 return false;
4891             }
4892             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4893                 return false;
4894             }
4895             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4896             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4897                 return false;
4898             }
4899             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4900                 return false;
4901             }
4902             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4903                 return false;
4904             }
4905         }
4906         catch ( final Exception e ) {
4907             e.printStackTrace();
4908             return false;
4909         }
4910         return true;
4911     }
4912
4913     private static boolean testGeneralTable() {
4914         try {
4915             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4916             t0.setValue( 3, 2, "23" );
4917             t0.setValue( 10, 1, "error" );
4918             t0.setValue( 10, 1, "110" );
4919             t0.setValue( 9, 1, "19" );
4920             t0.setValue( 1, 10, "101" );
4921             t0.setValue( 10, 10, "1010" );
4922             t0.setValue( 100, 10, "10100" );
4923             t0.setValue( 0, 0, "00" );
4924             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4925                 return false;
4926             }
4927             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4928                 return false;
4929             }
4930             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4931                 return false;
4932             }
4933             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4934                 return false;
4935             }
4936             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4937                 return false;
4938             }
4939             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4940                 return false;
4941             }
4942             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4943                 return false;
4944             }
4945             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4946                 return false;
4947             }
4948             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4949                 return false;
4950             }
4951             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4952             t1.setValue( "3", "2", "23" );
4953             t1.setValue( "10", "1", "error" );
4954             t1.setValue( "10", "1", "110" );
4955             t1.setValue( "9", "1", "19" );
4956             t1.setValue( "1", "10", "101" );
4957             t1.setValue( "10", "10", "1010" );
4958             t1.setValue( "100", "10", "10100" );
4959             t1.setValue( "0", "0", "00" );
4960             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4961             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4962                 return false;
4963             }
4964             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4965                 return false;
4966             }
4967             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4968                 return false;
4969             }
4970             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4971                 return false;
4972             }
4973             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4974                 return false;
4975             }
4976             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4977                 return false;
4978             }
4979             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4980                 return false;
4981             }
4982             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4983                 return false;
4984             }
4985             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4986                 return false;
4987             }
4988             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4989                 return false;
4990             }
4991         }
4992         catch ( final Exception e ) {
4993             e.printStackTrace( System.out );
4994             return false;
4995         }
4996         return true;
4997     }
4998
4999     private static boolean testGetDistance() {
5000         try {
5001             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5002             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",
5003                                                  new NHXParser() )[ 0 ];
5004             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5005                 return false;
5006             }
5007             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5008                 return false;
5009             }
5010             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5011                 return false;
5012             }
5013             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5014                 return false;
5015             }
5016             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5017                 return false;
5018             }
5019             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5020                 return false;
5021             }
5022             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5023                 return false;
5024             }
5025             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5026                 return false;
5027             }
5028             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5029                 return false;
5030             }
5031             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5032                 return false;
5033             }
5034             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5035                 return false;
5036             }
5037             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5038                 return false;
5039             }
5040             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5041                 return false;
5042             }
5043             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5044                 return false;
5045             }
5046             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5047                 return false;
5048             }
5049             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5050                 return false;
5051             }
5052             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5053                 return false;
5054             }
5055             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5056                 return false;
5057             }
5058             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5059                 return false;
5060             }
5061             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5062                 return false;
5063             }
5064             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5065                 return false;
5066             }
5067             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5068                 return false;
5069             }
5070             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5071                 return false;
5072             }
5073             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5074                 return false;
5075             }
5076             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5077                 return false;
5078             }
5079             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5080                 return false;
5081             }
5082             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5083                 return false;
5084             }
5085             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5086                 return false;
5087             }
5088             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5089                 return false;
5090             }
5091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5095                 return false;
5096             }
5097             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",
5098                                                  new NHXParser() )[ 0 ];
5099             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5100                 return false;
5101             }
5102             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5103                 return false;
5104             }
5105             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5106                 return false;
5107             }
5108             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5109                 return false;
5110             }
5111             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5112                 return false;
5113             }
5114             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5115                 return false;
5116             }
5117             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5118                 return false;
5119             }
5120             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5121                 return false;
5122             }
5123             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5124                 return false;
5125             }
5126             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5127                 return false;
5128             }
5129             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5130                 return false;
5131             }
5132         }
5133         catch ( final Exception e ) {
5134             e.printStackTrace( System.out );
5135             return false;
5136         }
5137         return true;
5138     }
5139
5140     private static boolean testGetLCA() {
5141         try {
5142             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5143             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5144                                                  new NHXParser() )[ 0 ];
5145             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5146             if ( !A.getName().equals( "A" ) ) {
5147                 return false;
5148             }
5149             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5150             if ( !gh.getName().equals( "gh" ) ) {
5151                 return false;
5152             }
5153             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5154             if ( !ab.getName().equals( "ab" ) ) {
5155                 return false;
5156             }
5157             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5158             if ( !ab2.getName().equals( "ab" ) ) {
5159                 return false;
5160             }
5161             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5162             if ( !gh2.getName().equals( "gh" ) ) {
5163                 return false;
5164             }
5165             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5166             if ( !gh3.getName().equals( "gh" ) ) {
5167                 return false;
5168             }
5169             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5170             if ( !abc.getName().equals( "abc" ) ) {
5171                 return false;
5172             }
5173             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5174             if ( !abc2.getName().equals( "abc" ) ) {
5175                 return false;
5176             }
5177             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5178             if ( !abcd.getName().equals( "abcd" ) ) {
5179                 return false;
5180             }
5181             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5182             if ( !abcd2.getName().equals( "abcd" ) ) {
5183                 return false;
5184             }
5185             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5186             if ( !abcdef.getName().equals( "abcdef" ) ) {
5187                 return false;
5188             }
5189             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5190             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5191                 return false;
5192             }
5193             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5194             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5195                 return false;
5196             }
5197             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5198             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5199                 return false;
5200             }
5201             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5202             if ( !abcde.getName().equals( "abcde" ) ) {
5203                 return false;
5204             }
5205             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5206             if ( !abcde2.getName().equals( "abcde" ) ) {
5207                 return false;
5208             }
5209             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5210             if ( !r.getName().equals( "abcdefgh" ) ) {
5211                 return false;
5212             }
5213             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5214             if ( !r2.getName().equals( "abcdefgh" ) ) {
5215                 return false;
5216             }
5217             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5218             if ( !r3.getName().equals( "abcdefgh" ) ) {
5219                 return false;
5220             }
5221             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5222             if ( !abcde3.getName().equals( "abcde" ) ) {
5223                 return false;
5224             }
5225             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5226             if ( !abcde4.getName().equals( "abcde" ) ) {
5227                 return false;
5228             }
5229             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5230             if ( !ab3.getName().equals( "ab" ) ) {
5231                 return false;
5232             }
5233             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5234             if ( !ab4.getName().equals( "ab" ) ) {
5235                 return false;
5236             }
5237             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5238             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5239             if ( !cd.getName().equals( "cd" ) ) {
5240                 return false;
5241             }
5242             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5243             if ( !cd2.getName().equals( "cd" ) ) {
5244                 return false;
5245             }
5246             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5247             if ( !cde.getName().equals( "cde" ) ) {
5248                 return false;
5249             }
5250             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5251             if ( !cde2.getName().equals( "cde" ) ) {
5252                 return false;
5253             }
5254             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5255             if ( !cdef.getName().equals( "cdef" ) ) {
5256                 return false;
5257             }
5258             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5259             if ( !cdef2.getName().equals( "cdef" ) ) {
5260                 return false;
5261             }
5262             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5263             if ( !cdef3.getName().equals( "cdef" ) ) {
5264                 return false;
5265             }
5266             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5267             if ( !rt.getName().equals( "r" ) ) {
5268                 return false;
5269             }
5270             final Phylogeny p3 = factory
5271                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5272                              new NHXParser() )[ 0 ];
5273             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5274             if ( !bc_3.getName().equals( "bc" ) ) {
5275                 return false;
5276             }
5277             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5278             if ( !ac_3.getName().equals( "abc" ) ) {
5279                 return false;
5280             }
5281             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5282             if ( !ad_3.getName().equals( "abcde" ) ) {
5283                 return false;
5284             }
5285             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5286             if ( !af_3.getName().equals( "abcdef" ) ) {
5287                 return false;
5288             }
5289             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5290             if ( !ag_3.getName().equals( "" ) ) {
5291                 return false;
5292             }
5293             if ( !ag_3.isRoot() ) {
5294                 return false;
5295             }
5296             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5297             if ( !al_3.getName().equals( "" ) ) {
5298                 return false;
5299             }
5300             if ( !al_3.isRoot() ) {
5301                 return false;
5302             }
5303             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5304             if ( !kl_3.getName().equals( "" ) ) {
5305                 return false;
5306             }
5307             if ( !kl_3.isRoot() ) {
5308                 return false;
5309             }
5310             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5311             if ( !fl_3.getName().equals( "" ) ) {
5312                 return false;
5313             }
5314             if ( !fl_3.isRoot() ) {
5315                 return false;
5316             }
5317             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5318             if ( !gk_3.getName().equals( "ghijk" ) ) {
5319                 return false;
5320             }
5321             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5322             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5323             if ( !r_4.getName().equals( "r" ) ) {
5324                 return false;
5325             }
5326             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5327             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5328             if ( !r_5.getName().equals( "root" ) ) {
5329                 return false;
5330             }
5331             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5332             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5333             if ( !r_6.getName().equals( "rot" ) ) {
5334                 return false;
5335             }
5336             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5337             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5338             if ( !r_7.getName().equals( "rott" ) ) {
5339                 return false;
5340             }
5341         }
5342         catch ( final Exception e ) {
5343             e.printStackTrace( System.out );
5344             return false;
5345         }
5346         return true;
5347     }
5348
5349     private static boolean testGetLCA2() {
5350         try {
5351             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5352             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5353             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5354             PhylogenyMethods.preOrderReId( p_a );
5355             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5356                                                                                               p_a.getNode( "a" ) );
5357             if ( !p_a_1.getName().equals( "a" ) ) {
5358                 return false;
5359             }
5360             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5361             PhylogenyMethods.preOrderReId( p_b );
5362             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5363                                                                                               p_b.getNode( "a" ) );
5364             if ( !p_b_1.getName().equals( "b" ) ) {
5365                 return false;
5366             }
5367             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5368                                                                                               p_b.getNode( "b" ) );
5369             if ( !p_b_2.getName().equals( "b" ) ) {
5370                 return false;
5371             }
5372             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5373             PhylogenyMethods.preOrderReId( p_c );
5374             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5375                                                                                               p_c.getNode( "a" ) );
5376             if ( !p_c_1.getName().equals( "b" ) ) {
5377                 return false;
5378             }
5379             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5380                                                                                               p_c.getNode( "c" ) );
5381             if ( !p_c_2.getName().equals( "c" ) ) {
5382                 System.out.println( p_c_2.getName() );
5383                 System.exit( -1 );
5384                 return false;
5385             }
5386             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5387                                                                                               p_c.getNode( "b" ) );
5388             if ( !p_c_3.getName().equals( "b" ) ) {
5389                 return false;
5390             }
5391             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5392                                                                                               p_c.getNode( "a" ) );
5393             if ( !p_c_4.getName().equals( "c" ) ) {
5394                 return false;
5395             }
5396             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5397                                                  new NHXParser() )[ 0 ];
5398             PhylogenyMethods.preOrderReId( p1 );
5399             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5400                                                                                           p1.getNode( "A" ) );
5401             if ( !A.getName().equals( "A" ) ) {
5402                 return false;
5403             }
5404             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5405                                                                                            p1.getNode( "gh" ) );
5406             if ( !gh.getName().equals( "gh" ) ) {
5407                 return false;
5408             }
5409             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5410                                                                                            p1.getNode( "B" ) );
5411             if ( !ab.getName().equals( "ab" ) ) {
5412                 return false;
5413             }
5414             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5415                                                                                             p1.getNode( "A" ) );
5416             if ( !ab2.getName().equals( "ab" ) ) {
5417                 return false;
5418             }
5419             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5420                                                                                             p1.getNode( "G" ) );
5421             if ( !gh2.getName().equals( "gh" ) ) {
5422                 return false;
5423             }
5424             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5425                                                                                             p1.getNode( "H" ) );
5426             if ( !gh3.getName().equals( "gh" ) ) {
5427                 return false;
5428             }
5429             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5430                                                                                             p1.getNode( "A" ) );
5431             if ( !abc.getName().equals( "abc" ) ) {
5432                 return false;
5433             }
5434             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5435                                                                                              p1.getNode( "C" ) );
5436             if ( !abc2.getName().equals( "abc" ) ) {
5437                 return false;
5438             }
5439             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5440                                                                                              p1.getNode( "D" ) );
5441             if ( !abcd.getName().equals( "abcd" ) ) {
5442                 return false;
5443             }
5444             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5445                                                                                               p1.getNode( "A" ) );
5446             if ( !abcd2.getName().equals( "abcd" ) ) {
5447                 return false;
5448             }
5449             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5450                                                                                                p1.getNode( "F" ) );
5451             if ( !abcdef.getName().equals( "abcdef" ) ) {
5452                 return false;
5453             }
5454             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5455                                                                                                 p1.getNode( "A" ) );
5456             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5457                 return false;
5458             }
5459             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5460                                                                                                 p1.getNode( "F" ) );
5461             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5462                 return false;
5463             }
5464             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5465                                                                                                 p1.getNode( "ab" ) );
5466             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5467                 return false;
5468             }
5469             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5470                                                                                               p1.getNode( "E" ) );
5471             if ( !abcde.getName().equals( "abcde" ) ) {
5472                 return false;
5473             }
5474             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5475                                                                                                p1.getNode( "A" ) );
5476             if ( !abcde2.getName().equals( "abcde" ) ) {
5477                 return false;
5478             }
5479             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5480                                                                                           p1.getNode( "abcdefgh" ) );
5481             if ( !r.getName().equals( "abcdefgh" ) ) {
5482                 return false;
5483             }
5484             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5485                                                                                            p1.getNode( "H" ) );
5486             if ( !r2.getName().equals( "abcdefgh" ) ) {
5487                 return false;
5488             }
5489             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5490                                                                                            p1.getNode( "A" ) );
5491             if ( !r3.getName().equals( "abcdefgh" ) ) {
5492                 return false;
5493             }
5494             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5495                                                                                                p1.getNode( "abcde" ) );
5496             if ( !abcde3.getName().equals( "abcde" ) ) {
5497                 return false;
5498             }
5499             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5500                                                                                                p1.getNode( "E" ) );
5501             if ( !abcde4.getName().equals( "abcde" ) ) {
5502                 return false;
5503             }
5504             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5505                                                                                             p1.getNode( "B" ) );
5506             if ( !ab3.getName().equals( "ab" ) ) {
5507                 return false;
5508             }
5509             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5510                                                                                             p1.getNode( "ab" ) );
5511             if ( !ab4.getName().equals( "ab" ) ) {
5512                 return false;
5513             }
5514             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5515             PhylogenyMethods.preOrderReId( p2 );
5516             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5517                                                                                            p2.getNode( "d" ) );
5518             if ( !cd.getName().equals( "cd" ) ) {
5519                 return false;
5520             }
5521             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5522                                                                                             p2.getNode( "c" ) );
5523             if ( !cd2.getName().equals( "cd" ) ) {
5524                 return false;
5525             }
5526             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5527                                                                                             p2.getNode( "e" ) );
5528             if ( !cde.getName().equals( "cde" ) ) {
5529                 return false;
5530             }
5531             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5532                                                                                              p2.getNode( "c" ) );
5533             if ( !cde2.getName().equals( "cde" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5537                                                                                              p2.getNode( "f" ) );
5538             if ( !cdef.getName().equals( "cdef" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5542                                                                                               p2.getNode( "f" ) );
5543             if ( !cdef2.getName().equals( "cdef" ) ) {
5544                 return false;
5545             }
5546             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5547                                                                                               p2.getNode( "d" ) );
5548             if ( !cdef3.getName().equals( "cdef" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5552                                                                                            p2.getNode( "a" ) );
5553             if ( !rt.getName().equals( "r" ) ) {
5554                 return false;
5555             }
5556             final Phylogeny p3 = factory
5557                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5558                              new NHXParser() )[ 0 ];
5559             PhylogenyMethods.preOrderReId( p3 );
5560             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5561                                                                                              p3.getNode( "c" ) );
5562             if ( !bc_3.getName().equals( "bc" ) ) {
5563                 return false;
5564             }
5565             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5566                                                                                              p3.getNode( "c" ) );
5567             if ( !ac_3.getName().equals( "abc" ) ) {
5568                 return false;
5569             }
5570             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5571                                                                                              p3.getNode( "d" ) );
5572             if ( !ad_3.getName().equals( "abcde" ) ) {
5573                 return false;
5574             }
5575             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5576                                                                                              p3.getNode( "f" ) );
5577             if ( !af_3.getName().equals( "abcdef" ) ) {
5578                 return false;
5579             }
5580             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5581                                                                                              p3.getNode( "g" ) );
5582             if ( !ag_3.getName().equals( "" ) ) {
5583                 return false;
5584             }
5585             if ( !ag_3.isRoot() ) {
5586                 return false;
5587             }
5588             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5589                                                                                              p3.getNode( "l" ) );
5590             if ( !al_3.getName().equals( "" ) ) {
5591                 return false;
5592             }
5593             if ( !al_3.isRoot() ) {
5594                 return false;
5595             }
5596             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5597                                                                                              p3.getNode( "l" ) );
5598             if ( !kl_3.getName().equals( "" ) ) {
5599                 return false;
5600             }
5601             if ( !kl_3.isRoot() ) {
5602                 return false;
5603             }
5604             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5605                                                                                              p3.getNode( "l" ) );
5606             if ( !fl_3.getName().equals( "" ) ) {
5607                 return false;
5608             }
5609             if ( !fl_3.isRoot() ) {
5610                 return false;
5611             }
5612             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5613                                                                                              p3.getNode( "k" ) );
5614             if ( !gk_3.getName().equals( "ghijk" ) ) {
5615                 return false;
5616             }
5617             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5618             PhylogenyMethods.preOrderReId( p4 );
5619             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5620                                                                                             p4.getNode( "c" ) );
5621             if ( !r_4.getName().equals( "r" ) ) {
5622                 return false;
5623             }
5624             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5625             PhylogenyMethods.preOrderReId( p5 );
5626             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5627                                                                                             p5.getNode( "c" ) );
5628             if ( !r_5.getName().equals( "root" ) ) {
5629                 return false;
5630             }
5631             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5632             PhylogenyMethods.preOrderReId( p6 );
5633             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5634                                                                                             p6.getNode( "a" ) );
5635             if ( !r_6.getName().equals( "rot" ) ) {
5636                 return false;
5637             }
5638             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5639             PhylogenyMethods.preOrderReId( p7 );
5640             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5641                                                                                             p7.getNode( "e" ) );
5642             if ( !r_7.getName().equals( "rott" ) ) {
5643                 return false;
5644             }
5645             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5646                                                                                              p7.getNode( "a" ) );
5647             if ( !r_71.getName().equals( "rott" ) ) {
5648                 return false;
5649             }
5650             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5651                                                                                              p7.getNode( "rott" ) );
5652             if ( !r_72.getName().equals( "rott" ) ) {
5653                 return false;
5654             }
5655             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5656                                                                                              p7.getNode( "a" ) );
5657             if ( !r_73.getName().equals( "rott" ) ) {
5658                 return false;
5659             }
5660             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5661                                                                                              p7.getNode( "rott" ) );
5662             if ( !r_74.getName().equals( "rott" ) ) {
5663                 return false;
5664             }
5665             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5666                                                                                              p7.getNode( "e" ) );
5667             if ( !r_75.getName().equals( "e" ) ) {
5668                 return false;
5669             }
5670         }
5671         catch ( final Exception e ) {
5672             e.printStackTrace( System.out );
5673             return false;
5674         }
5675         return true;
5676     }
5677
5678     private static boolean testHmmscanOutputParser() {
5679         final String test_dir = Test.PATH_TO_TEST_DATA;
5680         try {
5681             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5682                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5683             parser1.parse();
5684             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5685                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5686             final List<Protein> proteins = parser2.parse();
5687             if ( parser2.getProteinsEncountered() != 4 ) {
5688                 return false;
5689             }
5690             if ( proteins.size() != 4 ) {
5691                 return false;
5692             }
5693             if ( parser2.getDomainsEncountered() != 69 ) {
5694                 return false;
5695             }
5696             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5697                 return false;
5698             }
5699             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5700                 return false;
5701             }
5702             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5703                 return false;
5704             }
5705             final Protein p1 = proteins.get( 0 );
5706             if ( p1.getNumberOfProteinDomains() != 15 ) {
5707                 return false;
5708             }
5709             if ( p1.getLength() != 850 ) {
5710                 return false;
5711             }
5712             final Protein p2 = proteins.get( 1 );
5713             if ( p2.getNumberOfProteinDomains() != 51 ) {
5714                 return false;
5715             }
5716             if ( p2.getLength() != 1291 ) {
5717                 return false;
5718             }
5719             final Protein p3 = proteins.get( 2 );
5720             if ( p3.getNumberOfProteinDomains() != 2 ) {
5721                 return false;
5722             }
5723             final Protein p4 = proteins.get( 3 );
5724             if ( p4.getNumberOfProteinDomains() != 1 ) {
5725                 return false;
5726             }
5727             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5728                 return false;
5729             }
5730             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5731                 return false;
5732             }
5733             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5734                 return false;
5735             }
5736             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5737                 return false;
5738             }
5739             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5740                 return false;
5741             }
5742             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5743                 return false;
5744             }
5745             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5746                 return false;
5747             }
5748         }
5749         catch ( final Exception e ) {
5750             e.printStackTrace( System.out );
5751             return false;
5752         }
5753         return true;
5754     }
5755
5756     private static boolean testLastExternalNodeMethods() {
5757         try {
5758             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5759             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5760             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5761             final PhylogenyNode n1 = t0.getNode( "A" );
5762             if ( n1.isLastExternalNode() ) {
5763                 return false;
5764             }
5765             final PhylogenyNode n2 = t0.getNode( "B" );
5766             if ( n2.isLastExternalNode() ) {
5767                 return false;
5768             }
5769             final PhylogenyNode n3 = t0.getNode( "C" );
5770             if ( n3.isLastExternalNode() ) {
5771                 return false;
5772             }
5773             final PhylogenyNode n4 = t0.getNode( "D" );
5774             if ( !n4.isLastExternalNode() ) {
5775                 return false;
5776             }
5777         }
5778         catch ( final Exception e ) {
5779             e.printStackTrace( System.out );
5780             return false;
5781         }
5782         return true;
5783     }
5784
5785     private static boolean testLevelOrderIterator() {
5786         try {
5787             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5788             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5789             PhylogenyNodeIterator it0;
5790             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5791                 it0.next();
5792             }
5793             for( it0.reset(); it0.hasNext(); ) {
5794                 it0.next();
5795             }
5796             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5797             if ( !it.next().getName().equals( "r" ) ) {
5798                 return false;
5799             }
5800             if ( !it.next().getName().equals( "ab" ) ) {
5801                 return false;
5802             }
5803             if ( !it.next().getName().equals( "cd" ) ) {
5804                 return false;
5805             }
5806             if ( !it.next().getName().equals( "A" ) ) {
5807                 return false;
5808             }
5809             if ( !it.next().getName().equals( "B" ) ) {
5810                 return false;
5811             }
5812             if ( !it.next().getName().equals( "C" ) ) {
5813                 return false;
5814             }
5815             if ( !it.next().getName().equals( "D" ) ) {
5816                 return false;
5817             }
5818             if ( it.hasNext() ) {
5819                 return false;
5820             }
5821             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",
5822                                                  new NHXParser() )[ 0 ];
5823             PhylogenyNodeIterator it2;
5824             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5825                 it2.next();
5826             }
5827             for( it2.reset(); it2.hasNext(); ) {
5828                 it2.next();
5829             }
5830             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5831             if ( !it3.next().getName().equals( "r" ) ) {
5832                 return false;
5833             }
5834             if ( !it3.next().getName().equals( "abc" ) ) {
5835                 return false;
5836             }
5837             if ( !it3.next().getName().equals( "defg" ) ) {
5838                 return false;
5839             }
5840             if ( !it3.next().getName().equals( "A" ) ) {
5841                 return false;
5842             }
5843             if ( !it3.next().getName().equals( "B" ) ) {
5844                 return false;
5845             }
5846             if ( !it3.next().getName().equals( "C" ) ) {
5847                 return false;
5848             }
5849             if ( !it3.next().getName().equals( "D" ) ) {
5850                 return false;
5851             }
5852             if ( !it3.next().getName().equals( "E" ) ) {
5853                 return false;
5854             }
5855             if ( !it3.next().getName().equals( "F" ) ) {
5856                 return false;
5857             }
5858             if ( !it3.next().getName().equals( "G" ) ) {
5859                 return false;
5860             }
5861             if ( !it3.next().getName().equals( "1" ) ) {
5862                 return false;
5863             }
5864             if ( !it3.next().getName().equals( "2" ) ) {
5865                 return false;
5866             }
5867             if ( !it3.next().getName().equals( "3" ) ) {
5868                 return false;
5869             }
5870             if ( !it3.next().getName().equals( "4" ) ) {
5871                 return false;
5872             }
5873             if ( !it3.next().getName().equals( "5" ) ) {
5874                 return false;
5875             }
5876             if ( !it3.next().getName().equals( "6" ) ) {
5877                 return false;
5878             }
5879             if ( !it3.next().getName().equals( "f1" ) ) {
5880                 return false;
5881             }
5882             if ( !it3.next().getName().equals( "f2" ) ) {
5883                 return false;
5884             }
5885             if ( !it3.next().getName().equals( "f3" ) ) {
5886                 return false;
5887             }
5888             if ( !it3.next().getName().equals( "a" ) ) {
5889                 return false;
5890             }
5891             if ( !it3.next().getName().equals( "b" ) ) {
5892                 return false;
5893             }
5894             if ( !it3.next().getName().equals( "f21" ) ) {
5895                 return false;
5896             }
5897             if ( !it3.next().getName().equals( "X" ) ) {
5898                 return false;
5899             }
5900             if ( !it3.next().getName().equals( "Y" ) ) {
5901                 return false;
5902             }
5903             if ( !it3.next().getName().equals( "Z" ) ) {
5904                 return false;
5905             }
5906             if ( it3.hasNext() ) {
5907                 return false;
5908             }
5909             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5910             PhylogenyNodeIterator it4;
5911             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5912                 it4.next();
5913             }
5914             for( it4.reset(); it4.hasNext(); ) {
5915                 it4.next();
5916             }
5917             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5918             if ( !it5.next().getName().equals( "r" ) ) {
5919                 return false;
5920             }
5921             if ( !it5.next().getName().equals( "A" ) ) {
5922                 return false;
5923             }
5924             if ( !it5.next().getName().equals( "B" ) ) {
5925                 return false;
5926             }
5927             if ( !it5.next().getName().equals( "C" ) ) {
5928                 return false;
5929             }
5930             if ( !it5.next().getName().equals( "D" ) ) {
5931                 return false;
5932             }
5933             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5934             PhylogenyNodeIterator it6;
5935             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5936                 it6.next();
5937             }
5938             for( it6.reset(); it6.hasNext(); ) {
5939                 it6.next();
5940             }
5941             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5942             if ( !it7.next().getName().equals( "A" ) ) {
5943                 return false;
5944             }
5945             if ( it.hasNext() ) {
5946                 return false;
5947             }
5948         }
5949         catch ( final Exception e ) {
5950             e.printStackTrace( System.out );
5951             return false;
5952         }
5953         return true;
5954     }
5955
5956     private static boolean testMafft( final String path ) {
5957         try {
5958             final List<String> opts = new ArrayList<String>();
5959             opts.add( "--maxiterate" );
5960             opts.add( "1000" );
5961             opts.add( "--localpair" );
5962             opts.add( "--quiet" );
5963             Msa msa = null;
5964             final MsaInferrer mafft = Mafft.createInstance( path );
5965             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5966             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5967                 return false;
5968             }
5969             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5970                 return false;
5971             }
5972         }
5973         catch ( final Exception e ) {
5974             e.printStackTrace( System.out );
5975             return false;
5976         }
5977         return true;
5978     }
5979
5980     private static boolean testMidpointrooting() {
5981         try {
5982             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5983             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5984             PhylogenyMethods.midpointRoot( t0 );
5985             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5986                 return false;
5987             }
5988             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5989                 return false;
5990             }
5991             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5992                            1 ) ) {
5993                 return false;
5994             }
5995             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",
5996                                                  new NHXParser() )[ 0 ];
5997             if ( !t1.isRooted() ) {
5998                 return false;
5999             }
6000             PhylogenyMethods.midpointRoot( t1 );
6001             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6002                 return false;
6003             }
6004             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6005                 return false;
6006             }
6007             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6008                 return false;
6009             }
6010             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6011                 return false;
6012             }
6013             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6014                 return false;
6015             }
6016             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6017                 return false;
6018             }
6019             t1.reRoot( t1.getNode( "A" ) );
6020             PhylogenyMethods.midpointRoot( t1 );
6021             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6022                 return false;
6023             }
6024             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6025                 return false;
6026             }
6027             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6028                 return false;
6029             }
6030             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6031                 return false;
6032             }
6033             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6034                 System.exit( -1 );
6035                 return false;
6036             }
6037             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6038                 return false;
6039             }
6040         }
6041         catch ( final Exception e ) {
6042             e.printStackTrace( System.out );
6043             return false;
6044         }
6045         return true;
6046     }
6047
6048     private static boolean testMsaQualityMethod() {
6049         try {
6050             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6051             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6052             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6053             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6054             final List<Sequence> l = new ArrayList<Sequence>();
6055             l.add( s0 );
6056             l.add( s1 );
6057             l.add( s2 );
6058             l.add( s3 );
6059             final Msa msa = BasicMsa.createInstance( l );
6060             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6061                 return false;
6062             }
6063             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6064                 return false;
6065             }
6066             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6067                 return false;
6068             }
6069             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6070                 return false;
6071             }
6072             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6073                 return false;
6074             }
6075             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6076                 return false;
6077             }
6078             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6079                 return false;
6080             }
6081         }
6082         catch ( final Exception e ) {
6083             e.printStackTrace( System.out );
6084             return false;
6085         }
6086         return true;
6087     }
6088     
6089     private static boolean testDeleteableMsa() {
6090         try {
6091             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6092             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6093             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6094             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6095             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6096             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6097             final List<Sequence> l0 = new ArrayList<Sequence>();
6098             l0.add( s0 );
6099             l0.add( s1 );
6100             l0.add( s2 );
6101             l0.add( s3 );
6102             l0.add( s4 );
6103             l0.add( s5 );
6104             final Msa msa0 = BasicMsa.createInstance( l0 );
6105             final DeleteableMsa dmsa0 = new DeleteableMsa( ( BasicMsa ) msa0 );
6106             dmsa0.deleteRow( "b" );
6107             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6108                 return false;
6109             }
6110             System.out.println();
6111             System.out.println(  dmsa0.toString() );
6112             dmsa0.deleteRow( "e" );
6113             System.out.println();
6114             System.out.println(  dmsa0.toString() );
6115             dmsa0.deleteRow( "a" );
6116             System.out.println();
6117             System.out.println(  dmsa0.toString() );
6118             dmsa0.deleteRow( "f" );
6119             System.out.println();
6120             System.out.println(  dmsa0.toString() );
6121             
6122             if ( dmsa0.getLength() != 4 ) {
6123                 return false;
6124             }
6125             if ( dmsa0.getNumberOfSequences() != 2 ) {
6126                 return false;
6127             }
6128             
6129             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6130                 return false;
6131             }
6132             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6133                 return false;
6134             }
6135             if ( dmsa0.getResidueAt( 0, 0 )  != 'C') {
6136                 return false;
6137             }
6138             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" )) {
6139                 return false;
6140             }
6141             if ( dmsa0.getColumnAt( 0 ).size() !=2 ) {
6142                 return false;
6143             }
6144             dmsa0.deleteRow( "c" );
6145             dmsa0.deleteRow( "d" );
6146             if ( dmsa0.getNumberOfSequences() != 0 ) {
6147                 return false;
6148             }
6149             //
6150             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---A-A---" );
6151             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----A---" );
6152             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AA-A---" );
6153             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-A---" );
6154             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-A---" );
6155             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AA-AA--" );
6156             final List<Sequence> l1 = new ArrayList<Sequence>();
6157             l1.add( s_0 );
6158             l1.add( s_1 );
6159             l1.add( s_2 );
6160             l1.add( s_3 );
6161             l1.add( s_4 );
6162             l1.add( s_5 );
6163             final Msa msa1 = BasicMsa.createInstance( l1 );
6164             final DeleteableMsa dmsa1 = new DeleteableMsa( ( BasicMsa ) msa1 );
6165             System.out.println(  dmsa1.toString() );
6166             MsaMethods.removeGapColumns( 1, dmsa1 );
6167             System.out.println(  dmsa1.toString() );
6168             
6169         }
6170         catch ( final Exception e ) {
6171             e.printStackTrace( System.out );
6172             return false;
6173         }
6174         return true;
6175     }
6176
6177     private static boolean testNextNodeWithCollapsing() {
6178         try {
6179             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6180             PhylogenyNode n;
6181             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6182             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6183             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6184             t0.getNode( "cd" ).setCollapse( true );
6185             t0.getNode( "cde" ).setCollapse( true );
6186             n = t0.getFirstExternalNode();
6187             while ( n != null ) {
6188                 ext.add( n );
6189                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6190             }
6191             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6192                 return false;
6193             }
6194             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6195                 return false;
6196             }
6197             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6198                 return false;
6199             }
6200             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6201                 return false;
6202             }
6203             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6204                 return false;
6205             }
6206             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6207                 return false;
6208             }
6209             ext.clear();
6210             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6211             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6212             t1.getNode( "ab" ).setCollapse( true );
6213             t1.getNode( "cd" ).setCollapse( true );
6214             t1.getNode( "cde" ).setCollapse( true );
6215             n = t1.getNode( "ab" );
6216             ext = new ArrayList<PhylogenyNode>();
6217             while ( n != null ) {
6218                 ext.add( n );
6219                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6220             }
6221             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6222                 return false;
6223             }
6224             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6225                 return false;
6226             }
6227             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6228                 return false;
6229             }
6230             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6231                 return false;
6232             }
6233             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6234                 return false;
6235             }
6236             //
6237             //
6238             ext.clear();
6239             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6240             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6241             t2.getNode( "ab" ).setCollapse( true );
6242             t2.getNode( "cd" ).setCollapse( true );
6243             t2.getNode( "cde" ).setCollapse( true );
6244             t2.getNode( "c" ).setCollapse( true );
6245             t2.getNode( "d" ).setCollapse( true );
6246             t2.getNode( "e" ).setCollapse( true );
6247             t2.getNode( "gh" ).setCollapse( true );
6248             n = t2.getNode( "ab" );
6249             ext = new ArrayList<PhylogenyNode>();
6250             while ( n != null ) {
6251                 ext.add( n );
6252                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6253             }
6254             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6255                 return false;
6256             }
6257             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6258                 return false;
6259             }
6260             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6261                 return false;
6262             }
6263             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6264                 return false;
6265             }
6266             //
6267             //
6268             ext.clear();
6269             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6270             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6271             t3.getNode( "ab" ).setCollapse( true );
6272             t3.getNode( "cd" ).setCollapse( true );
6273             t3.getNode( "cde" ).setCollapse( true );
6274             t3.getNode( "c" ).setCollapse( true );
6275             t3.getNode( "d" ).setCollapse( true );
6276             t3.getNode( "e" ).setCollapse( true );
6277             t3.getNode( "gh" ).setCollapse( true );
6278             t3.getNode( "fgh" ).setCollapse( true );
6279             n = t3.getNode( "ab" );
6280             ext = new ArrayList<PhylogenyNode>();
6281             while ( n != null ) {
6282                 ext.add( n );
6283                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6284             }
6285             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6286                 return false;
6287             }
6288             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6289                 return false;
6290             }
6291             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6292                 return false;
6293             }
6294             //
6295             //
6296             ext.clear();
6297             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6298             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6299             t4.getNode( "ab" ).setCollapse( true );
6300             t4.getNode( "cd" ).setCollapse( true );
6301             t4.getNode( "cde" ).setCollapse( true );
6302             t4.getNode( "c" ).setCollapse( true );
6303             t4.getNode( "d" ).setCollapse( true );
6304             t4.getNode( "e" ).setCollapse( true );
6305             t4.getNode( "gh" ).setCollapse( true );
6306             t4.getNode( "fgh" ).setCollapse( true );
6307             t4.getNode( "abcdefgh" ).setCollapse( true );
6308             n = t4.getNode( "abcdefgh" );
6309             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6310                 return false;
6311             }
6312             //
6313             //
6314             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6315             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6316             ext.clear();
6317             n = t5.getFirstExternalNode();
6318             while ( n != null ) {
6319                 ext.add( n );
6320                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6321             }
6322             if ( ext.size() != 8 ) {
6323                 return false;
6324             }
6325             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6326                 return false;
6327             }
6328             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6329                 return false;
6330             }
6331             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6332                 return false;
6333             }
6334             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6335                 return false;
6336             }
6337             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6338                 return false;
6339             }
6340             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6341                 return false;
6342             }
6343             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6344                 return false;
6345             }
6346             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6347                 return false;
6348             }
6349             //
6350             //
6351             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6352             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6353             ext.clear();
6354             t6.getNode( "ab" ).setCollapse( true );
6355             n = t6.getNode( "ab" );
6356             while ( n != null ) {
6357                 ext.add( n );
6358                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6359             }
6360             if ( ext.size() != 7 ) {
6361                 return false;
6362             }
6363             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6364                 return false;
6365             }
6366             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6367                 return false;
6368             }
6369             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6370                 return false;
6371             }
6372             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6373                 return false;
6374             }
6375             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6376                 return false;
6377             }
6378             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6379                 return false;
6380             }
6381             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6382                 return false;
6383             }
6384             //
6385             //
6386             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6387             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6388             ext.clear();
6389             t7.getNode( "cd" ).setCollapse( true );
6390             n = t7.getNode( "a" );
6391             while ( n != null ) {
6392                 ext.add( n );
6393                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6394             }
6395             if ( ext.size() != 7 ) {
6396                 return false;
6397             }
6398             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6399                 return false;
6400             }
6401             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6402                 return false;
6403             }
6404             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6405                 return false;
6406             }
6407             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6408                 return false;
6409             }
6410             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6411                 return false;
6412             }
6413             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6414                 return false;
6415             }
6416             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6417                 return false;
6418             }
6419             //
6420             //
6421             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6422             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6423             ext.clear();
6424             t8.getNode( "cd" ).setCollapse( true );
6425             t8.getNode( "c" ).setCollapse( true );
6426             t8.getNode( "d" ).setCollapse( true );
6427             n = t8.getNode( "a" );
6428             while ( n != null ) {
6429                 ext.add( n );
6430                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6431             }
6432             if ( ext.size() != 7 ) {
6433                 return false;
6434             }
6435             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6436                 return false;
6437             }
6438             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6439                 return false;
6440             }
6441             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6442                 System.out.println( "2 fail" );
6443                 return false;
6444             }
6445             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6446                 return false;
6447             }
6448             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6449                 return false;
6450             }
6451             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6452                 return false;
6453             }
6454             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6455                 return false;
6456             }
6457             //
6458             //
6459             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6460             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6461             ext.clear();
6462             t9.getNode( "gh" ).setCollapse( true );
6463             n = t9.getNode( "a" );
6464             while ( n != null ) {
6465                 ext.add( n );
6466                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6467             }
6468             if ( ext.size() != 7 ) {
6469                 return false;
6470             }
6471             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6472                 return false;
6473             }
6474             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6475                 return false;
6476             }
6477             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6478                 return false;
6479             }
6480             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6481                 return false;
6482             }
6483             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6490                 return false;
6491             }
6492             //
6493             //
6494             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6495             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6496             ext.clear();
6497             t10.getNode( "gh" ).setCollapse( true );
6498             t10.getNode( "g" ).setCollapse( true );
6499             t10.getNode( "h" ).setCollapse( true );
6500             n = t10.getNode( "a" );
6501             while ( n != null ) {
6502                 ext.add( n );
6503                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6504             }
6505             if ( ext.size() != 7 ) {
6506                 return false;
6507             }
6508             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6509                 return false;
6510             }
6511             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6512                 return false;
6513             }
6514             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6515                 return false;
6516             }
6517             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6518                 return false;
6519             }
6520             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6521                 return false;
6522             }
6523             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6524                 return false;
6525             }
6526             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6527                 return false;
6528             }
6529             //
6530             //
6531             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6532             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6533             ext.clear();
6534             t11.getNode( "gh" ).setCollapse( true );
6535             t11.getNode( "fgh" ).setCollapse( true );
6536             n = t11.getNode( "a" );
6537             while ( n != null ) {
6538                 ext.add( n );
6539                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6540             }
6541             if ( ext.size() != 6 ) {
6542                 return false;
6543             }
6544             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6545                 return false;
6546             }
6547             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6548                 return false;
6549             }
6550             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6551                 return false;
6552             }
6553             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6554                 return false;
6555             }
6556             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6557                 return false;
6558             }
6559             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6560                 return false;
6561             }
6562             //
6563             //
6564             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6565             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6566             ext.clear();
6567             t12.getNode( "gh" ).setCollapse( true );
6568             t12.getNode( "fgh" ).setCollapse( true );
6569             t12.getNode( "g" ).setCollapse( true );
6570             t12.getNode( "h" ).setCollapse( true );
6571             t12.getNode( "f" ).setCollapse( true );
6572             n = t12.getNode( "a" );
6573             while ( n != null ) {
6574                 ext.add( n );
6575                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6576             }
6577             if ( ext.size() != 6 ) {
6578                 return false;
6579             }
6580             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6581                 return false;
6582             }
6583             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6584                 return false;
6585             }
6586             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6587                 return false;
6588             }
6589             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6590                 return false;
6591             }
6592             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6593                 return false;
6594             }
6595             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6596                 return false;
6597             }
6598             //
6599             //
6600             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6601             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6602             ext.clear();
6603             t13.getNode( "ab" ).setCollapse( true );
6604             t13.getNode( "b" ).setCollapse( true );
6605             t13.getNode( "fgh" ).setCollapse( true );
6606             t13.getNode( "gh" ).setCollapse( true );
6607             n = t13.getNode( "ab" );
6608             while ( n != null ) {
6609                 ext.add( n );
6610                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6611             }
6612             if ( ext.size() != 5 ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6628                 return false;
6629             }
6630             //
6631             //
6632             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6633             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6634             ext.clear();
6635             t14.getNode( "ab" ).setCollapse( true );
6636             t14.getNode( "a" ).setCollapse( true );
6637             t14.getNode( "fgh" ).setCollapse( true );
6638             t14.getNode( "gh" ).setCollapse( true );
6639             n = t14.getNode( "ab" );
6640             while ( n != null ) {
6641                 ext.add( n );
6642                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6643             }
6644             if ( ext.size() != 5 ) {
6645                 return false;
6646             }
6647             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6648                 return false;
6649             }
6650             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6651                 return false;
6652             }
6653             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6654                 return false;
6655             }
6656             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6657                 return false;
6658             }
6659             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6660                 return false;
6661             }
6662             //
6663             //
6664             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" );
6665             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6666             ext.clear();
6667             t15.getNode( "ab" ).setCollapse( true );
6668             t15.getNode( "a" ).setCollapse( true );
6669             t15.getNode( "fgh" ).setCollapse( true );
6670             t15.getNode( "gh" ).setCollapse( true );
6671             n = t15.getNode( "ab" );
6672             while ( n != null ) {
6673                 ext.add( n );
6674                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6675             }
6676             if ( ext.size() != 6 ) {
6677                 return false;
6678             }
6679             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6680                 return false;
6681             }
6682             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6683                 return false;
6684             }
6685             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6686                 return false;
6687             }
6688             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6689                 return false;
6690             }
6691             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6692                 return false;
6693             }
6694             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6695                 return false;
6696             }
6697             //
6698             //
6699             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" );
6700             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6701             ext.clear();
6702             t16.getNode( "ab" ).setCollapse( true );
6703             t16.getNode( "a" ).setCollapse( true );
6704             t16.getNode( "fgh" ).setCollapse( true );
6705             t16.getNode( "gh" ).setCollapse( true );
6706             t16.getNode( "cd" ).setCollapse( true );
6707             t16.getNode( "cde" ).setCollapse( true );
6708             t16.getNode( "d" ).setCollapse( true );
6709             t16.getNode( "x" ).setCollapse( true );
6710             n = t16.getNode( "ab" );
6711             while ( n != null ) {
6712                 ext.add( n );
6713                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6714             }
6715             if ( ext.size() != 4 ) {
6716                 return false;
6717             }
6718             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6719                 return false;
6720             }
6721             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6722                 return false;
6723             }
6724             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6728                 return false;
6729             }
6730         }
6731         catch ( final Exception e ) {
6732             e.printStackTrace( System.out );
6733             return false;
6734         }
6735         return true;
6736     }
6737
6738     private static boolean testNexusCharactersParsing() {
6739         try {
6740             final NexusCharactersParser parser = new NexusCharactersParser();
6741             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6742             parser.parse();
6743             String[] labels = parser.getCharStateLabels();
6744             if ( labels.length != 7 ) {
6745                 return false;
6746             }
6747             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6748                 return false;
6749             }
6750             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6751                 return false;
6752             }
6753             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6754                 return false;
6755             }
6756             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6757                 return false;
6758             }
6759             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6760                 return false;
6761             }
6762             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6763                 return false;
6764             }
6765             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6766                 return false;
6767             }
6768             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6769             parser.parse();
6770             labels = parser.getCharStateLabels();
6771             if ( labels.length != 7 ) {
6772                 return false;
6773             }
6774             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6775                 return false;
6776             }
6777             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6778                 return false;
6779             }
6780             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6781                 return false;
6782             }
6783             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6784                 return false;
6785             }
6786             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6787                 return false;
6788             }
6789             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6790                 return false;
6791             }
6792             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6793                 return false;
6794             }
6795         }
6796         catch ( final Exception e ) {
6797             e.printStackTrace( System.out );
6798             return false;
6799         }
6800         return true;
6801     }
6802
6803     private static boolean testNexusMatrixParsing() {
6804         try {
6805             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6806             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6807             parser.parse();
6808             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6809             if ( m.getNumberOfCharacters() != 9 ) {
6810                 return false;
6811             }
6812             if ( m.getNumberOfIdentifiers() != 5 ) {
6813                 return false;
6814             }
6815             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6816                 return false;
6817             }
6818             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6819                 return false;
6820             }
6821             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6822                 return false;
6823             }
6824             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6825                 return false;
6826             }
6827             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6828                 return false;
6829             }
6830             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6831                 return false;
6832             }
6833             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6834                 return false;
6835             }
6836             //            if ( labels.length != 7 ) {
6837             //                return false;
6838             //            }
6839             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6840             //                return false;
6841             //            }
6842             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6843             //                return false;
6844             //            }
6845             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6846             //                return false;
6847             //            }
6848             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6849             //                return false;
6850             //            }
6851             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6852             //                return false;
6853             //            }
6854             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6855             //                return false;
6856             //            }
6857             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6858             //                return false;
6859             //            }
6860             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6861             //            parser.parse();
6862             //            labels = parser.getCharStateLabels();
6863             //            if ( labels.length != 7 ) {
6864             //                return false;
6865             //            }
6866             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6867             //                return false;
6868             //            }
6869             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6870             //                return false;
6871             //            }
6872             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6873             //                return false;
6874             //            }
6875             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6876             //                return false;
6877             //            }
6878             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6879             //                return false;
6880             //            }
6881             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6882             //                return false;
6883             //            }
6884             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6885             //                return false;
6886             //            }
6887         }
6888         catch ( final Exception e ) {
6889             e.printStackTrace( System.out );
6890             return false;
6891         }
6892         return true;
6893     }
6894
6895     private static boolean testNexusTreeParsing() {
6896         try {
6897             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6898             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6899             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6900             if ( phylogenies.length != 1 ) {
6901                 return false;
6902             }
6903             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6904                 return false;
6905             }
6906             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6907                 return false;
6908             }
6909             phylogenies = null;
6910             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6911             if ( phylogenies.length != 1 ) {
6912                 return false;
6913             }
6914             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6915                 return false;
6916             }
6917             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6918                 return false;
6919             }
6920             phylogenies = null;
6921             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6922             if ( phylogenies.length != 1 ) {
6923                 return false;
6924             }
6925             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6926                 return false;
6927             }
6928             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6929                 return false;
6930             }
6931             if ( phylogenies[ 0 ].isRooted() ) {
6932                 return false;
6933             }
6934             phylogenies = null;
6935             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6936             if ( phylogenies.length != 18 ) {
6937                 return false;
6938             }
6939             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6940                 return false;
6941             }
6942             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6943                 return false;
6944             }
6945             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6946                 return false;
6947             }
6948             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6949                 return false;
6950             }
6951             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6952                 return false;
6953             }
6954             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6955                 return false;
6956             }
6957             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6958                 return false;
6959             }
6960             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6961                 return false;
6962             }
6963             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6964                 return false;
6965             }
6966             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6967                 return false;
6968             }
6969             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6970                 return false;
6971             }
6972             if ( phylogenies[ 8 ].isRooted() ) {
6973                 return false;
6974             }
6975             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6976                 return false;
6977             }
6978             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6979                 return false;
6980             }
6981             if ( !phylogenies[ 9 ].isRooted() ) {
6982                 return false;
6983             }
6984             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6985                 return false;
6986             }
6987             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6988                 return false;
6989             }
6990             if ( !phylogenies[ 10 ].isRooted() ) {
6991                 return false;
6992             }
6993             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6994                 return false;
6995             }
6996             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6997                 return false;
6998             }
6999             if ( phylogenies[ 11 ].isRooted() ) {
7000                 return false;
7001             }
7002             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7003                 return false;
7004             }
7005             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7006                 return false;
7007             }
7008             if ( !phylogenies[ 12 ].isRooted() ) {
7009                 return false;
7010             }
7011             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7012                 return false;
7013             }
7014             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7015                 return false;
7016             }
7017             if ( !phylogenies[ 13 ].isRooted() ) {
7018                 return false;
7019             }
7020             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7021                 return false;
7022             }
7023             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7024                 return false;
7025             }
7026             if ( !phylogenies[ 14 ].isRooted() ) {
7027                 return false;
7028             }
7029             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7030                 return false;
7031             }
7032             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7033                 return false;
7034             }
7035             if ( phylogenies[ 15 ].isRooted() ) {
7036                 return false;
7037             }
7038             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7039                 return false;
7040             }
7041             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7042                 return false;
7043             }
7044             if ( !phylogenies[ 16 ].isRooted() ) {
7045                 return false;
7046             }
7047             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7048                 return false;
7049             }
7050             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7051                 return false;
7052             }
7053             if ( phylogenies[ 17 ].isRooted() ) {
7054                 return false;
7055             }
7056             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7057                 return false;
7058             }
7059             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7060             phylogenies = null;
7061             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7062             if ( phylogenies.length != 9 ) {
7063                 return false;
7064             }
7065             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7066                     .getDistanceToParent() ) ) {
7067                 return false;
7068             }
7069             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7070                     .getDistanceToParent() ) ) {
7071                 return false;
7072             }
7073             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7074                 return false;
7075             }
7076             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7077                 return false;
7078             }
7079             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7080                 return false;
7081             }
7082             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7083                 return false;
7084             }
7085             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7086                 return false;
7087             }
7088         }
7089         catch ( final Exception e ) {
7090             e.printStackTrace( System.out );
7091             return false;
7092         }
7093         return true;
7094     }
7095
7096     private static boolean testNexusTreeParsingIterating() {
7097         try {
7098             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7099             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7100             if ( !p.hasNext() ) {
7101                 return false;
7102             }
7103             Phylogeny phy = p.next();
7104             if ( phy == null ) {
7105                 return false;
7106             }
7107             if ( phy.getNumberOfExternalNodes() != 25 ) {
7108                 return false;
7109             }
7110             if ( !phy.getName().equals( "" ) ) {
7111                 return false;
7112             }
7113             if ( p.hasNext() ) {
7114                 return false;
7115             }
7116             phy = p.next();
7117             if ( phy != null ) {
7118                 return false;
7119             }
7120             //
7121             p.reset();
7122             if ( !p.hasNext() ) {
7123                 return false;
7124             }
7125             phy = p.next();
7126             if ( phy == null ) {
7127                 return false;
7128             }
7129             if ( phy.getNumberOfExternalNodes() != 25 ) {
7130                 return false;
7131             }
7132             if ( !phy.getName().equals( "" ) ) {
7133                 return false;
7134             }
7135             if ( p.hasNext() ) {
7136                 return false;
7137             }
7138             phy = p.next();
7139             if ( phy != null ) {
7140                 return false;
7141             }
7142             ////
7143             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7144             if ( !p.hasNext() ) {
7145                 return false;
7146             }
7147             phy = p.next();
7148             if ( phy == null ) {
7149                 return false;
7150             }
7151             if ( phy.getNumberOfExternalNodes() != 10 ) {
7152                 return false;
7153             }
7154             if ( !phy.getName().equals( "name" ) ) {
7155                 return false;
7156             }
7157             if ( p.hasNext() ) {
7158                 return false;
7159             }
7160             phy = p.next();
7161             if ( phy != null ) {
7162                 return false;
7163             }
7164             //
7165             p.reset();
7166             if ( !p.hasNext() ) {
7167                 return false;
7168             }
7169             phy = p.next();
7170             if ( phy == null ) {
7171                 return false;
7172             }
7173             if ( phy.getNumberOfExternalNodes() != 10 ) {
7174                 return false;
7175             }
7176             if ( !phy.getName().equals( "name" ) ) {
7177                 return false;
7178             }
7179             if ( p.hasNext() ) {
7180                 return false;
7181             }
7182             phy = p.next();
7183             if ( phy != null ) {
7184                 return false;
7185             }
7186             //
7187             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7188             if ( !p.hasNext() ) {
7189                 return false;
7190             }
7191             phy = p.next();
7192             if ( phy == null ) {
7193                 return false;
7194             }
7195             if ( phy.getNumberOfExternalNodes() != 3 ) {
7196                 return false;
7197             }
7198             if ( !phy.getName().equals( "" ) ) {
7199                 return false;
7200             }
7201             if ( phy.isRooted() ) {
7202                 return false;
7203             }
7204             if ( p.hasNext() ) {
7205                 return false;
7206             }
7207             phy = p.next();
7208             if ( phy != null ) {
7209                 return false;
7210             }
7211             //
7212             p.reset();
7213             if ( !p.hasNext() ) {
7214                 return false;
7215             }
7216             phy = p.next();
7217             if ( phy == null ) {
7218                 return false;
7219             }
7220             if ( phy.getNumberOfExternalNodes() != 3 ) {
7221                 return false;
7222             }
7223             if ( !phy.getName().equals( "" ) ) {
7224                 return false;
7225             }
7226             if ( p.hasNext() ) {
7227                 return false;
7228             }
7229             phy = p.next();
7230             if ( phy != null ) {
7231                 return false;
7232             }
7233             //
7234             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7235             if ( !p.hasNext() ) {
7236                 return false;
7237             }
7238             //0
7239             phy = p.next();
7240             if ( phy == null ) {
7241                 return false;
7242             }
7243             if ( phy.getNumberOfExternalNodes() != 10 ) {
7244                 return false;
7245             }
7246             if ( !phy.getName().equals( "tree 0" ) ) {
7247                 return false;
7248             }
7249             //1
7250             if ( !p.hasNext() ) {
7251                 return false;
7252             }
7253             phy = p.next();
7254             if ( phy == null ) {
7255                 return false;
7256             }
7257             if ( phy.getNumberOfExternalNodes() != 10 ) {
7258                 return false;
7259             }
7260             if ( !phy.getName().equals( "tree 1" ) ) {
7261                 return false;
7262             }
7263             //2
7264             if ( !p.hasNext() ) {
7265                 return false;
7266             }
7267             phy = p.next();
7268             if ( phy == null ) {
7269                 return false;
7270             }
7271             if ( phy.getNumberOfExternalNodes() != 3 ) {
7272                 System.out.println( phy.toString() );
7273                 return false;
7274             }
7275             if ( !phy.getName().equals( "" ) ) {
7276                 return false;
7277             }
7278             if ( phy.isRooted() ) {
7279                 return false;
7280             }
7281             //3
7282             if ( !p.hasNext() ) {
7283                 return false;
7284             }
7285             phy = p.next();
7286             if ( phy == null ) {
7287                 return false;
7288             }
7289             if ( phy.getNumberOfExternalNodes() != 4 ) {
7290                 return false;
7291             }
7292             if ( !phy.getName().equals( "" ) ) {
7293                 return false;
7294             }
7295             if ( !phy.isRooted() ) {
7296                 return false;
7297             }
7298             //4
7299             if ( !p.hasNext() ) {
7300                 return false;
7301             }
7302             phy = p.next();
7303             if ( phy == null ) {
7304                 return false;
7305             }
7306             if ( phy.getNumberOfExternalNodes() != 5 ) {
7307                 System.out.println( phy.getNumberOfExternalNodes() );
7308                 return false;
7309             }
7310             if ( !phy.getName().equals( "" ) ) {
7311                 return false;
7312             }
7313             if ( !phy.isRooted() ) {
7314                 return false;
7315             }
7316             //5
7317             if ( !p.hasNext() ) {
7318                 return false;
7319             }
7320             phy = p.next();
7321             if ( phy == null ) {
7322                 return false;
7323             }
7324             if ( phy.getNumberOfExternalNodes() != 3 ) {
7325                 return false;
7326             }
7327             if ( !phy.getName().equals( "" ) ) {
7328                 return false;
7329             }
7330             if ( phy.isRooted() ) {
7331                 return false;
7332             }
7333             //6
7334             if ( !p.hasNext() ) {
7335                 return false;
7336             }
7337             phy = p.next();
7338             if ( phy == null ) {
7339                 return false;
7340             }
7341             if ( phy.getNumberOfExternalNodes() != 2 ) {
7342                 return false;
7343             }
7344             if ( !phy.getName().equals( "" ) ) {
7345                 return false;
7346             }
7347             if ( !phy.isRooted() ) {
7348                 return false;
7349             }
7350             //7
7351             if ( !p.hasNext() ) {
7352                 return false;
7353             }
7354             phy = p.next();
7355             if ( phy.getNumberOfExternalNodes() != 3 ) {
7356                 return false;
7357             }
7358             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7359                 return false;
7360             }
7361             if ( !phy.isRooted() ) {
7362                 return false;
7363             }
7364             //8
7365             if ( !p.hasNext() ) {
7366                 return false;
7367             }
7368             phy = p.next();
7369             if ( phy.getNumberOfExternalNodes() != 3 ) {
7370                 return false;
7371             }
7372             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7373                 return false;
7374             }
7375             if ( !phy.getName().equals( "tree 8" ) ) {
7376                 return false;
7377             }
7378             //9
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             phy = p.next();
7383             if ( phy.getNumberOfExternalNodes() != 3 ) {
7384                 return false;
7385             }
7386             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7387                 return false;
7388             }
7389             if ( !phy.getName().equals( "tree 9" ) ) {
7390                 return false;
7391             }
7392             //10
7393             if ( !p.hasNext() ) {
7394                 return false;
7395             }
7396             phy = p.next();
7397             if ( phy.getNumberOfExternalNodes() != 3 ) {
7398                 return false;
7399             }
7400             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7401                 return false;
7402             }
7403             if ( !phy.getName().equals( "tree 10" ) ) {
7404                 return false;
7405             }
7406             if ( !phy.isRooted() ) {
7407                 return false;
7408             }
7409             //11
7410             if ( !p.hasNext() ) {
7411                 return false;
7412             }
7413             phy = p.next();
7414             if ( phy.getNumberOfExternalNodes() != 3 ) {
7415                 return false;
7416             }
7417             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7418                 return false;
7419             }
7420             if ( !phy.getName().equals( "tree 11" ) ) {
7421                 return false;
7422             }
7423             if ( phy.isRooted() ) {
7424                 return false;
7425             }
7426             //12
7427             if ( !p.hasNext() ) {
7428                 return false;
7429             }
7430             phy = p.next();
7431             if ( phy.getNumberOfExternalNodes() != 3 ) {
7432                 return false;
7433             }
7434             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7435                 return false;
7436             }
7437             if ( !phy.getName().equals( "tree 12" ) ) {
7438                 return false;
7439             }
7440             if ( !phy.isRooted() ) {
7441                 return false;
7442             }
7443             //13
7444             if ( !p.hasNext() ) {
7445                 return false;
7446             }
7447             phy = p.next();
7448             if ( phy.getNumberOfExternalNodes() != 3 ) {
7449                 return false;
7450             }
7451             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7452                 return false;
7453             }
7454             if ( !phy.getName().equals( "tree 13" ) ) {
7455                 return false;
7456             }
7457             if ( !phy.isRooted() ) {
7458                 return false;
7459             }
7460             //14
7461             if ( !p.hasNext() ) {
7462                 return false;
7463             }
7464             phy = p.next();
7465             if ( phy.getNumberOfExternalNodes() != 10 ) {
7466                 System.out.println( phy.getNumberOfExternalNodes() );
7467                 return false;
7468             }
7469             if ( !phy
7470                     .toNewHampshire()
7471                     .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;" ) ) {
7472                 System.out.println( phy.toNewHampshire() );
7473                 return false;
7474             }
7475             if ( !phy.getName().equals( "tree 14" ) ) {
7476                 return false;
7477             }
7478             if ( !phy.isRooted() ) {
7479                 return false;
7480             }
7481             //15
7482             if ( !p.hasNext() ) {
7483                 return false;
7484             }
7485             phy = p.next();
7486             if ( phy.getNumberOfExternalNodes() != 10 ) {
7487                 System.out.println( phy.getNumberOfExternalNodes() );
7488                 return false;
7489             }
7490             if ( !phy
7491                     .toNewHampshire()
7492                     .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;" ) ) {
7493                 System.out.println( phy.toNewHampshire() );
7494                 return false;
7495             }
7496             if ( !phy.getName().equals( "tree 15" ) ) {
7497                 return false;
7498             }
7499             if ( phy.isRooted() ) {
7500                 return false;
7501             }
7502             //16
7503             if ( !p.hasNext() ) {
7504                 return false;
7505             }
7506             phy = p.next();
7507             if ( phy.getNumberOfExternalNodes() != 10 ) {
7508                 System.out.println( phy.getNumberOfExternalNodes() );
7509                 return false;
7510             }
7511             if ( !phy
7512                     .toNewHampshire()
7513                     .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;" ) ) {
7514                 System.out.println( phy.toNewHampshire() );
7515                 return false;
7516             }
7517             if ( !phy.getName().equals( "tree 16" ) ) {
7518                 return false;
7519             }
7520             if ( !phy.isRooted() ) {
7521                 return false;
7522             }
7523             //17
7524             if ( !p.hasNext() ) {
7525                 return false;
7526             }
7527             phy = p.next();
7528             if ( phy.getNumberOfExternalNodes() != 10 ) {
7529                 System.out.println( phy.getNumberOfExternalNodes() );
7530                 return false;
7531             }
7532             if ( !phy
7533                     .toNewHampshire()
7534                     .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;" ) ) {
7535                 System.out.println( phy.toNewHampshire() );
7536                 return false;
7537             }
7538             if ( !phy.getName().equals( "tree 17" ) ) {
7539                 return false;
7540             }
7541             if ( phy.isRooted() ) {
7542                 return false;
7543             }
7544             //
7545             if ( p.hasNext() ) {
7546                 return false;
7547             }
7548             phy = p.next();
7549             if ( phy != null ) {
7550                 return false;
7551             }
7552             p.reset();
7553             //0
7554             if ( !p.hasNext() ) {
7555                 return false;
7556             }
7557             phy = p.next();
7558             if ( phy == null ) {
7559                 return false;
7560             }
7561             if ( phy.getNumberOfExternalNodes() != 10 ) {
7562                 return false;
7563             }
7564             if ( !phy.getName().equals( "tree 0" ) ) {
7565                 return false;
7566             }
7567             //1
7568             if ( !p.hasNext() ) {
7569                 return false;
7570             }
7571             phy = p.next();
7572             if ( phy == null ) {
7573                 return false;
7574             }
7575             if ( phy.getNumberOfExternalNodes() != 10 ) {
7576                 return false;
7577             }
7578             if ( !phy.getName().equals( "tree 1" ) ) {
7579                 return false;
7580             }
7581             //2
7582             if ( !p.hasNext() ) {
7583                 return false;
7584             }
7585             phy = p.next();
7586             if ( phy == null ) {
7587                 return false;
7588             }
7589             if ( phy.getNumberOfExternalNodes() != 3 ) {
7590                 return false;
7591             }
7592             if ( !phy.getName().equals( "" ) ) {
7593                 return false;
7594             }
7595             if ( phy.isRooted() ) {
7596                 return false;
7597             }
7598             //3
7599             if ( !p.hasNext() ) {
7600                 return false;
7601             }
7602             phy = p.next();
7603             if ( phy == null ) {
7604                 return false;
7605             }
7606             if ( phy.getNumberOfExternalNodes() != 4 ) {
7607                 return false;
7608             }
7609             if ( !phy.getName().equals( "" ) ) {
7610                 return false;
7611             }
7612             if ( !phy.isRooted() ) {
7613                 return false;
7614             }
7615             //4
7616             if ( !p.hasNext() ) {
7617                 return false;
7618             }
7619             phy = p.next();
7620             if ( phy == null ) {
7621                 return false;
7622             }
7623             if ( phy.getNumberOfExternalNodes() != 5 ) {
7624                 System.out.println( phy.getNumberOfExternalNodes() );
7625                 return false;
7626             }
7627             if ( !phy.getName().equals( "" ) ) {
7628                 return false;
7629             }
7630             if ( !phy.isRooted() ) {
7631                 return false;
7632             }
7633             //5
7634             if ( !p.hasNext() ) {
7635                 return false;
7636             }
7637             phy = p.next();
7638             if ( phy == null ) {
7639                 return false;
7640             }
7641             if ( phy.getNumberOfExternalNodes() != 3 ) {
7642                 return false;
7643             }
7644             if ( !phy.getName().equals( "" ) ) {
7645                 return false;
7646             }
7647             if ( phy.isRooted() ) {
7648                 return false;
7649             }
7650             //
7651             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7652             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7653             // 0
7654             if ( !p2.hasNext() ) {
7655                 return false;
7656             }
7657             phy = p2.next();
7658             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7659                 return false;
7660             }
7661             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7662                 return false;
7663             }
7664             // 1
7665             if ( !p2.hasNext() ) {
7666                 return false;
7667             }
7668             phy = p2.next();
7669             // 2
7670             if ( !p2.hasNext() ) {
7671                 return false;
7672             }
7673             phy = p2.next();
7674             // 3
7675             if ( !p2.hasNext() ) {
7676                 return false;
7677             }
7678             phy = p2.next();
7679             // 4
7680             if ( !p2.hasNext() ) {
7681                 return false;
7682             }
7683             phy = p2.next();
7684             // 5
7685             if ( !p2.hasNext() ) {
7686                 return false;
7687             }
7688             phy = p2.next();
7689             // 6
7690             if ( !p2.hasNext() ) {
7691                 return false;
7692             }
7693             phy = p2.next();
7694             // 7
7695             if ( !p2.hasNext() ) {
7696                 return false;
7697             }
7698             phy = p2.next();
7699             // 8
7700             if ( !p2.hasNext() ) {
7701                 return false;
7702             }
7703             phy = p2.next();
7704             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7705                 return false;
7706             }
7707             if ( p2.hasNext() ) {
7708                 return false;
7709             }
7710             phy = p2.next();
7711             if ( phy != null ) {
7712                 return false;
7713             }
7714             // 0
7715             p2.reset();
7716             if ( !p2.hasNext() ) {
7717                 return false;
7718             }
7719             phy = p2.next();
7720             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7721                 return false;
7722             }
7723             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7724                 return false;
7725             }
7726         }
7727         catch ( final Exception e ) {
7728             e.printStackTrace( System.out );
7729             return false;
7730         }
7731         return true;
7732     }
7733
7734     private static boolean testNexusTreeParsingTranslating() {
7735         try {
7736             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7737             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7738             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7739             if ( phylogenies.length != 1 ) {
7740                 return false;
7741             }
7742             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7743                 return false;
7744             }
7745             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7746                 return false;
7747             }
7748             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7749                 return false;
7750             }
7751             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7752                 return false;
7753             }
7754             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7755                     .equals( "Aranaeus" ) ) {
7756                 return false;
7757             }
7758             phylogenies = null;
7759             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7760             if ( phylogenies.length != 3 ) {
7761                 return false;
7762             }
7763             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7764                 return false;
7765             }
7766             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7767                 return false;
7768             }
7769             if ( phylogenies[ 0 ].isRooted() ) {
7770                 return false;
7771             }
7772             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7773                 return false;
7774             }
7775             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7776                 return false;
7777             }
7778             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7779                     .equals( "Aranaeus" ) ) {
7780                 return false;
7781             }
7782             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7783                 return false;
7784             }
7785             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7786                 return false;
7787             }
7788             if ( phylogenies[ 1 ].isRooted() ) {
7789                 return false;
7790             }
7791             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7792                 return false;
7793             }
7794             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7795                 return false;
7796             }
7797             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7798                     .equals( "Aranaeus" ) ) {
7799                 return false;
7800             }
7801             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7802                 return false;
7803             }
7804             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7805                 return false;
7806             }
7807             if ( !phylogenies[ 2 ].isRooted() ) {
7808                 return false;
7809             }
7810             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7811                 return false;
7812             }
7813             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7814                 return false;
7815             }
7816             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7817                     .equals( "Aranaeus" ) ) {
7818                 return false;
7819             }
7820             phylogenies = null;
7821             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7822             if ( phylogenies.length != 3 ) {
7823                 return false;
7824             }
7825             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7826                 return false;
7827             }
7828             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7829                 return false;
7830             }
7831             if ( phylogenies[ 0 ].isRooted() ) {
7832                 return false;
7833             }
7834             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7835                 return false;
7836             }
7837             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7838                 return false;
7839             }
7840             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7841                     .equals( "Aranaeus" ) ) {
7842                 return false;
7843             }
7844             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7845                 return false;
7846             }
7847             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7848                 return false;
7849             }
7850             if ( phylogenies[ 1 ].isRooted() ) {
7851                 return false;
7852             }
7853             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7854                 return false;
7855             }
7856             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7857                 return false;
7858             }
7859             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7860                     .equals( "Aranaeus" ) ) {
7861                 return false;
7862             }
7863             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7864                 return false;
7865             }
7866             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7867                 return false;
7868             }
7869             if ( !phylogenies[ 2 ].isRooted() ) {
7870                 return false;
7871             }
7872             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7873                 return false;
7874             }
7875             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7876                 return false;
7877             }
7878             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7879                     .equals( "Aranaeus" ) ) {
7880                 return false;
7881             }
7882             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7883             if ( phylogenies.length != 3 ) {
7884                 return false;
7885             }
7886             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7887                            0.00100049 ) ) {
7888                 return false;
7889             }
7890         }
7891         catch ( final Exception e ) {
7892             e.printStackTrace( System.out );
7893             return false;
7894         }
7895         return true;
7896     }
7897
7898     private static boolean testNHParsing() {
7899         try {
7900             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7901             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7902             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7903                 return false;
7904             }
7905             final NHXParser nhxp = new NHXParser();
7906             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7907             nhxp.setReplaceUnderscores( true );
7908             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7909             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7910                 return false;
7911             }
7912             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7913                 return false;
7914             }
7915             final Phylogeny p1b = factory
7916                     .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 ",
7917                              new NHXParser() )[ 0 ];
7918             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7919                 return false;
7920             }
7921             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7922                 return false;
7923             }
7924             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7925             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7926             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7927             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7928             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7929             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7930             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7931             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7932             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7933             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7934             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7935                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7936                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7937                                                     new NHXParser() );
7938             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7939                 return false;
7940             }
7941             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7942                 return false;
7943             }
7944             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7945                 return false;
7946             }
7947             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7948                 return false;
7949             }
7950             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7951             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7952             final String p16_S = "((A,B),C)";
7953             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7954             if ( p16.length != 1 ) {
7955                 return false;
7956             }
7957             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7958                 return false;
7959             }
7960             final String p17_S = "(C,(A,B))";
7961             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7962             if ( p17.length != 1 ) {
7963                 return false;
7964             }
7965             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7966                 return false;
7967             }
7968             final String p18_S = "((A,B),(C,D))";
7969             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7970             if ( p18.length != 1 ) {
7971                 return false;
7972             }
7973             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7974                 return false;
7975             }
7976             final String p19_S = "(((A,B),C),D)";
7977             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7978             if ( p19.length != 1 ) {
7979                 return false;
7980             }
7981             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7982                 return false;
7983             }
7984             final String p20_S = "(A,(B,(C,D)))";
7985             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7986             if ( p20.length != 1 ) {
7987                 return false;
7988             }
7989             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7990                 return false;
7991             }
7992             final String p21_S = "(A,(B,(C,(D,E))))";
7993             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7994             if ( p21.length != 1 ) {
7995                 return false;
7996             }
7997             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7998                 return false;
7999             }
8000             final String p22_S = "((((A,B),C),D),E)";
8001             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8002             if ( p22.length != 1 ) {
8003                 return false;
8004             }
8005             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8006                 return false;
8007             }
8008             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8009             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8010             if ( p23.length != 1 ) {
8011                 System.out.println( "xl=" + p23.length );
8012                 System.exit( -1 );
8013                 return false;
8014             }
8015             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8016                 return false;
8017             }
8018             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8019             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8020             if ( p24.length != 1 ) {
8021                 return false;
8022             }
8023             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8024                 return false;
8025             }
8026             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8027             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8028             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8029             if ( p241.length != 2 ) {
8030                 return false;
8031             }
8032             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8033                 return false;
8034             }
8035             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8036                 return false;
8037             }
8038             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8039                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8040                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8041                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8042                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8043                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8044                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8045                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8046             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8047             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8048                 return false;
8049             }
8050             final String p26_S = "(A,B)ab";
8051             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8052             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8053                 return false;
8054             }
8055             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8056             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8057             if ( p27s.length != 1 ) {
8058                 System.out.println( "xxl=" + p27s.length );
8059                 System.exit( -1 );
8060                 return false;
8061             }
8062             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8063                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8064                 System.exit( -1 );
8065                 return false;
8066             }
8067             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8068                                                     new NHXParser() );
8069             if ( p27.length != 1 ) {
8070                 System.out.println( "yl=" + p27.length );
8071                 System.exit( -1 );
8072                 return false;
8073             }
8074             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8075                 System.out.println( p27[ 0 ].toNewHampshireX() );
8076                 System.exit( -1 );
8077                 return false;
8078             }
8079             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8080             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8081             final String p28_S3 = "(A,B)ab";
8082             final String p28_S4 = "((((A,B),C),D),;E;)";
8083             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8084                                                     new NHXParser() );
8085             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8086                 return false;
8087             }
8088             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8089                 return false;
8090             }
8091             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8092                 return false;
8093             }
8094             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8095                 return false;
8096             }
8097             if ( p28.length != 4 ) {
8098                 return false;
8099             }
8100             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";
8101             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8102             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8103                 return false;
8104             }
8105             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";
8106             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8107             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8108                 return false;
8109             }
8110             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8111             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8112             if ( ( p32.length != 0 ) ) {
8113                 return false;
8114             }
8115             final String p33_S = "A";
8116             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8117             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8118                 return false;
8119             }
8120             final String p34_S = "B;";
8121             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8122             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8123                 return false;
8124             }
8125             final String p35_S = "B:0.2";
8126             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8127             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8128                 return false;
8129             }
8130             final String p36_S = "(A)";
8131             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8132             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8133                 return false;
8134             }
8135             final String p37_S = "((A))";
8136             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8137             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8138                 return false;
8139             }
8140             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8141             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8142             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8143                 return false;
8144             }
8145             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8146             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8147             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8148                 return false;
8149             }
8150             final String p40_S = "(A,B,C)";
8151             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8152             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8153                 return false;
8154             }
8155             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8156             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8157             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8158                 return false;
8159             }
8160             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8161             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8162             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8163                 return false;
8164             }
8165             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)";
8166             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8167             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8168                 return false;
8169             }
8170             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)))";
8171             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8172             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8173                 return false;
8174             }
8175             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8176             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8177             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8178                 return false;
8179             }
8180             final String p46_S = "";
8181             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8182             if ( p46.length != 0 ) {
8183                 return false;
8184             }
8185             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8186             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8187                 return false;
8188             }
8189             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8190             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8191                 return false;
8192             }
8193             final Phylogeny p49 = factory
8194                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8195                              new NHXParser() )[ 0 ];
8196             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8197                 return false;
8198             }
8199             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8200             if ( p50.getNode( "A" ) == null ) {
8201                 return false;
8202             }
8203             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8204                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8205                 return false;
8206             }
8207             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8208                 return false;
8209             }
8210             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8211                     .equals( "((A,B)88:2.0,C);" ) ) {
8212                 return false;
8213             }
8214             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8215             if ( p51.getNode( "A(A" ) == null ) {
8216                 return false;
8217             }
8218             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8219             if ( p52.getNode( "A(A" ) == null ) {
8220                 return false;
8221             }
8222             final Phylogeny p53 = factory
8223                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8224                              new NHXParser() )[ 0 ];
8225             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8226                 return false;
8227             }
8228             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8229             if ( p54.getNode( "A" ) == null ) {
8230                 return false;
8231             }
8232             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8233                 return false;
8234             }
8235             final Phylogeny p55 = factory
8236                     .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);" ),
8237                              new NHXParser() )[ 0 ];
8238             if ( !p55
8239                     .toNewHampshire()
8240                     .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);" ) ) {
8241                 System.out.println( p55.toNewHampshire() );
8242                 return false;
8243             }
8244             final Phylogeny p56 = factory
8245                     .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);" ),
8246                              new NHXParser() )[ 0 ];
8247             if ( !p56
8248                     .toNewHampshire()
8249                     .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);" ) ) {
8250                 System.out.println( p56.toNewHampshire() );
8251                 return false;
8252             }
8253             final Phylogeny p57 = factory
8254                     .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);" ),
8255                              new NHXParser() )[ 0 ];
8256             if ( !p57
8257                     .toNewHampshire()
8258                     .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);" ) ) {
8259                 System.out.println( p56.toNewHampshire() );
8260                 return false;
8261             }
8262             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8263             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8264             if ( !p58.toNewHampshire().equals( s58 ) ) {
8265                 System.out.println( p58.toNewHampshire() );
8266                 return false;
8267             }
8268             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8269             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8270             if ( !p59.toNewHampshire().equals( s59 ) ) {
8271                 System.out.println( p59.toNewHampshire() );
8272                 return false;
8273             }
8274             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8275             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8276             if ( !p60.toNewHampshire().equals( s60 ) ) {
8277                 System.out.println( p60.toNewHampshire() );
8278                 return false;
8279             }
8280             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8281             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8282             if ( !p61.toNewHampshire()
8283                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8284                 System.out.println( p61.toNewHampshire() );
8285                 return false;
8286             }
8287         }
8288         catch ( final Exception e ) {
8289             e.printStackTrace( System.out );
8290             return false;
8291         }
8292         return true;
8293     }
8294
8295     private static boolean testNHParsingIter() {
8296         try {
8297             final String p0_str = "(A,B);";
8298             final NHXParser p = new NHXParser();
8299             p.setSource( p0_str );
8300             if ( !p.hasNext() ) {
8301                 return false;
8302             }
8303             final Phylogeny p0 = p.next();
8304             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8305                 System.out.println( p0.toNewHampshire() );
8306                 return false;
8307             }
8308             if ( p.hasNext() ) {
8309                 return false;
8310             }
8311             if ( p.next() != null ) {
8312                 return false;
8313             }
8314             //
8315             final String p00_str = "(A,B)root;";
8316             p.setSource( p00_str );
8317             final Phylogeny p00 = p.next();
8318             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8319                 System.out.println( p00.toNewHampshire() );
8320                 return false;
8321             }
8322             //
8323             final String p000_str = "A;";
8324             p.setSource( p000_str );
8325             final Phylogeny p000 = p.next();
8326             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8327                 System.out.println( p000.toNewHampshire() );
8328                 return false;
8329             }
8330             //
8331             final String p0000_str = "A";
8332             p.setSource( p0000_str );
8333             final Phylogeny p0000 = p.next();
8334             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8335                 System.out.println( p0000.toNewHampshire() );
8336                 return false;
8337             }
8338             //
8339             p.setSource( "(A)" );
8340             final Phylogeny p00000 = p.next();
8341             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8342                 System.out.println( p00000.toNewHampshire() );
8343                 return false;
8344             }
8345             //
8346             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8347             p.setSource( p1_str );
8348             if ( !p.hasNext() ) {
8349                 return false;
8350             }
8351             final Phylogeny p1_0 = p.next();
8352             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8353                 System.out.println( p1_0.toNewHampshire() );
8354                 return false;
8355             }
8356             if ( !p.hasNext() ) {
8357                 return false;
8358             }
8359             final Phylogeny p1_1 = p.next();
8360             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8361                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8362                 return false;
8363             }
8364             if ( !p.hasNext() ) {
8365                 return false;
8366             }
8367             final Phylogeny p1_2 = p.next();
8368             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8369                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8370                 return false;
8371             }
8372             if ( !p.hasNext() ) {
8373                 return false;
8374             }
8375             final Phylogeny p1_3 = p.next();
8376             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8377                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8378                 return false;
8379             }
8380             if ( p.hasNext() ) {
8381                 return false;
8382             }
8383             if ( p.next() != null ) {
8384                 return false;
8385             }
8386             //
8387             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8388             p.setSource( p2_str );
8389             if ( !p.hasNext() ) {
8390                 return false;
8391             }
8392             Phylogeny p2_0 = p.next();
8393             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8394                 System.out.println( p2_0.toNewHampshire() );
8395                 return false;
8396             }
8397             if ( !p.hasNext() ) {
8398                 return false;
8399             }
8400             Phylogeny p2_1 = p.next();
8401             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8402                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8403                 return false;
8404             }
8405             if ( !p.hasNext() ) {
8406                 return false;
8407             }
8408             Phylogeny p2_2 = p.next();
8409             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8410                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8411                 return false;
8412             }
8413             if ( !p.hasNext() ) {
8414                 return false;
8415             }
8416             Phylogeny p2_3 = p.next();
8417             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8418                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8419                 return false;
8420             }
8421             if ( !p.hasNext() ) {
8422                 return false;
8423             }
8424             Phylogeny p2_4 = p.next();
8425             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8426                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8427                 return false;
8428             }
8429             if ( p.hasNext() ) {
8430                 return false;
8431             }
8432             if ( p.next() != null ) {
8433                 return false;
8434             }
8435             ////
8436             p.reset();
8437             if ( !p.hasNext() ) {
8438                 return false;
8439             }
8440             p2_0 = p.next();
8441             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8442                 System.out.println( p2_0.toNewHampshire() );
8443                 return false;
8444             }
8445             if ( !p.hasNext() ) {
8446                 return false;
8447             }
8448             p2_1 = p.next();
8449             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8450                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8451                 return false;
8452             }
8453             if ( !p.hasNext() ) {
8454                 return false;
8455             }
8456             p2_2 = p.next();
8457             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8458                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8459                 return false;
8460             }
8461             if ( !p.hasNext() ) {
8462                 return false;
8463             }
8464             p2_3 = p.next();
8465             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8466                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8467                 return false;
8468             }
8469             if ( !p.hasNext() ) {
8470                 return false;
8471             }
8472             p2_4 = p.next();
8473             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8474                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8475                 return false;
8476             }
8477             if ( p.hasNext() ) {
8478                 return false;
8479             }
8480             if ( p.next() != null ) {
8481                 return false;
8482             }
8483             //
8484             final String p3_str = "((A,B),C)abc";
8485             p.setSource( p3_str );
8486             if ( !p.hasNext() ) {
8487                 return false;
8488             }
8489             final Phylogeny p3_0 = p.next();
8490             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8491                 return false;
8492             }
8493             if ( p.hasNext() ) {
8494                 return false;
8495             }
8496             if ( p.next() != null ) {
8497                 return false;
8498             }
8499             //
8500             final String p4_str = "((A,B)ab,C)abc";
8501             p.setSource( p4_str );
8502             if ( !p.hasNext() ) {
8503                 return false;
8504             }
8505             final Phylogeny p4_0 = p.next();
8506             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8507                 return false;
8508             }
8509             if ( p.hasNext() ) {
8510                 return false;
8511             }
8512             if ( p.next() != null ) {
8513                 return false;
8514             }
8515             //
8516             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8517             p.setSource( p5_str );
8518             if ( !p.hasNext() ) {
8519                 return false;
8520             }
8521             final Phylogeny p5_0 = p.next();
8522             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8523                 return false;
8524             }
8525             if ( p.hasNext() ) {
8526                 return false;
8527             }
8528             if ( p.next() != null ) {
8529                 return false;
8530             }
8531             //
8532             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8533             p.setSource( p6_str );
8534             if ( !p.hasNext() ) {
8535                 return false;
8536             }
8537             Phylogeny p6_0 = p.next();
8538             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8539                 return false;
8540             }
8541             if ( p.hasNext() ) {
8542                 return false;
8543             }
8544             if ( p.next() != null ) {
8545                 return false;
8546             }
8547             p.reset();
8548             if ( !p.hasNext() ) {
8549                 return false;
8550             }
8551             p6_0 = p.next();
8552             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8553                 return false;
8554             }
8555             if ( p.hasNext() ) {
8556                 return false;
8557             }
8558             if ( p.next() != null ) {
8559                 return false;
8560             }
8561             //
8562             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8563             p.setSource( p7_str );
8564             if ( !p.hasNext() ) {
8565                 return false;
8566             }
8567             Phylogeny p7_0 = p.next();
8568             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8569                 return false;
8570             }
8571             if ( p.hasNext() ) {
8572                 return false;
8573             }
8574             if ( p.next() != null ) {
8575                 return false;
8576             }
8577             p.reset();
8578             if ( !p.hasNext() ) {
8579                 return false;
8580             }
8581             p7_0 = p.next();
8582             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8583                 return false;
8584             }
8585             if ( p.hasNext() ) {
8586                 return false;
8587             }
8588             if ( p.next() != null ) {
8589                 return false;
8590             }
8591             //
8592             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8593             p.setSource( p8_str );
8594             if ( !p.hasNext() ) {
8595                 return false;
8596             }
8597             Phylogeny p8_0 = p.next();
8598             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8599                 return false;
8600             }
8601             if ( !p.hasNext() ) {
8602                 return false;
8603             }
8604             if ( !p.hasNext() ) {
8605                 return false;
8606             }
8607             Phylogeny p8_1 = p.next();
8608             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8609                 return false;
8610             }
8611             if ( p.hasNext() ) {
8612                 return false;
8613             }
8614             if ( p.next() != null ) {
8615                 return false;
8616             }
8617             p.reset();
8618             if ( !p.hasNext() ) {
8619                 return false;
8620             }
8621             p8_0 = p.next();
8622             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8623                 return false;
8624             }
8625             if ( !p.hasNext() ) {
8626                 return false;
8627             }
8628             p8_1 = p.next();
8629             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8630                 return false;
8631             }
8632             if ( p.hasNext() ) {
8633                 return false;
8634             }
8635             if ( p.next() != null ) {
8636                 return false;
8637             }
8638             p.reset();
8639             //
8640             p.setSource( "" );
8641             if ( p.hasNext() ) {
8642                 return false;
8643             }
8644             //
8645             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8646             if ( !p.hasNext() ) {
8647                 return false;
8648             }
8649             Phylogeny p_27 = p.next();
8650             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8651                 System.out.println( p_27.toNewHampshireX() );
8652                 System.exit( -1 );
8653                 return false;
8654             }
8655             if ( p.hasNext() ) {
8656                 return false;
8657             }
8658             if ( p.next() != null ) {
8659                 return false;
8660             }
8661             p.reset();
8662             if ( !p.hasNext() ) {
8663                 return false;
8664             }
8665             p_27 = p.next();
8666             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8667                 System.out.println( p_27.toNewHampshireX() );
8668                 System.exit( -1 );
8669                 return false;
8670             }
8671             if ( p.hasNext() ) {
8672                 return false;
8673             }
8674             if ( p.next() != null ) {
8675                 return false;
8676             }
8677             //
8678             final String p30_str = "(A,B);(C,D)";
8679             final NHXParser p30 = new NHXParser();
8680             p30.setSource( p30_str );
8681             if ( !p30.hasNext() ) {
8682                 return false;
8683             }
8684             Phylogeny phy30 = p30.next();
8685             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8686                 System.out.println( phy30.toNewHampshire() );
8687                 return false;
8688             }
8689             if ( !p30.hasNext() ) {
8690                 return false;
8691             }
8692             Phylogeny phy301 = p30.next();
8693             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8694                 System.out.println( phy301.toNewHampshire() );
8695                 return false;
8696             }
8697             if ( p30.hasNext() ) {
8698                 return false;
8699             }
8700             if ( p30.hasNext() ) {
8701                 return false;
8702             }
8703             if ( p30.next() != null ) {
8704                 return false;
8705             }
8706             if ( p30.next() != null ) {
8707                 return false;
8708             }
8709             p30.reset();
8710             if ( !p30.hasNext() ) {
8711                 return false;
8712             }
8713             phy30 = p30.next();
8714             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8715                 System.out.println( phy30.toNewHampshire() );
8716                 return false;
8717             }
8718             if ( !p30.hasNext() ) {
8719                 return false;
8720             }
8721             phy301 = p30.next();
8722             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8723                 System.out.println( phy301.toNewHampshire() );
8724                 return false;
8725             }
8726             if ( p30.hasNext() ) {
8727                 return false;
8728             }
8729             if ( p30.hasNext() ) {
8730                 return false;
8731             }
8732             if ( p30.next() != null ) {
8733                 return false;
8734             }
8735             if ( p30.next() != null ) {
8736                 return false;
8737             }
8738         }
8739         catch ( final Exception e ) {
8740             e.printStackTrace( System.out );
8741             return false;
8742         }
8743         return true;
8744     }
8745
8746     private static boolean testNHXconversion() {
8747         try {
8748             final PhylogenyNode n1 = new PhylogenyNode();
8749             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8750             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8751             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8752             final PhylogenyNode n5 = PhylogenyNode
8753                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8754             final PhylogenyNode n6 = PhylogenyNode
8755                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8756             if ( !n1.toNewHampshireX().equals( "" ) ) {
8757                 return false;
8758             }
8759             if ( !n2.toNewHampshireX().equals( "" ) ) {
8760                 return false;
8761             }
8762             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8763                 return false;
8764             }
8765             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8766                 return false;
8767             }
8768             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8769                 return false;
8770             }
8771             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8772                 System.out.println( n6.toNewHampshireX() );
8773                 return false;
8774             }
8775             final PhylogenyNode n7 = new PhylogenyNode();
8776             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8777             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8778                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8779                 System.out.println( n7
8780                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8781                 return false;
8782             }
8783         }
8784         catch ( final Exception e ) {
8785             e.printStackTrace( System.out );
8786             return false;
8787         }
8788         return true;
8789     }
8790
8791     private static boolean testNHXNodeParsing() {
8792         try {
8793             final PhylogenyNode n1 = new PhylogenyNode();
8794             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8795             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8796             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8797             final PhylogenyNode n5 = PhylogenyNode
8798                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y: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]" );
8799             if ( !n3.getName().equals( "n3" ) ) {
8800                 return false;
8801             }
8802             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8803                 return false;
8804             }
8805             if ( n3.isDuplication() ) {
8806                 return false;
8807             }
8808             if ( n3.isHasAssignedEvent() ) {
8809                 return false;
8810             }
8811             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8812                 return false;
8813             }
8814             if ( !n4.getName().equals( "n4" ) ) {
8815                 return false;
8816             }
8817             if ( n4.getDistanceToParent() != 0.01 ) {
8818                 return false;
8819             }
8820             if ( !n5.getName().equals( "n5" ) ) {
8821                 return false;
8822             }
8823             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8824                 return false;
8825             }
8826             if ( n5.getDistanceToParent() != 0.1 ) {
8827                 return false;
8828             }
8829             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8830                 return false;
8831             }
8832             if ( !n5.isDuplication() ) {
8833                 return false;
8834             }
8835             if ( !n5.isHasAssignedEvent() ) {
8836                 return false;
8837             }
8838             final PhylogenyNode n8 = PhylogenyNode
8839                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8840                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8841             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8842                 return false;
8843             }
8844             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8845                 return false;
8846             }
8847             final PhylogenyNode n9 = PhylogenyNode
8848                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8849                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8850             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8851                 return false;
8852             }
8853             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8854                 return false;
8855             }
8856             final PhylogenyNode n10 = PhylogenyNode
8857                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8858             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8859                 return false;
8860             }
8861             final PhylogenyNode n20 = PhylogenyNode
8862                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8863             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8864                 return false;
8865             }
8866             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8867                 return false;
8868             }
8869             final PhylogenyNode n20x = PhylogenyNode
8870                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8871             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8872                 return false;
8873             }
8874             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8875                 return false;
8876             }
8877             final PhylogenyNode n20xx = PhylogenyNode
8878                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8879             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8880                 return false;
8881             }
8882             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8883                 return false;
8884             }
8885             final PhylogenyNode n20xxx = PhylogenyNode
8886                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8887             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8888                 return false;
8889             }
8890             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8891                 return false;
8892             }
8893             final PhylogenyNode n20xxxx = PhylogenyNode
8894                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8895             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8896                 return false;
8897             }
8898             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8899                 return false;
8900             }
8901             final PhylogenyNode n21 = PhylogenyNode
8902                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8903             if ( !n21.getName().equals( "N21_PIG" ) ) {
8904                 return false;
8905             }
8906             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8907                 return false;
8908             }
8909             final PhylogenyNode n21x = PhylogenyNode
8910                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8911             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8912                 return false;
8913             }
8914             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8915                 return false;
8916             }
8917             final PhylogenyNode n22 = PhylogenyNode
8918                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8919             if ( !n22.getName().equals( "n22/PIG" ) ) {
8920                 return false;
8921             }
8922             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8923                 return false;
8924             }
8925             final PhylogenyNode n23 = PhylogenyNode
8926                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8927             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8928                 return false;
8929             }
8930             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8931                 return false;
8932             }
8933             final PhylogenyNode a = PhylogenyNode
8934                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8935             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8936                 return false;
8937             }
8938             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8939                 return false;
8940             }
8941             final PhylogenyNode c1 = PhylogenyNode
8942                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8943                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8944             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8945                 return false;
8946             }
8947             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8948                 return false;
8949             }
8950             final PhylogenyNode c2 = PhylogenyNode
8951                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8952                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8953             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8954                 return false;
8955             }
8956             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8957                 return false;
8958             }
8959             final PhylogenyNode e3 = PhylogenyNode
8960                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8961             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8962                 return false;
8963             }
8964             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8965                 return false;
8966             }
8967             final PhylogenyNode n11 = PhylogenyNode
8968                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8969                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8970             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8971                 return false;
8972             }
8973             if ( n11.getDistanceToParent() != 0.4 ) {
8974                 return false;
8975             }
8976             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8977                 return false;
8978             }
8979             final PhylogenyNode n12 = PhylogenyNode
8980                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8981                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8982             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8983                 return false;
8984             }
8985             if ( n12.getDistanceToParent() != 0.4 ) {
8986                 return false;
8987             }
8988             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8989                 return false;
8990             }
8991             final PhylogenyNode o = PhylogenyNode
8992                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8993             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8994                 return false;
8995             }
8996             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8997                 return false;
8998             }
8999             if ( n1.getName().compareTo( "" ) != 0 ) {
9000                 return false;
9001             }
9002             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9003                 return false;
9004             }
9005             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9006                 return false;
9007             }
9008             if ( n2.getName().compareTo( "" ) != 0 ) {
9009                 return false;
9010             }
9011             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9012                 return false;
9013             }
9014             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9015                 return false;
9016             }
9017             final PhylogenyNode n00 = PhylogenyNode
9018                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9019             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9020                 return false;
9021             }
9022             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9023                 return false;
9024             }
9025             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9026             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9027                 return false;
9028             }
9029             final PhylogenyNode n13 = PhylogenyNode
9030                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9031             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9032                 return false;
9033             }
9034             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9035                 return false;
9036             }
9037             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9038                 return false;
9039             }
9040             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9041                 return false;
9042             }
9043             final PhylogenyNode n14 = PhylogenyNode
9044                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9045             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9046                 return false;
9047             }
9048             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9049                 return false;
9050             }
9051             final PhylogenyNode n15 = PhylogenyNode
9052                     .createInstanceFromNhxString( "something_wicked[123]",
9053                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9054             if ( !n15.getName().equals( "something_wicked" ) ) {
9055                 return false;
9056             }
9057             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9058                 return false;
9059             }
9060             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9061                 return false;
9062             }
9063             final PhylogenyNode n16 = PhylogenyNode
9064                     .createInstanceFromNhxString( "something_wicked2[9]",
9065                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9066             if ( !n16.getName().equals( "something_wicked2" ) ) {
9067                 return false;
9068             }
9069             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9070                 return false;
9071             }
9072             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9073                 return false;
9074             }
9075             final PhylogenyNode n17 = PhylogenyNode
9076                     .createInstanceFromNhxString( "something_wicked3[a]",
9077                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9078             if ( !n17.getName().equals( "something_wicked3" ) ) {
9079                 return false;
9080             }
9081             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9082                 return false;
9083             }
9084             final PhylogenyNode n18 = PhylogenyNode
9085                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9086             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9087                 return false;
9088             }
9089             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9090                 return false;
9091             }
9092             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9093                 return false;
9094             }
9095             final PhylogenyNode n19 = PhylogenyNode
9096                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9097             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9098                 return false;
9099             }
9100             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9101                 return false;
9102             }
9103             final PhylogenyNode n30 = PhylogenyNode
9104                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9105                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9106             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9107                 return false;
9108             }
9109             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9110                 return false;
9111             }
9112             final PhylogenyNode n31 = PhylogenyNode
9113                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9114                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9115             if ( n31.getNodeData().isHasTaxonomy() ) {
9116                 return false;
9117             }
9118             final PhylogenyNode n32 = PhylogenyNode
9119                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9120             if ( n32.getNodeData().isHasTaxonomy() ) {
9121                 return false;
9122             }
9123             final PhylogenyNode n40 = PhylogenyNode
9124                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9125             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9126                 return false;
9127             }
9128             final PhylogenyNode n41 = PhylogenyNode
9129                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9130             if ( n41.getNodeData().isHasTaxonomy() ) {
9131                 return false;
9132             }
9133             final PhylogenyNode n42 = PhylogenyNode
9134                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9135             if ( n42.getNodeData().isHasTaxonomy() ) {
9136                 return false;
9137             }
9138             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9139                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9140             if ( n43.getNodeData().isHasTaxonomy() ) {
9141                 return false;
9142             }
9143             final PhylogenyNode n44 = PhylogenyNode
9144                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9145             if ( n44.getNodeData().isHasTaxonomy() ) {
9146                 return false;
9147             }
9148         }
9149         catch ( final Exception e ) {
9150             e.printStackTrace( System.out );
9151             return false;
9152         }
9153         return true;
9154     }
9155
9156     private static boolean testNHXParsing() {
9157         try {
9158             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9159             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9160             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9161                 return false;
9162             }
9163             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]";
9164             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9165             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9166                 return false;
9167             }
9168             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]";
9169             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9170             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9171                 return false;
9172             }
9173             final Phylogeny[] p3 = factory
9174                     .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]",
9175                              new NHXParser() );
9176             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9177                 return false;
9178             }
9179             final Phylogeny[] p4 = factory
9180                     .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(]",
9181                              new NHXParser() );
9182             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9183                 return false;
9184             }
9185             final Phylogeny[] p5 = factory
9186                     .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(((]",
9187                              new NHXParser() );
9188             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9189                 return false;
9190             }
9191             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)";
9192             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)";
9193             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9194             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9195                 return false;
9196             }
9197             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)))";
9198             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)))";
9199             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9200             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9201                 return false;
9202             }
9203             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])   ))[,,, ])))))))";
9204             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9205             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9206             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9207                 return false;
9208             }
9209             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9210             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9211                 return false;
9212             }
9213             final Phylogeny p10 = factory
9214                     .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]",
9215                              new NHXParser() )[ 0 ];
9216             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9217                 return false;
9218             }
9219             final Phylogeny p11 = factory
9220                     .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]",
9221                              new NHXParser() )[ 0 ];
9222             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9223                 return false;
9224             }
9225         }
9226         catch ( final Exception e ) {
9227             e.printStackTrace( System.out );
9228             return false;
9229         }
9230         return true;
9231     }
9232
9233     private static boolean testNHXParsingMB() {
9234         try {
9235             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9236             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9237                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9238                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9239                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9240                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9241                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9242                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9243                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9244                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9245             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9246                 return false;
9247             }
9248             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9249                 return false;
9250             }
9251             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9252                            0.1100000000000000e+00 ) ) {
9253                 return false;
9254             }
9255             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9256                 return false;
9257             }
9258             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9259                 return false;
9260             }
9261             final Phylogeny p2 = factory
9262                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9263                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9264                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9265                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9266                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9267                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9268                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9269                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9270                                      + "7.369400000000000e-02}])",
9271                              new NHXParser() )[ 0 ];
9272             if ( p2.getNode( "1" ) == null ) {
9273                 return false;
9274             }
9275             if ( p2.getNode( "2" ) == null ) {
9276                 return false;
9277             }
9278         }
9279         catch ( final Exception e ) {
9280             e.printStackTrace( System.out );
9281             System.exit( -1 );
9282             return false;
9283         }
9284         return true;
9285     }
9286
9287     private static boolean testNHXParsingQuotes() {
9288         try {
9289             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9290             final NHXParser p = new NHXParser();
9291             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9292             if ( phylogenies_0.length != 5 ) {
9293                 return false;
9294             }
9295             final Phylogeny phy = phylogenies_0[ 4 ];
9296             if ( phy.getNumberOfExternalNodes() != 7 ) {
9297                 return false;
9298             }
9299             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9300                 return false;
9301             }
9302             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9303                 return false;
9304             }
9305             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9306                     .getScientificName().equals( "hsapiens" ) ) {
9307                 return false;
9308             }
9309             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9310                 return false;
9311             }
9312             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9313                 return false;
9314             }
9315             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9316                 return false;
9317             }
9318             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9319                 return false;
9320             }
9321             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9322                 return false;
9323             }
9324             final NHXParser p1p = new NHXParser();
9325             p1p.setIgnoreQuotes( true );
9326             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9327             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9328                 return false;
9329             }
9330             final NHXParser p2p = new NHXParser();
9331             p1p.setIgnoreQuotes( false );
9332             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9333             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9334                 return false;
9335             }
9336             final NHXParser p3p = new NHXParser();
9337             p3p.setIgnoreQuotes( false );
9338             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9339             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9340                 return false;
9341             }
9342             final NHXParser p4p = new NHXParser();
9343             p4p.setIgnoreQuotes( false );
9344             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9345             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9346                 return false;
9347             }
9348             final Phylogeny p10 = factory
9349                     .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]",
9350                              new NHXParser() )[ 0 ];
9351             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]";
9352             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9353                 return false;
9354             }
9355             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9356             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9357                 return false;
9358             }
9359             final Phylogeny p12 = factory
9360                     .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]",
9361                              new NHXParser() )[ 0 ];
9362             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]";
9363             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9364                 return false;
9365             }
9366             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9367             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9368                 return false;
9369             }
9370             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;";
9371             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9372                 return false;
9373             }
9374             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9375             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9376                 return false;
9377             }
9378         }
9379         catch ( final Exception e ) {
9380             e.printStackTrace( System.out );
9381             return false;
9382         }
9383         return true;
9384     }
9385
9386     private static boolean testNodeRemoval() {
9387         try {
9388             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9389             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9390             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9391             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9392                 return false;
9393             }
9394             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9395             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9396             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9397                 return false;
9398             }
9399             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9400             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9401             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9402                 return false;
9403             }
9404         }
9405         catch ( final Exception e ) {
9406             e.printStackTrace( System.out );
9407             return false;
9408         }
9409         return true;
9410     }
9411
9412     private static boolean testPhylogenyBranch() {
9413         try {
9414             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9415             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9416             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9417             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9418             if ( !a1b1.equals( a1b1 ) ) {
9419                 return false;
9420             }
9421             if ( !a1b1.equals( b1a1 ) ) {
9422                 return false;
9423             }
9424             if ( !b1a1.equals( a1b1 ) ) {
9425                 return false;
9426             }
9427             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9428             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9429             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9430             if ( a1_b1.equals( b1_a1 ) ) {
9431                 return false;
9432             }
9433             if ( a1_b1.equals( a1_b1_ ) ) {
9434                 return false;
9435             }
9436             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9437             if ( !a1_b1.equals( b1_a1_ ) ) {
9438                 return false;
9439             }
9440             if ( a1_b1_.equals( b1_a1_ ) ) {
9441                 return false;
9442             }
9443             if ( !a1_b1_.equals( b1_a1 ) ) {
9444                 return false;
9445             }
9446         }
9447         catch ( final Exception e ) {
9448             e.printStackTrace( System.out );
9449             return false;
9450         }
9451         return true;
9452     }
9453
9454     private static boolean testPhyloXMLparsingOfDistributionElement() {
9455         try {
9456             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9457             PhyloXmlParser xml_parser = null;
9458             try {
9459                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9460             }
9461             catch ( final Exception e ) {
9462                 // Do nothing -- means were not running from jar.
9463             }
9464             if ( xml_parser == null ) {
9465                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9466                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9467                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9468                 }
9469                 else {
9470                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9471                 }
9472             }
9473             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9474                                                               xml_parser );
9475             if ( xml_parser.getErrorCount() > 0 ) {
9476                 System.out.println( xml_parser.getErrorMessages().toString() );
9477                 return false;
9478             }
9479             if ( phylogenies_0.length != 1 ) {
9480                 return false;
9481             }
9482             final Phylogeny t1 = phylogenies_0[ 0 ];
9483             PhylogenyNode n = null;
9484             Distribution d = null;
9485             n = t1.getNode( "root node" );
9486             if ( !n.getNodeData().isHasDistribution() ) {
9487                 return false;
9488             }
9489             if ( n.getNodeData().getDistributions().size() != 1 ) {
9490                 return false;
9491             }
9492             d = n.getNodeData().getDistribution();
9493             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9494                 return false;
9495             }
9496             if ( d.getPoints().size() != 1 ) {
9497                 return false;
9498             }
9499             if ( d.getPolygons() != null ) {
9500                 return false;
9501             }
9502             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9503                 return false;
9504             }
9505             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9506                 return false;
9507             }
9508             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9509                 return false;
9510             }
9511             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9512                 return false;
9513             }
9514             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9515                 return false;
9516             }
9517             n = t1.getNode( "node a" );
9518             if ( !n.getNodeData().isHasDistribution() ) {
9519                 return false;
9520             }
9521             if ( n.getNodeData().getDistributions().size() != 2 ) {
9522                 return false;
9523             }
9524             d = n.getNodeData().getDistribution( 1 );
9525             if ( !d.getDesc().equals( "San Diego" ) ) {
9526                 return false;
9527             }
9528             if ( d.getPoints().size() != 1 ) {
9529                 return false;
9530             }
9531             if ( d.getPolygons() != null ) {
9532                 return false;
9533             }
9534             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9535                 return false;
9536             }
9537             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9538                 return false;
9539             }
9540             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9541                 return false;
9542             }
9543             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9544                 return false;
9545             }
9546             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9547                 return false;
9548             }
9549             n = t1.getNode( "node bb" );
9550             if ( !n.getNodeData().isHasDistribution() ) {
9551                 return false;
9552             }
9553             if ( n.getNodeData().getDistributions().size() != 1 ) {
9554                 return false;
9555             }
9556             d = n.getNodeData().getDistribution( 0 );
9557             if ( d.getPoints().size() != 3 ) {
9558                 return false;
9559             }
9560             if ( d.getPolygons().size() != 2 ) {
9561                 return false;
9562             }
9563             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9564                 return false;
9565             }
9566             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9567                 return false;
9568             }
9569             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9570                 return false;
9571             }
9572             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9573                 return false;
9574             }
9575             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9576                 return false;
9577             }
9578             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9579                 return false;
9580             }
9581             Polygon p = d.getPolygons().get( 0 );
9582             if ( p.getPoints().size() != 3 ) {
9583                 return false;
9584             }
9585             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9586                 return false;
9587             }
9588             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9589                 return false;
9590             }
9591             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9592                 return false;
9593             }
9594             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9595                 return false;
9596             }
9597             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9598                 return false;
9599             }
9600             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9601                 return false;
9602             }
9603             p = d.getPolygons().get( 1 );
9604             if ( p.getPoints().size() != 3 ) {
9605                 return false;
9606             }
9607             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9608                 return false;
9609             }
9610             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9611                 return false;
9612             }
9613             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9614                 return false;
9615             }
9616             // Roundtrip:
9617             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9618             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9619             if ( rt.length != 1 ) {
9620                 return false;
9621             }
9622             final Phylogeny t1_rt = rt[ 0 ];
9623             n = t1_rt.getNode( "root node" );
9624             if ( !n.getNodeData().isHasDistribution() ) {
9625                 return false;
9626             }
9627             if ( n.getNodeData().getDistributions().size() != 1 ) {
9628                 return false;
9629             }
9630             d = n.getNodeData().getDistribution();
9631             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9632                 return false;
9633             }
9634             if ( d.getPoints().size() != 1 ) {
9635                 return false;
9636             }
9637             if ( d.getPolygons() != null ) {
9638                 return false;
9639             }
9640             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9641                 return false;
9642             }
9643             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9644                 return false;
9645             }
9646             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9647                 return false;
9648             }
9649             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9650                 return false;
9651             }
9652             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9653                 return false;
9654             }
9655             n = t1_rt.getNode( "node a" );
9656             if ( !n.getNodeData().isHasDistribution() ) {
9657                 return false;
9658             }
9659             if ( n.getNodeData().getDistributions().size() != 2 ) {
9660                 return false;
9661             }
9662             d = n.getNodeData().getDistribution( 1 );
9663             if ( !d.getDesc().equals( "San Diego" ) ) {
9664                 return false;
9665             }
9666             if ( d.getPoints().size() != 1 ) {
9667                 return false;
9668             }
9669             if ( d.getPolygons() != null ) {
9670                 return false;
9671             }
9672             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9673                 return false;
9674             }
9675             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9676                 return false;
9677             }
9678             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9679                 return false;
9680             }
9681             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9682                 return false;
9683             }
9684             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9685                 return false;
9686             }
9687             n = t1_rt.getNode( "node bb" );
9688             if ( !n.getNodeData().isHasDistribution() ) {
9689                 return false;
9690             }
9691             if ( n.getNodeData().getDistributions().size() != 1 ) {
9692                 return false;
9693             }
9694             d = n.getNodeData().getDistribution( 0 );
9695             if ( d.getPoints().size() != 3 ) {
9696                 return false;
9697             }
9698             if ( d.getPolygons().size() != 2 ) {
9699                 return false;
9700             }
9701             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9702                 return false;
9703             }
9704             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9705                 return false;
9706             }
9707             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9708                 return false;
9709             }
9710             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9711                 return false;
9712             }
9713             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9714                 return false;
9715             }
9716             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9717                 return false;
9718             }
9719             p = d.getPolygons().get( 0 );
9720             if ( p.getPoints().size() != 3 ) {
9721                 return false;
9722             }
9723             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9724                 return false;
9725             }
9726             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9727                 return false;
9728             }
9729             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9730                 return false;
9731             }
9732             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9733                 return false;
9734             }
9735             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9736                 return false;
9737             }
9738             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9739                 return false;
9740             }
9741             p = d.getPolygons().get( 1 );
9742             if ( p.getPoints().size() != 3 ) {
9743                 return false;
9744             }
9745             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9746                 return false;
9747             }
9748             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9749                 return false;
9750             }
9751             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9752                 return false;
9753             }
9754         }
9755         catch ( final Exception e ) {
9756             e.printStackTrace( System.out );
9757             return false;
9758         }
9759         return true;
9760     }
9761
9762     private static boolean testPostOrderIterator() {
9763         try {
9764             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9765             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9766             PhylogenyNodeIterator it0;
9767             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9768                 it0.next();
9769             }
9770             for( it0.reset(); it0.hasNext(); ) {
9771                 it0.next();
9772             }
9773             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9774             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9775             if ( !it.next().getName().equals( "A" ) ) {
9776                 return false;
9777             }
9778             if ( !it.next().getName().equals( "B" ) ) {
9779                 return false;
9780             }
9781             if ( !it.next().getName().equals( "ab" ) ) {
9782                 return false;
9783             }
9784             if ( !it.next().getName().equals( "C" ) ) {
9785                 return false;
9786             }
9787             if ( !it.next().getName().equals( "D" ) ) {
9788                 return false;
9789             }
9790             if ( !it.next().getName().equals( "cd" ) ) {
9791                 return false;
9792             }
9793             if ( !it.next().getName().equals( "abcd" ) ) {
9794                 return false;
9795             }
9796             if ( !it.next().getName().equals( "E" ) ) {
9797                 return false;
9798             }
9799             if ( !it.next().getName().equals( "F" ) ) {
9800                 return false;
9801             }
9802             if ( !it.next().getName().equals( "ef" ) ) {
9803                 return false;
9804             }
9805             if ( !it.next().getName().equals( "G" ) ) {
9806                 return false;
9807             }
9808             if ( !it.next().getName().equals( "H" ) ) {
9809                 return false;
9810             }
9811             if ( !it.next().getName().equals( "gh" ) ) {
9812                 return false;
9813             }
9814             if ( !it.next().getName().equals( "efgh" ) ) {
9815                 return false;
9816             }
9817             if ( !it.next().getName().equals( "r" ) ) {
9818                 return false;
9819             }
9820             if ( it.hasNext() ) {
9821                 return false;
9822             }
9823         }
9824         catch ( final Exception e ) {
9825             e.printStackTrace( System.out );
9826             return false;
9827         }
9828         return true;
9829     }
9830
9831     private static boolean testPreOrderIterator() {
9832         try {
9833             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9834             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9835             PhylogenyNodeIterator it0;
9836             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9837                 it0.next();
9838             }
9839             for( it0.reset(); it0.hasNext(); ) {
9840                 it0.next();
9841             }
9842             PhylogenyNodeIterator it = t0.iteratorPreorder();
9843             if ( !it.next().getName().equals( "r" ) ) {
9844                 return false;
9845             }
9846             if ( !it.next().getName().equals( "ab" ) ) {
9847                 return false;
9848             }
9849             if ( !it.next().getName().equals( "A" ) ) {
9850                 return false;
9851             }
9852             if ( !it.next().getName().equals( "B" ) ) {
9853                 return false;
9854             }
9855             if ( !it.next().getName().equals( "cd" ) ) {
9856                 return false;
9857             }
9858             if ( !it.next().getName().equals( "C" ) ) {
9859                 return false;
9860             }
9861             if ( !it.next().getName().equals( "D" ) ) {
9862                 return false;
9863             }
9864             if ( it.hasNext() ) {
9865                 return false;
9866             }
9867             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9868             it = t1.iteratorPreorder();
9869             if ( !it.next().getName().equals( "r" ) ) {
9870                 return false;
9871             }
9872             if ( !it.next().getName().equals( "abcd" ) ) {
9873                 return false;
9874             }
9875             if ( !it.next().getName().equals( "ab" ) ) {
9876                 return false;
9877             }
9878             if ( !it.next().getName().equals( "A" ) ) {
9879                 return false;
9880             }
9881             if ( !it.next().getName().equals( "B" ) ) {
9882                 return false;
9883             }
9884             if ( !it.next().getName().equals( "cd" ) ) {
9885                 return false;
9886             }
9887             if ( !it.next().getName().equals( "C" ) ) {
9888                 return false;
9889             }
9890             if ( !it.next().getName().equals( "D" ) ) {
9891                 return false;
9892             }
9893             if ( !it.next().getName().equals( "efgh" ) ) {
9894                 return false;
9895             }
9896             if ( !it.next().getName().equals( "ef" ) ) {
9897                 return false;
9898             }
9899             if ( !it.next().getName().equals( "E" ) ) {
9900                 return false;
9901             }
9902             if ( !it.next().getName().equals( "F" ) ) {
9903                 return false;
9904             }
9905             if ( !it.next().getName().equals( "gh" ) ) {
9906                 return false;
9907             }
9908             if ( !it.next().getName().equals( "G" ) ) {
9909                 return false;
9910             }
9911             if ( !it.next().getName().equals( "H" ) ) {
9912                 return false;
9913             }
9914             if ( it.hasNext() ) {
9915                 return false;
9916             }
9917         }
9918         catch ( final Exception e ) {
9919             e.printStackTrace( System.out );
9920             return false;
9921         }
9922         return true;
9923     }
9924
9925     private static boolean testPropertiesMap() {
9926         try {
9927             final PropertiesMap pm = new PropertiesMap();
9928             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9929             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9930             final Property p2 = new Property( "something:else",
9931                                               "?",
9932                                               "improbable:research",
9933                                               "xsd:decimal",
9934                                               AppliesTo.NODE );
9935             pm.addProperty( p0 );
9936             pm.addProperty( p1 );
9937             pm.addProperty( p2 );
9938             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9939                 return false;
9940             }
9941             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9942                 return false;
9943             }
9944             if ( pm.getProperties().size() != 3 ) {
9945                 return false;
9946             }
9947             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9948                 return false;
9949             }
9950             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9951                 return false;
9952             }
9953             if ( pm.getProperties().size() != 3 ) {
9954                 return false;
9955             }
9956             pm.removeProperty( "dimensions:diameter" );
9957             if ( pm.getProperties().size() != 2 ) {
9958                 return false;
9959             }
9960             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9961                 return false;
9962             }
9963             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9964                 return false;
9965             }
9966         }
9967         catch ( final Exception e ) {
9968             e.printStackTrace( System.out );
9969             return false;
9970         }
9971         return true;
9972     }
9973
9974     private static boolean testProteinId() {
9975         try {
9976             final ProteinId id1 = new ProteinId( "a" );
9977             final ProteinId id2 = new ProteinId( "a" );
9978             final ProteinId id3 = new ProteinId( "A" );
9979             final ProteinId id4 = new ProteinId( "b" );
9980             if ( !id1.equals( id1 ) ) {
9981                 return false;
9982             }
9983             if ( id1.getId().equals( "x" ) ) {
9984                 return false;
9985             }
9986             if ( id1.getId().equals( null ) ) {
9987                 return false;
9988             }
9989             if ( !id1.equals( id2 ) ) {
9990                 return false;
9991             }
9992             if ( id1.equals( id3 ) ) {
9993                 return false;
9994             }
9995             if ( id1.hashCode() != id1.hashCode() ) {
9996                 return false;
9997             }
9998             if ( id1.hashCode() != id2.hashCode() ) {
9999                 return false;
10000             }
10001             if ( id1.hashCode() == id3.hashCode() ) {
10002                 return false;
10003             }
10004             if ( id1.compareTo( id1 ) != 0 ) {
10005                 return false;
10006             }
10007             if ( id1.compareTo( id2 ) != 0 ) {
10008                 return false;
10009             }
10010             if ( id1.compareTo( id3 ) != 0 ) {
10011                 return false;
10012             }
10013             if ( id1.compareTo( id4 ) >= 0 ) {
10014                 return false;
10015             }
10016             if ( id4.compareTo( id1 ) <= 0 ) {
10017                 return false;
10018             }
10019             if ( !id4.getId().equals( "b" ) ) {
10020                 return false;
10021             }
10022             final ProteinId id5 = new ProteinId( " C " );
10023             if ( !id5.getId().equals( "C" ) ) {
10024                 return false;
10025             }
10026             if ( id5.equals( id1 ) ) {
10027                 return false;
10028             }
10029         }
10030         catch ( final Exception e ) {
10031             e.printStackTrace( System.out );
10032             return false;
10033         }
10034         return true;
10035     }
10036
10037     private static boolean testReIdMethods() {
10038         try {
10039             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10040             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10041             final long count = PhylogenyNode.getNodeCount();
10042             p.levelOrderReID();
10043             if ( p.getNode( "r" ).getId() != count ) {
10044                 return false;
10045             }
10046             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10047                 return false;
10048             }
10049             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10050                 return false;
10051             }
10052             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10053                 return false;
10054             }
10055             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10056                 return false;
10057             }
10058             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10059                 return false;
10060             }
10061             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10062                 return false;
10063             }
10064             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10065                 return false;
10066             }
10067             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10068                 return false;
10069             }
10070             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10071                 return false;
10072             }
10073             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10074                 return false;
10075             }
10076             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10077                 return false;
10078             }
10079             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10080                 return false;
10081             }
10082             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10083                 return false;
10084             }
10085             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10086                 return false;
10087             }
10088         }
10089         catch ( final Exception e ) {
10090             e.printStackTrace( System.out );
10091             return false;
10092         }
10093         return true;
10094     }
10095
10096     private static boolean testRerooting() {
10097         try {
10098             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10099             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",
10100                                                  new NHXParser() )[ 0 ];
10101             if ( !t1.isRooted() ) {
10102                 return false;
10103             }
10104             t1.reRoot( t1.getNode( "D" ) );
10105             t1.reRoot( t1.getNode( "CD" ) );
10106             t1.reRoot( t1.getNode( "A" ) );
10107             t1.reRoot( t1.getNode( "B" ) );
10108             t1.reRoot( t1.getNode( "AB" ) );
10109             t1.reRoot( t1.getNode( "D" ) );
10110             t1.reRoot( t1.getNode( "C" ) );
10111             t1.reRoot( t1.getNode( "CD" ) );
10112             t1.reRoot( t1.getNode( "A" ) );
10113             t1.reRoot( t1.getNode( "B" ) );
10114             t1.reRoot( t1.getNode( "AB" ) );
10115             t1.reRoot( t1.getNode( "D" ) );
10116             t1.reRoot( t1.getNode( "D" ) );
10117             t1.reRoot( t1.getNode( "C" ) );
10118             t1.reRoot( t1.getNode( "A" ) );
10119             t1.reRoot( t1.getNode( "B" ) );
10120             t1.reRoot( t1.getNode( "AB" ) );
10121             t1.reRoot( t1.getNode( "C" ) );
10122             t1.reRoot( t1.getNode( "D" ) );
10123             t1.reRoot( t1.getNode( "CD" ) );
10124             t1.reRoot( t1.getNode( "D" ) );
10125             t1.reRoot( t1.getNode( "A" ) );
10126             t1.reRoot( t1.getNode( "B" ) );
10127             t1.reRoot( t1.getNode( "AB" ) );
10128             t1.reRoot( t1.getNode( "C" ) );
10129             t1.reRoot( t1.getNode( "D" ) );
10130             t1.reRoot( t1.getNode( "CD" ) );
10131             t1.reRoot( t1.getNode( "D" ) );
10132             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10133                 return false;
10134             }
10135             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10136                 return false;
10137             }
10138             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10139                 return false;
10140             }
10141             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10142                 return false;
10143             }
10144             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10145                 return false;
10146             }
10147             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10148                 return false;
10149             }
10150             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",
10151                                                  new NHXParser() )[ 0 ];
10152             t2.reRoot( t2.getNode( "A" ) );
10153             t2.reRoot( t2.getNode( "D" ) );
10154             t2.reRoot( t2.getNode( "ABC" ) );
10155             t2.reRoot( t2.getNode( "A" ) );
10156             t2.reRoot( t2.getNode( "B" ) );
10157             t2.reRoot( t2.getNode( "D" ) );
10158             t2.reRoot( t2.getNode( "C" ) );
10159             t2.reRoot( t2.getNode( "ABC" ) );
10160             t2.reRoot( t2.getNode( "A" ) );
10161             t2.reRoot( t2.getNode( "B" ) );
10162             t2.reRoot( t2.getNode( "AB" ) );
10163             t2.reRoot( t2.getNode( "AB" ) );
10164             t2.reRoot( t2.getNode( "D" ) );
10165             t2.reRoot( t2.getNode( "C" ) );
10166             t2.reRoot( t2.getNode( "B" ) );
10167             t2.reRoot( t2.getNode( "AB" ) );
10168             t2.reRoot( t2.getNode( "D" ) );
10169             t2.reRoot( t2.getNode( "D" ) );
10170             t2.reRoot( t2.getNode( "ABC" ) );
10171             t2.reRoot( t2.getNode( "A" ) );
10172             t2.reRoot( t2.getNode( "B" ) );
10173             t2.reRoot( t2.getNode( "AB" ) );
10174             t2.reRoot( t2.getNode( "D" ) );
10175             t2.reRoot( t2.getNode( "C" ) );
10176             t2.reRoot( t2.getNode( "ABC" ) );
10177             t2.reRoot( t2.getNode( "A" ) );
10178             t2.reRoot( t2.getNode( "B" ) );
10179             t2.reRoot( t2.getNode( "AB" ) );
10180             t2.reRoot( t2.getNode( "D" ) );
10181             t2.reRoot( t2.getNode( "D" ) );
10182             t2.reRoot( t2.getNode( "C" ) );
10183             t2.reRoot( t2.getNode( "A" ) );
10184             t2.reRoot( t2.getNode( "B" ) );
10185             t2.reRoot( t2.getNode( "AB" ) );
10186             t2.reRoot( t2.getNode( "C" ) );
10187             t2.reRoot( t2.getNode( "D" ) );
10188             t2.reRoot( t2.getNode( "ABC" ) );
10189             t2.reRoot( t2.getNode( "D" ) );
10190             t2.reRoot( t2.getNode( "A" ) );
10191             t2.reRoot( t2.getNode( "B" ) );
10192             t2.reRoot( t2.getNode( "AB" ) );
10193             t2.reRoot( t2.getNode( "C" ) );
10194             t2.reRoot( t2.getNode( "D" ) );
10195             t2.reRoot( t2.getNode( "ABC" ) );
10196             t2.reRoot( t2.getNode( "D" ) );
10197             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10198                 return false;
10199             }
10200             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10201                 return false;
10202             }
10203             t2.reRoot( t2.getNode( "ABC" ) );
10204             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10205                 return false;
10206             }
10207             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10208                 return false;
10209             }
10210             t2.reRoot( t2.getNode( "AB" ) );
10211             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10212                 return false;
10213             }
10214             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10215                 return false;
10216             }
10217             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10218                 return false;
10219             }
10220             t2.reRoot( t2.getNode( "AB" ) );
10221             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10222                 return false;
10223             }
10224             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10225                 return false;
10226             }
10227             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10228                 return false;
10229             }
10230             t2.reRoot( t2.getNode( "D" ) );
10231             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10232                 return false;
10233             }
10234             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10235                 return false;
10236             }
10237             t2.reRoot( t2.getNode( "ABC" ) );
10238             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10239                 return false;
10240             }
10241             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10242                 return false;
10243             }
10244             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10245                                                  new NHXParser() )[ 0 ];
10246             t3.reRoot( t3.getNode( "B" ) );
10247             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10248                 return false;
10249             }
10250             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10251                 return false;
10252             }
10253             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10254                 return false;
10255             }
10256             t3.reRoot( t3.getNode( "B" ) );
10257             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10258                 return false;
10259             }
10260             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10261                 return false;
10262             }
10263             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10264                 return false;
10265             }
10266             t3.reRoot( t3.getRoot() );
10267             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10268                 return false;
10269             }
10270             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10271                 return false;
10272             }
10273             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10274                 return false;
10275             }
10276         }
10277         catch ( final Exception e ) {
10278             e.printStackTrace( System.out );
10279             return false;
10280         }
10281         return true;
10282     }
10283
10284     private static boolean testSDIse() {
10285         try {
10286             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10287             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10288             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10289             gene1.setRooted( true );
10290             species1.setRooted( true );
10291             final SDI sdi = new SDI( gene1, species1 );
10292             if ( !gene1.getRoot().isDuplication() ) {
10293                 return false;
10294             }
10295             final Phylogeny species2 = factory
10296                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10297                              new NHXParser() )[ 0 ];
10298             final Phylogeny gene2 = factory
10299                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10300                              new NHXParser() )[ 0 ];
10301             species2.setRooted( true );
10302             gene2.setRooted( true );
10303             final SDI sdi2 = new SDI( gene2, species2 );
10304             if ( sdi2.getDuplicationsSum() != 0 ) {
10305                 return false;
10306             }
10307             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10308                 return false;
10309             }
10310             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10311                 return false;
10312             }
10313             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10314                 return false;
10315             }
10316             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10317                 return false;
10318             }
10319             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10320                 return false;
10321             }
10322             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10323                 return false;
10324             }
10325             final Phylogeny species3 = factory
10326                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10327                              new NHXParser() )[ 0 ];
10328             final Phylogeny gene3 = factory
10329                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10330                              new NHXParser() )[ 0 ];
10331             species3.setRooted( true );
10332             gene3.setRooted( true );
10333             final SDI sdi3 = new SDI( gene3, species3 );
10334             if ( sdi3.getDuplicationsSum() != 1 ) {
10335                 return false;
10336             }
10337             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10338                 return false;
10339             }
10340             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10341                 return false;
10342             }
10343             final Phylogeny species4 = factory
10344                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10345                              new NHXParser() )[ 0 ];
10346             final Phylogeny gene4 = factory
10347                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10348                              new NHXParser() )[ 0 ];
10349             species4.setRooted( true );
10350             gene4.setRooted( true );
10351             final SDI sdi4 = new SDI( gene4, species4 );
10352             if ( sdi4.getDuplicationsSum() != 1 ) {
10353                 return false;
10354             }
10355             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10356                 return false;
10357             }
10358             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10359                 return false;
10360             }
10361             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10362                 return false;
10363             }
10364             if ( species4.getNumberOfExternalNodes() != 6 ) {
10365                 return false;
10366             }
10367             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10368                 return false;
10369             }
10370             final Phylogeny species5 = factory
10371                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10372                              new NHXParser() )[ 0 ];
10373             final Phylogeny gene5 = factory
10374                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10375                              new NHXParser() )[ 0 ];
10376             species5.setRooted( true );
10377             gene5.setRooted( true );
10378             final SDI sdi5 = new SDI( gene5, species5 );
10379             if ( sdi5.getDuplicationsSum() != 2 ) {
10380                 return false;
10381             }
10382             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10383                 return false;
10384             }
10385             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10386                 return false;
10387             }
10388             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10389                 return false;
10390             }
10391             if ( species5.getNumberOfExternalNodes() != 6 ) {
10392                 return false;
10393             }
10394             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10395                 return false;
10396             }
10397             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10398             // Conjecture for Comparing Molecular Phylogenies"
10399             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10400             final Phylogeny species6 = factory
10401                     .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,"
10402                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10403                              new NHXParser() )[ 0 ];
10404             final Phylogeny gene6 = factory
10405                     .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,"
10406                                      + "((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,"
10407                                      + "(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;",
10408                              new NHXParser() )[ 0 ];
10409             species6.setRooted( true );
10410             gene6.setRooted( true );
10411             final SDI sdi6 = new SDI( gene6, species6 );
10412             if ( sdi6.getDuplicationsSum() != 3 ) {
10413                 return false;
10414             }
10415             if ( !gene6.getNode( "r" ).isDuplication() ) {
10416                 return false;
10417             }
10418             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10419                 return false;
10420             }
10421             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10422                 return false;
10423             }
10424             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10425                 return false;
10426             }
10427             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10428                 return false;
10429             }
10430             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10431                 return false;
10432             }
10433             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10434                 return false;
10435             }
10436             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10437                 return false;
10438             }
10439             sdi6.computeMappingCostL();
10440             if ( sdi6.computeMappingCostL() != 17 ) {
10441                 return false;
10442             }
10443             if ( species6.getNumberOfExternalNodes() != 9 ) {
10444                 return false;
10445             }
10446             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10447                 return false;
10448             }
10449             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10450                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10451                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10452                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10453                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10454             species7.setRooted( true );
10455             final Phylogeny gene7_1 = Test
10456                     .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])" );
10457             gene7_1.setRooted( true );
10458             final SDI sdi7 = new SDI( gene7_1, species7 );
10459             if ( sdi7.getDuplicationsSum() != 0 ) {
10460                 return false;
10461             }
10462             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10463                 return false;
10464             }
10465             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10466                 return false;
10467             }
10468             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10469                 return false;
10470             }
10471             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10472                 return false;
10473             }
10474             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10475                 return false;
10476             }
10477             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10478                 return false;
10479             }
10480             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10481                 return false;
10482             }
10483             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10484                 return false;
10485             }
10486             final Phylogeny gene7_2 = Test
10487                     .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])" );
10488             gene7_2.setRooted( true );
10489             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10490             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10491                 return false;
10492             }
10493             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10494                 return false;
10495             }
10496             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10497                 return false;
10498             }
10499             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10500                 return false;
10501             }
10502             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10503                 return false;
10504             }
10505             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10506                 return false;
10507             }
10508             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10509                 return false;
10510             }
10511             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10512                 return false;
10513             }
10514             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10515                 return false;
10516             }
10517             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10518                 return false;
10519             }
10520         }
10521         catch ( final Exception e ) {
10522             return false;
10523         }
10524         return true;
10525     }
10526
10527     private static boolean testSDIunrooted() {
10528         try {
10529             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10530             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10531             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10532             final Iterator<PhylogenyBranch> iter = l.iterator();
10533             PhylogenyBranch br = iter.next();
10534             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10535                 return false;
10536             }
10537             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10538                 return false;
10539             }
10540             br = iter.next();
10541             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10542                 return false;
10543             }
10544             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10545                 return false;
10546             }
10547             br = iter.next();
10548             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10549                 return false;
10550             }
10551             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10552                 return false;
10553             }
10554             br = iter.next();
10555             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10556                 return false;
10557             }
10558             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10559                 return false;
10560             }
10561             br = iter.next();
10562             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10563                 return false;
10564             }
10565             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10566                 return false;
10567             }
10568             br = iter.next();
10569             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10570                 return false;
10571             }
10572             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10573                 return false;
10574             }
10575             br = iter.next();
10576             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10577                 return false;
10578             }
10579             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10580                 return false;
10581             }
10582             br = iter.next();
10583             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10584                 return false;
10585             }
10586             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10587                 return false;
10588             }
10589             br = iter.next();
10590             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10591                 return false;
10592             }
10593             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10594                 return false;
10595             }
10596             br = iter.next();
10597             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10598                 return false;
10599             }
10600             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10601                 return false;
10602             }
10603             br = iter.next();
10604             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10605                 return false;
10606             }
10607             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10608                 return false;
10609             }
10610             br = iter.next();
10611             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10612                 return false;
10613             }
10614             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10615                 return false;
10616             }
10617             br = iter.next();
10618             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10619                 return false;
10620             }
10621             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10622                 return false;
10623             }
10624             br = iter.next();
10625             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10626                 return false;
10627             }
10628             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10629                 return false;
10630             }
10631             br = iter.next();
10632             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10633                 return false;
10634             }
10635             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10636                 return false;
10637             }
10638             if ( iter.hasNext() ) {
10639                 return false;
10640             }
10641             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10642             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10643             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10644             br = iter1.next();
10645             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10646                 return false;
10647             }
10648             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10649                 return false;
10650             }
10651             br = iter1.next();
10652             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10653                 return false;
10654             }
10655             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10656                 return false;
10657             }
10658             br = iter1.next();
10659             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10660                 return false;
10661             }
10662             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10663                 return false;
10664             }
10665             if ( iter1.hasNext() ) {
10666                 return false;
10667             }
10668             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10669             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10670             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10671             br = iter2.next();
10672             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10673                 return false;
10674             }
10675             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10676                 return false;
10677             }
10678             br = iter2.next();
10679             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10680                 return false;
10681             }
10682             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10683                 return false;
10684             }
10685             br = iter2.next();
10686             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10687                 return false;
10688             }
10689             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10690                 return false;
10691             }
10692             if ( iter2.hasNext() ) {
10693                 return false;
10694             }
10695             final Phylogeny species0 = factory
10696                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10697                              new NHXParser() )[ 0 ];
10698             final Phylogeny gene1 = factory
10699                     .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])",
10700                              new NHXParser() )[ 0 ];
10701             species0.setRooted( true );
10702             gene1.setRooted( true );
10703             final SDIR sdi_unrooted = new SDIR();
10704             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10705             if ( sdi_unrooted.getCount() != 1 ) {
10706                 return false;
10707             }
10708             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10709                 return false;
10710             }
10711             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10712                 return false;
10713             }
10714             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10715                 return false;
10716             }
10717             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10718                 return false;
10719             }
10720             final Phylogeny gene2 = factory
10721                     .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])",
10722                              new NHXParser() )[ 0 ];
10723             gene2.setRooted( true );
10724             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10725             if ( sdi_unrooted.getCount() != 1 ) {
10726                 return false;
10727             }
10728             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10729                 return false;
10730             }
10731             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10732                 return false;
10733             }
10734             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10735                 return false;
10736             }
10737             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10738                 return false;
10739             }
10740             final Phylogeny species6 = factory
10741                     .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,"
10742                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10743                              new NHXParser() )[ 0 ];
10744             final Phylogeny gene6 = factory
10745                     .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],"
10746                                      + "(((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],"
10747                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10748                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10749                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10750                              new NHXParser() )[ 0 ];
10751             species6.setRooted( true );
10752             gene6.setRooted( true );
10753             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10754             if ( sdi_unrooted.getCount() != 1 ) {
10755                 return false;
10756             }
10757             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10758                 return false;
10759             }
10760             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10761                 return false;
10762             }
10763             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10764                 return false;
10765             }
10766             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10767                 return false;
10768             }
10769             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10770                 return false;
10771             }
10772             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10773                 return false;
10774             }
10775             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10776                 return false;
10777             }
10778             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10779                 return false;
10780             }
10781             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10782                 return false;
10783             }
10784             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10785                 return false;
10786             }
10787             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10788                 return false;
10789             }
10790             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10791                 return false;
10792             }
10793             p6 = null;
10794             final Phylogeny species7 = factory
10795                     .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,"
10796                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10797                              new NHXParser() )[ 0 ];
10798             final Phylogeny gene7 = factory
10799                     .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],"
10800                                      + "(((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],"
10801                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10802                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10803                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10804                              new NHXParser() )[ 0 ];
10805             species7.setRooted( true );
10806             gene7.setRooted( true );
10807             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10808             if ( sdi_unrooted.getCount() != 1 ) {
10809                 return false;
10810             }
10811             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10812                 return false;
10813             }
10814             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10815                 return false;
10816             }
10817             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10818                 return false;
10819             }
10820             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10821                 return false;
10822             }
10823             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10824                 return false;
10825             }
10826             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10827                 return false;
10828             }
10829             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10830                 return false;
10831             }
10832             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10833                 return false;
10834             }
10835             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10836                 return false;
10837             }
10838             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10839                 return false;
10840             }
10841             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10842                 return false;
10843             }
10844             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10845                 return false;
10846             }
10847             p7 = null;
10848             final Phylogeny species8 = factory
10849                     .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,"
10850                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10851                              new NHXParser() )[ 0 ];
10852             final Phylogeny gene8 = factory
10853                     .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],"
10854                                      + "(((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],"
10855                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10856                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10857                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10858                              new NHXParser() )[ 0 ];
10859             species8.setRooted( true );
10860             gene8.setRooted( true );
10861             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10862             if ( sdi_unrooted.getCount() != 1 ) {
10863                 return false;
10864             }
10865             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10866                 return false;
10867             }
10868             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10869                 return false;
10870             }
10871             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10872                 return false;
10873             }
10874             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10875                 return false;
10876             }
10877             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10878                 return false;
10879             }
10880             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10881                 return false;
10882             }
10883             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10884                 return false;
10885             }
10886             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10887                 return false;
10888             }
10889             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10890                 return false;
10891             }
10892             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10893                 return false;
10894             }
10895             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10896                 return false;
10897             }
10898             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10899                 return false;
10900             }
10901             p8 = null;
10902         }
10903         catch ( final Exception e ) {
10904             e.printStackTrace( System.out );
10905             return false;
10906         }
10907         return true;
10908     }
10909
10910     private static boolean testSequenceDbWsTools1() {
10911         try {
10912             final PhylogenyNode n = new PhylogenyNode();
10913             n.setName( "NP_001025424" );
10914             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10915             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10916                     || !acc.getValue().equals( "NP_001025424" ) ) {
10917                 return false;
10918             }
10919             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10920             acc = SequenceDbWsTools.obtainSeqAccession( n );
10921             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10922                     || !acc.getValue().equals( "NP_001025424" ) ) {
10923                 return false;
10924             }
10925             n.setName( "NP_001025424.1" );
10926             acc = SequenceDbWsTools.obtainSeqAccession( n );
10927             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10928                     || !acc.getValue().equals( "NP_001025424" ) ) {
10929                 return false;
10930             }
10931             n.setName( "NM_001030253" );
10932             acc = SequenceDbWsTools.obtainSeqAccession( n );
10933             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10934                     || !acc.getValue().equals( "NM_001030253" ) ) {
10935                 return false;
10936             }
10937             n.setName( "BCL2_HUMAN" );
10938             acc = SequenceDbWsTools.obtainSeqAccession( n );
10939             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10940                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10941                 System.out.println( acc.toString() );
10942                 return false;
10943             }
10944             n.setName( "P10415" );
10945             acc = SequenceDbWsTools.obtainSeqAccession( n );
10946             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10947                     || !acc.getValue().equals( "P10415" ) ) {
10948                 System.out.println( acc.toString() );
10949                 return false;
10950             }
10951             n.setName( " P10415 " );
10952             acc = SequenceDbWsTools.obtainSeqAccession( n );
10953             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10954                     || !acc.getValue().equals( "P10415" ) ) {
10955                 System.out.println( acc.toString() );
10956                 return false;
10957             }
10958             n.setName( "_P10415|" );
10959             acc = SequenceDbWsTools.obtainSeqAccession( n );
10960             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10961                     || !acc.getValue().equals( "P10415" ) ) {
10962                 System.out.println( acc.toString() );
10963                 return false;
10964             }
10965             n.setName( "AY695820" );
10966             acc = SequenceDbWsTools.obtainSeqAccession( n );
10967             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10968                     || !acc.getValue().equals( "AY695820" ) ) {
10969                 System.out.println( acc.toString() );
10970                 return false;
10971             }
10972             n.setName( "_AY695820_" );
10973             acc = SequenceDbWsTools.obtainSeqAccession( n );
10974             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10975                     || !acc.getValue().equals( "AY695820" ) ) {
10976                 System.out.println( acc.toString() );
10977                 return false;
10978             }
10979             n.setName( "AAA59452" );
10980             acc = SequenceDbWsTools.obtainSeqAccession( n );
10981             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10982                     || !acc.getValue().equals( "AAA59452" ) ) {
10983                 System.out.println( acc.toString() );
10984                 return false;
10985             }
10986             n.setName( "_AAA59452_" );
10987             acc = SequenceDbWsTools.obtainSeqAccession( n );
10988             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10989                     || !acc.getValue().equals( "AAA59452" ) ) {
10990                 System.out.println( acc.toString() );
10991                 return false;
10992             }
10993             n.setName( "AAA59452.1" );
10994             acc = SequenceDbWsTools.obtainSeqAccession( n );
10995             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10996                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10997                 System.out.println( acc.toString() );
10998                 return false;
10999             }
11000             n.setName( "_AAA59452.1_" );
11001             acc = SequenceDbWsTools.obtainSeqAccession( n );
11002             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11003                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11004                 System.out.println( acc.toString() );
11005                 return false;
11006             }
11007             n.setName( "GI:94894583" );
11008             acc = SequenceDbWsTools.obtainSeqAccession( n );
11009             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11010                     || !acc.getValue().equals( "94894583" ) ) {
11011                 System.out.println( acc.toString() );
11012                 return false;
11013             }
11014             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11015             acc = SequenceDbWsTools.obtainSeqAccession( n );
11016             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11017                     || !acc.getValue().equals( "71845847" ) ) {
11018                 System.out.println( acc.toString() );
11019                 return false;
11020             }
11021             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11022             acc = SequenceDbWsTools.obtainSeqAccession( n );
11023             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11024                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11025                 System.out.println( acc.toString() );
11026                 return false;
11027             }
11028         }
11029         catch ( final Exception e ) {
11030             return false;
11031         }
11032         return true;
11033     }
11034
11035     private static boolean testSequenceDbWsTools2() {
11036         try {
11037             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11038             SequenceDbWsTools.obtainSeqInformation( n1 );
11039             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11040                 return false;
11041             }
11042             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11043                 return false;
11044             }
11045             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11046                 return false;
11047             }
11048             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11049                 return false;
11050             }
11051             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11052             SequenceDbWsTools.obtainSeqInformation( n2 );
11053             if ( !n2.getNodeData().getSequence().getName()
11054                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11055                 return false;
11056             }
11057             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11058                 return false;
11059             }
11060             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11061                 return false;
11062             }
11063             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11064                 return false;
11065             }
11066             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11067             SequenceDbWsTools.obtainSeqInformation( n3 );
11068             if ( !n3.getNodeData().getSequence().getName()
11069                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11070                 return false;
11071             }
11072             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11073                 return false;
11074             }
11075             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11076                 return false;
11077             }
11078             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11079                 return false;
11080             }
11081         }
11082         catch ( final IOException e ) {
11083             System.out.println();
11084             System.out.println( "the following might be due to absence internet connection:" );
11085             e.printStackTrace( System.out );
11086             return true;
11087         }
11088         catch ( final Exception e ) {
11089             e.printStackTrace();
11090             return false;
11091         }
11092         return true;
11093     }
11094
11095     private static boolean testSequenceIdParsing() {
11096         try {
11097             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11098             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11099                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11100                 if ( id != null ) {
11101                     System.out.println( "value   =" + id.getValue() );
11102                     System.out.println( "provider=" + id.getSource() );
11103                 }
11104                 return false;
11105             }
11106             //
11107             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11108             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11109                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11110                 if ( id != null ) {
11111                     System.out.println( "value   =" + id.getValue() );
11112                     System.out.println( "provider=" + id.getSource() );
11113                 }
11114                 return false;
11115             }
11116             //
11117             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11118             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11119                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11120                 if ( id != null ) {
11121                     System.out.println( "value   =" + id.getValue() );
11122                     System.out.println( "provider=" + id.getSource() );
11123                 }
11124                 return false;
11125             }
11126             // 
11127             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11128             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11129                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11130                 if ( id != null ) {
11131                     System.out.println( "value   =" + id.getValue() );
11132                     System.out.println( "provider=" + id.getSource() );
11133                 }
11134                 return false;
11135             }
11136             // 
11137             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11138             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11139                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11140                 if ( id != null ) {
11141                     System.out.println( "value   =" + id.getValue() );
11142                     System.out.println( "provider=" + id.getSource() );
11143                 }
11144                 return false;
11145             }
11146             // 
11147             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11148             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11149                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11150                 if ( id != null ) {
11151                     System.out.println( "value   =" + id.getValue() );
11152                     System.out.println( "provider=" + id.getSource() );
11153                 }
11154                 return false;
11155             }
11156             // 
11157             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11158             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11159                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11160                 if ( id != null ) {
11161                     System.out.println( "value   =" + id.getValue() );
11162                     System.out.println( "provider=" + id.getSource() );
11163                 }
11164                 return false;
11165             }
11166             // 
11167             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11168             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11169                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11170                 if ( id != null ) {
11171                     System.out.println( "value   =" + id.getValue() );
11172                     System.out.println( "provider=" + id.getSource() );
11173                 }
11174                 return false;
11175             }
11176             // 
11177             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11178             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11179                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11180                 if ( id != null ) {
11181                     System.out.println( "value   =" + id.getValue() );
11182                     System.out.println( "provider=" + id.getSource() );
11183                 }
11184                 return false;
11185             }
11186             // 
11187             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11188             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11189                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11190                 if ( id != null ) {
11191                     System.out.println( "value   =" + id.getValue() );
11192                     System.out.println( "provider=" + id.getSource() );
11193                 }
11194                 return false;
11195             }
11196             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11197             if ( id != null ) {
11198                 System.out.println( "value   =" + id.getValue() );
11199                 System.out.println( "provider=" + id.getSource() );
11200                 return false;
11201             }
11202         }
11203         catch ( final Exception e ) {
11204             e.printStackTrace( System.out );
11205             return false;
11206         }
11207         return true;
11208     }
11209
11210     private static boolean testSequenceWriter() {
11211         try {
11212             final String n = ForesterUtil.LINE_SEPARATOR;
11213             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11214                 return false;
11215             }
11216             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11217                 return false;
11218             }
11219             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11220                 return false;
11221             }
11222             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11223                 return false;
11224             }
11225             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11226                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11227                 return false;
11228             }
11229             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11230                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11231                 return false;
11232             }
11233         }
11234         catch ( final Exception e ) {
11235             e.printStackTrace();
11236             return false;
11237         }
11238         return true;
11239     }
11240
11241     private static boolean testSpecies() {
11242         try {
11243             final Species s1 = new BasicSpecies( "a" );
11244             final Species s2 = new BasicSpecies( "a" );
11245             final Species s3 = new BasicSpecies( "A" );
11246             final Species s4 = new BasicSpecies( "b" );
11247             if ( !s1.equals( s1 ) ) {
11248                 return false;
11249             }
11250             if ( s1.getSpeciesId().equals( "x" ) ) {
11251                 return false;
11252             }
11253             if ( s1.getSpeciesId().equals( null ) ) {
11254                 return false;
11255             }
11256             if ( !s1.equals( s2 ) ) {
11257                 return false;
11258             }
11259             if ( s1.equals( s3 ) ) {
11260                 return false;
11261             }
11262             if ( s1.hashCode() != s1.hashCode() ) {
11263                 return false;
11264             }
11265             if ( s1.hashCode() != s2.hashCode() ) {
11266                 return false;
11267             }
11268             if ( s1.hashCode() == s3.hashCode() ) {
11269                 return false;
11270             }
11271             if ( s1.compareTo( s1 ) != 0 ) {
11272                 return false;
11273             }
11274             if ( s1.compareTo( s2 ) != 0 ) {
11275                 return false;
11276             }
11277             if ( s1.compareTo( s3 ) != 0 ) {
11278                 return false;
11279             }
11280             if ( s1.compareTo( s4 ) >= 0 ) {
11281                 return false;
11282             }
11283             if ( s4.compareTo( s1 ) <= 0 ) {
11284                 return false;
11285             }
11286             if ( !s4.getSpeciesId().equals( "b" ) ) {
11287                 return false;
11288             }
11289             final Species s5 = new BasicSpecies( " C " );
11290             if ( !s5.getSpeciesId().equals( "C" ) ) {
11291                 return false;
11292             }
11293             if ( s5.equals( s1 ) ) {
11294                 return false;
11295             }
11296         }
11297         catch ( final Exception e ) {
11298             e.printStackTrace( System.out );
11299             return false;
11300         }
11301         return true;
11302     }
11303
11304     private static boolean testSplit() {
11305         try {
11306             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11307             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11308             //Archaeopteryx.createApplication( p0 );
11309             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11310             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11311             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11312             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11313             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11314             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11315             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11316             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11317             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11318             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11319             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11320             // System.out.println( s0.toString() );
11321             //
11322             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11325             if ( s0.match( query_nodes ) ) {
11326                 return false;
11327             }
11328             query_nodes = new HashSet<PhylogenyNode>();
11329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11336             if ( !s0.match( query_nodes ) ) {
11337                 return false;
11338             }
11339             //
11340             query_nodes = new HashSet<PhylogenyNode>();
11341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11343             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11344             if ( !s0.match( query_nodes ) ) {
11345                 return false;
11346             }
11347             //
11348             query_nodes = new HashSet<PhylogenyNode>();
11349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11353             if ( !s0.match( query_nodes ) ) {
11354                 return false;
11355             }
11356             //
11357             query_nodes = new HashSet<PhylogenyNode>();
11358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11362             if ( !s0.match( query_nodes ) ) {
11363                 return false;
11364             }
11365             //
11366             query_nodes = new HashSet<PhylogenyNode>();
11367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11370             if ( !s0.match( query_nodes ) ) {
11371                 return false;
11372             }
11373             //
11374             query_nodes = new HashSet<PhylogenyNode>();
11375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11377             if ( !s0.match( query_nodes ) ) {
11378                 return false;
11379             }
11380             //
11381             query_nodes = new HashSet<PhylogenyNode>();
11382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11387             if ( !s0.match( query_nodes ) ) {
11388                 return false;
11389             }
11390             //
11391             query_nodes = new HashSet<PhylogenyNode>();
11392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11395             if ( !s0.match( query_nodes ) ) {
11396                 return false;
11397             }
11398             //
11399             query_nodes = new HashSet<PhylogenyNode>();
11400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11404             if ( !s0.match( query_nodes ) ) {
11405                 return false;
11406             }
11407             //
11408             query_nodes = new HashSet<PhylogenyNode>();
11409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11411             if ( s0.match( query_nodes ) ) {
11412                 return false;
11413             }
11414             //
11415             query_nodes = new HashSet<PhylogenyNode>();
11416             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11420             if ( s0.match( query_nodes ) ) {
11421                 return false;
11422             }
11423             //
11424             query_nodes = new HashSet<PhylogenyNode>();
11425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11430             if ( s0.match( query_nodes ) ) {
11431                 return false;
11432             }
11433             //
11434             query_nodes = new HashSet<PhylogenyNode>();
11435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11438             if ( s0.match( query_nodes ) ) {
11439                 return false;
11440             }
11441             //
11442             query_nodes = new HashSet<PhylogenyNode>();
11443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11445             if ( s0.match( query_nodes ) ) {
11446                 return false;
11447             }
11448             //
11449             query_nodes = new HashSet<PhylogenyNode>();
11450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11452             if ( s0.match( query_nodes ) ) {
11453                 return false;
11454             }
11455             //
11456             query_nodes = new HashSet<PhylogenyNode>();
11457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11458             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11459             if ( s0.match( query_nodes ) ) {
11460                 return false;
11461             }
11462             //
11463             query_nodes = new HashSet<PhylogenyNode>();
11464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11466             if ( s0.match( query_nodes ) ) {
11467                 return false;
11468             }
11469             //
11470             query_nodes = new HashSet<PhylogenyNode>();
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11473             if ( s0.match( query_nodes ) ) {
11474                 return false;
11475             }
11476             //
11477             query_nodes = new HashSet<PhylogenyNode>();
11478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11480             if ( s0.match( query_nodes ) ) {
11481                 return false;
11482             }
11483             //
11484             query_nodes = new HashSet<PhylogenyNode>();
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11488             if ( s0.match( query_nodes ) ) {
11489                 return false;
11490             }
11491             //
11492             query_nodes = new HashSet<PhylogenyNode>();
11493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11496             if ( s0.match( query_nodes ) ) {
11497                 return false;
11498             }
11499             //
11500             query_nodes = new HashSet<PhylogenyNode>();
11501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11504             if ( s0.match( query_nodes ) ) {
11505                 return false;
11506             }
11507             //
11508             query_nodes = new HashSet<PhylogenyNode>();
11509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11513             if ( s0.match( query_nodes ) ) {
11514                 return false;
11515             }
11516             /////////
11517             //            query_nodes = new HashSet<PhylogenyNode>();
11518             //            query_nodes.add( new PhylogenyNode( "X" ) );
11519             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11520             //            query_nodes.add( new PhylogenyNode( "A" ) );
11521             //            query_nodes.add( new PhylogenyNode( "B" ) );
11522             //            query_nodes.add( new PhylogenyNode( "C" ) );
11523             //            query_nodes.add( new PhylogenyNode( "D" ) );
11524             //            query_nodes.add( new PhylogenyNode( "E" ) );
11525             //            query_nodes.add( new PhylogenyNode( "F" ) );
11526             //            query_nodes.add( new PhylogenyNode( "G" ) );
11527             //            if ( !s0.match( query_nodes ) ) {
11528             //                return false;
11529             //            }
11530             //            query_nodes = new HashSet<PhylogenyNode>();
11531             //            query_nodes.add( new PhylogenyNode( "X" ) );
11532             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11533             //            query_nodes.add( new PhylogenyNode( "A" ) );
11534             //            query_nodes.add( new PhylogenyNode( "B" ) );
11535             //            query_nodes.add( new PhylogenyNode( "C" ) );
11536             //            if ( !s0.match( query_nodes ) ) {
11537             //                return false;
11538             //            }
11539             //            //
11540             //            query_nodes = new HashSet<PhylogenyNode>();
11541             //            query_nodes.add( new PhylogenyNode( "X" ) );
11542             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11543             //            query_nodes.add( new PhylogenyNode( "D" ) );
11544             //            query_nodes.add( new PhylogenyNode( "E" ) );
11545             //            query_nodes.add( new PhylogenyNode( "F" ) );
11546             //            query_nodes.add( new PhylogenyNode( "G" ) );
11547             //            if ( !s0.match( query_nodes ) ) {
11548             //                return false;
11549             //            }
11550             //            //
11551             //            query_nodes = new HashSet<PhylogenyNode>();
11552             //            query_nodes.add( new PhylogenyNode( "X" ) );
11553             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11554             //            query_nodes.add( new PhylogenyNode( "A" ) );
11555             //            query_nodes.add( new PhylogenyNode( "B" ) );
11556             //            query_nodes.add( new PhylogenyNode( "C" ) );
11557             //            query_nodes.add( new PhylogenyNode( "D" ) );
11558             //            if ( !s0.match( query_nodes ) ) {
11559             //                return false;
11560             //            }
11561             //            //
11562             //            query_nodes = new HashSet<PhylogenyNode>();
11563             //            query_nodes.add( new PhylogenyNode( "X" ) );
11564             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11565             //            query_nodes.add( new PhylogenyNode( "E" ) );
11566             //            query_nodes.add( new PhylogenyNode( "F" ) );
11567             //            query_nodes.add( new PhylogenyNode( "G" ) );
11568             //            if ( !s0.match( query_nodes ) ) {
11569             //                return false;
11570             //            }
11571             //            //
11572             //            query_nodes = new HashSet<PhylogenyNode>();
11573             //            query_nodes.add( new PhylogenyNode( "X" ) );
11574             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11575             //            query_nodes.add( new PhylogenyNode( "F" ) );
11576             //            query_nodes.add( new PhylogenyNode( "G" ) );
11577             //            if ( !s0.match( query_nodes ) ) {
11578             //                return false;
11579             //            }
11580             //
11581             query_nodes = new HashSet<PhylogenyNode>();
11582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11584             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11585             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11586             if ( s0.match( query_nodes ) ) {
11587                 return false;
11588             }
11589             //
11590             query_nodes = new HashSet<PhylogenyNode>();
11591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11592             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11593             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11595             if ( s0.match( query_nodes ) ) {
11596                 return false;
11597             }
11598             ///////////////////////////
11599             //
11600             query_nodes = new HashSet<PhylogenyNode>();
11601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11605             if ( s0.match( query_nodes ) ) {
11606                 return false;
11607             }
11608             //
11609             query_nodes = new HashSet<PhylogenyNode>();
11610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11614             if ( s0.match( query_nodes ) ) {
11615                 return false;
11616             }
11617             //
11618             query_nodes = new HashSet<PhylogenyNode>();
11619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11623             if ( s0.match( query_nodes ) ) {
11624                 return false;
11625             }
11626             //
11627             query_nodes = new HashSet<PhylogenyNode>();
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11632             if ( s0.match( query_nodes ) ) {
11633                 return false;
11634             }
11635             //
11636             query_nodes = new HashSet<PhylogenyNode>();
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11641             if ( s0.match( query_nodes ) ) {
11642                 return false;
11643             }
11644             //
11645             query_nodes = new HashSet<PhylogenyNode>();
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11649             if ( s0.match( query_nodes ) ) {
11650                 return false;
11651             }
11652             //
11653             query_nodes = new HashSet<PhylogenyNode>();
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11659             if ( s0.match( query_nodes ) ) {
11660                 return false;
11661             }
11662             //
11663             query_nodes = new HashSet<PhylogenyNode>();
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11669             if ( s0.match( query_nodes ) ) {
11670                 return false;
11671             }
11672             //
11673             query_nodes = new HashSet<PhylogenyNode>();
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11679             if ( s0.match( query_nodes ) ) {
11680                 return false;
11681             }
11682             //
11683             query_nodes = new HashSet<PhylogenyNode>();
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11690             if ( s0.match( query_nodes ) ) {
11691                 return false;
11692             }
11693         }
11694         catch ( final Exception e ) {
11695             e.printStackTrace();
11696             return false;
11697         }
11698         return true;
11699     }
11700
11701     private static boolean testSplitStrict() {
11702         try {
11703             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11704             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11705             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11706             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11707             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11708             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11709             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11710             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11711             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11712             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11713             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11714             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11717             if ( s0.match( query_nodes ) ) {
11718                 return false;
11719             }
11720             query_nodes = new HashSet<PhylogenyNode>();
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11728             if ( !s0.match( query_nodes ) ) {
11729                 return false;
11730             }
11731             //
11732             query_nodes = new HashSet<PhylogenyNode>();
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11736             if ( !s0.match( query_nodes ) ) {
11737                 return false;
11738             }
11739             //
11740             query_nodes = new HashSet<PhylogenyNode>();
11741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11745             if ( !s0.match( query_nodes ) ) {
11746                 return false;
11747             }
11748             //
11749             query_nodes = new HashSet<PhylogenyNode>();
11750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11754             if ( !s0.match( query_nodes ) ) {
11755                 return false;
11756             }
11757             //
11758             query_nodes = new HashSet<PhylogenyNode>();
11759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11762             if ( !s0.match( query_nodes ) ) {
11763                 return false;
11764             }
11765             //
11766             query_nodes = new HashSet<PhylogenyNode>();
11767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11769             if ( !s0.match( query_nodes ) ) {
11770                 return false;
11771             }
11772             //
11773             query_nodes = new HashSet<PhylogenyNode>();
11774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11779             if ( !s0.match( query_nodes ) ) {
11780                 return false;
11781             }
11782             //
11783             query_nodes = new HashSet<PhylogenyNode>();
11784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11787             if ( !s0.match( query_nodes ) ) {
11788                 return false;
11789             }
11790             //
11791             query_nodes = new HashSet<PhylogenyNode>();
11792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11796             if ( !s0.match( query_nodes ) ) {
11797                 return false;
11798             }
11799             //
11800             query_nodes = new HashSet<PhylogenyNode>();
11801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11803             if ( s0.match( query_nodes ) ) {
11804                 return false;
11805             }
11806             //
11807             query_nodes = new HashSet<PhylogenyNode>();
11808             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11812             if ( s0.match( query_nodes ) ) {
11813                 return false;
11814             }
11815             //
11816             query_nodes = new HashSet<PhylogenyNode>();
11817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11822             if ( s0.match( query_nodes ) ) {
11823                 return false;
11824             }
11825             //
11826             query_nodes = new HashSet<PhylogenyNode>();
11827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11830             if ( s0.match( query_nodes ) ) {
11831                 return false;
11832             }
11833             //
11834             query_nodes = new HashSet<PhylogenyNode>();
11835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11837             if ( s0.match( query_nodes ) ) {
11838                 return false;
11839             }
11840             //
11841             query_nodes = new HashSet<PhylogenyNode>();
11842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11844             if ( s0.match( query_nodes ) ) {
11845                 return false;
11846             }
11847             //
11848             query_nodes = new HashSet<PhylogenyNode>();
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11851             if ( s0.match( query_nodes ) ) {
11852                 return false;
11853             }
11854             //
11855             query_nodes = new HashSet<PhylogenyNode>();
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11858             if ( s0.match( query_nodes ) ) {
11859                 return false;
11860             }
11861             //
11862             query_nodes = new HashSet<PhylogenyNode>();
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11865             if ( s0.match( query_nodes ) ) {
11866                 return false;
11867             }
11868             //
11869             query_nodes = new HashSet<PhylogenyNode>();
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11872             if ( s0.match( query_nodes ) ) {
11873                 return false;
11874             }
11875             //
11876             query_nodes = new HashSet<PhylogenyNode>();
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11880             if ( s0.match( query_nodes ) ) {
11881                 return false;
11882             }
11883             //
11884             query_nodes = new HashSet<PhylogenyNode>();
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11888             if ( s0.match( query_nodes ) ) {
11889                 return false;
11890             }
11891             //
11892             query_nodes = new HashSet<PhylogenyNode>();
11893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11896             if ( s0.match( query_nodes ) ) {
11897                 return false;
11898             }
11899             //
11900             query_nodes = new HashSet<PhylogenyNode>();
11901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11905             if ( s0.match( query_nodes ) ) {
11906                 return false;
11907             }
11908         }
11909         catch ( final Exception e ) {
11910             e.printStackTrace();
11911             return false;
11912         }
11913         return true;
11914     }
11915
11916     private static boolean testSubtreeDeletion() {
11917         try {
11918             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11919             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11920             t1.deleteSubtree( t1.getNode( "A" ), false );
11921             if ( t1.getNumberOfExternalNodes() != 5 ) {
11922                 return false;
11923             }
11924             t1.toNewHampshireX();
11925             t1.deleteSubtree( t1.getNode( "E" ), false );
11926             if ( t1.getNumberOfExternalNodes() != 4 ) {
11927                 return false;
11928             }
11929             t1.toNewHampshireX();
11930             t1.deleteSubtree( t1.getNode( "F" ), false );
11931             if ( t1.getNumberOfExternalNodes() != 3 ) {
11932                 return false;
11933             }
11934             t1.toNewHampshireX();
11935             t1.deleteSubtree( t1.getNode( "D" ), false );
11936             t1.toNewHampshireX();
11937             if ( t1.getNumberOfExternalNodes() != 3 ) {
11938                 return false;
11939             }
11940             t1.deleteSubtree( t1.getNode( "def" ), false );
11941             t1.toNewHampshireX();
11942             if ( t1.getNumberOfExternalNodes() != 2 ) {
11943                 return false;
11944             }
11945             t1.deleteSubtree( t1.getNode( "B" ), false );
11946             t1.toNewHampshireX();
11947             if ( t1.getNumberOfExternalNodes() != 1 ) {
11948                 return false;
11949             }
11950             t1.deleteSubtree( t1.getNode( "C" ), false );
11951             t1.toNewHampshireX();
11952             if ( t1.getNumberOfExternalNodes() != 1 ) {
11953                 return false;
11954             }
11955             t1.deleteSubtree( t1.getNode( "abc" ), false );
11956             t1.toNewHampshireX();
11957             if ( t1.getNumberOfExternalNodes() != 1 ) {
11958                 return false;
11959             }
11960             t1.deleteSubtree( t1.getNode( "r" ), false );
11961             if ( t1.getNumberOfExternalNodes() != 0 ) {
11962                 return false;
11963             }
11964             if ( !t1.isEmpty() ) {
11965                 return false;
11966             }
11967             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11968             t2.deleteSubtree( t2.getNode( "A" ), false );
11969             t2.toNewHampshireX();
11970             if ( t2.getNumberOfExternalNodes() != 5 ) {
11971                 return false;
11972             }
11973             t2.deleteSubtree( t2.getNode( "abc" ), false );
11974             t2.toNewHampshireX();
11975             if ( t2.getNumberOfExternalNodes() != 3 ) {
11976                 return false;
11977             }
11978             t2.deleteSubtree( t2.getNode( "def" ), false );
11979             t2.toNewHampshireX();
11980             if ( t2.getNumberOfExternalNodes() != 1 ) {
11981                 return false;
11982             }
11983         }
11984         catch ( final Exception e ) {
11985             e.printStackTrace( System.out );
11986             return false;
11987         }
11988         return true;
11989     }
11990
11991     private static boolean testSupportCount() {
11992         try {
11993             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11994             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11995             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11996                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11997                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11998                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11999                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12000                                                               new NHXParser() );
12001             SupportCount.count( t0_1, phylogenies_1, true, false );
12002             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12003             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12004                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12005                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12006                                                                       + "(((((A,B),C),D),E),(F,G))"
12007                                                                       + "(((((A,B),C),D),E),(F,G))"
12008                                                                       + "(((((A,B),C),D),E),(F,G))"
12009                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12010                                                                       + "(((((A,B),C),D),E),(F,G))"
12011                                                                       + "((((((A,B),C),D),E),F),G)"
12012                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12013                                                               new NHXParser() );
12014             SupportCount.count( t0_2, phylogenies_2, true, false );
12015             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12016             while ( it.hasNext() ) {
12017                 final PhylogenyNode n = it.next();
12018                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12019                     return false;
12020                 }
12021             }
12022             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12023             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12024                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12025             SupportCount.count( t0_3, phylogenies_3, true, false );
12026             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12027             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12028                 return false;
12029             }
12030             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12031                 return false;
12032             }
12033             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12034                 return false;
12035             }
12036             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12037                 return false;
12038             }
12039             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12040                 return false;
12041             }
12042             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12043                 return false;
12044             }
12045             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12046                 return false;
12047             }
12048             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12049                 return false;
12050             }
12051             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12052                 return false;
12053             }
12054             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12055                 return false;
12056             }
12057             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12058             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12059                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12060             SupportCount.count( t0_4, phylogenies_4, true, false );
12061             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12062             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12063                 return false;
12064             }
12065             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12066                 return false;
12067             }
12068             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12069                 return false;
12070             }
12071             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12072                 return false;
12073             }
12074             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12075                 return false;
12076             }
12077             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12078                 return false;
12079             }
12080             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12081                 return false;
12082             }
12083             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12084                 return false;
12085             }
12086             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12087                 return false;
12088             }
12089             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12090                 return false;
12091             }
12092             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12093             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12094             double d = SupportCount.compare( b1, a, true, true, true );
12095             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12096                 return false;
12097             }
12098             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12099             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12100             d = SupportCount.compare( b2, a, true, true, true );
12101             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12102                 return false;
12103             }
12104             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12105             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12106             d = SupportCount.compare( b3, a, true, true, true );
12107             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12108                 return false;
12109             }
12110             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12111             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12112             d = SupportCount.compare( b4, a, true, true, false );
12113             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12114                 return false;
12115             }
12116         }
12117         catch ( final Exception e ) {
12118             e.printStackTrace( System.out );
12119             return false;
12120         }
12121         return true;
12122     }
12123
12124     private static boolean testSupportTransfer() {
12125         try {
12126             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12127             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)",
12128                                                  new NHXParser() )[ 0 ];
12129             final Phylogeny p2 = factory
12130                     .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 ];
12131             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12132                 return false;
12133             }
12134             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12135                 return false;
12136             }
12137             support_transfer.moveBranchLengthsToBootstrap( p1 );
12138             support_transfer.transferSupportValues( p1, p2 );
12139             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12140                 return false;
12141             }
12142             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12143                 return false;
12144             }
12145             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12146                 return false;
12147             }
12148             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12149                 return false;
12150             }
12151             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12152                 return false;
12153             }
12154             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12155                 return false;
12156             }
12157             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12158                 return false;
12159             }
12160             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12161                 return false;
12162             }
12163         }
12164         catch ( final Exception e ) {
12165             e.printStackTrace( System.out );
12166             return false;
12167         }
12168         return true;
12169     }
12170
12171     private static boolean testTaxonomyExtraction() {
12172         try {
12173             final PhylogenyNode n0 = PhylogenyNode
12174                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12175             if ( n0.getNodeData().isHasTaxonomy() ) {
12176                 return false;
12177             }
12178             final PhylogenyNode n1 = PhylogenyNode
12179                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12180             if ( n1.getNodeData().isHasTaxonomy() ) {
12181                 System.out.println( n1.toString() );
12182                 return false;
12183             }
12184             final PhylogenyNode n2x = PhylogenyNode
12185                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12186             if ( n2x.getNodeData().isHasTaxonomy() ) {
12187                 return false;
12188             }
12189             final PhylogenyNode n3 = PhylogenyNode
12190                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12191             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12192                 System.out.println( n3.toString() );
12193                 return false;
12194             }
12195             final PhylogenyNode n4 = PhylogenyNode
12196                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12197             if ( n4.getNodeData().isHasTaxonomy() ) {
12198                 System.out.println( n4.toString() );
12199                 return false;
12200             }
12201             final PhylogenyNode n5 = PhylogenyNode
12202                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12203             if ( n5.getNodeData().isHasTaxonomy() ) {
12204                 System.out.println( n5.toString() );
12205                 return false;
12206             }
12207             final PhylogenyNode n6 = PhylogenyNode
12208                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12209             if ( n6.getNodeData().isHasTaxonomy() ) {
12210                 System.out.println( n6.toString() );
12211                 return false;
12212             }
12213             final PhylogenyNode n7 = PhylogenyNode
12214                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12215             if ( n7.getNodeData().isHasTaxonomy() ) {
12216                 System.out.println( n7.toString() );
12217                 return false;
12218             }
12219             final PhylogenyNode n8 = PhylogenyNode
12220                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12221             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12222                 System.out.println( n8.toString() );
12223                 return false;
12224             }
12225             final PhylogenyNode n9 = PhylogenyNode
12226                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12227             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12228                 System.out.println( n9.toString() );
12229                 return false;
12230             }
12231             final PhylogenyNode n10x = PhylogenyNode
12232                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12233             if ( n10x.getNodeData().isHasTaxonomy() ) {
12234                 System.out.println( n10x.toString() );
12235                 return false;
12236             }
12237             final PhylogenyNode n10xx = PhylogenyNode
12238                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12239             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12240                 System.out.println( n10xx.toString() );
12241                 return false;
12242             }
12243             final PhylogenyNode n10 = PhylogenyNode
12244                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12245             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12246                 System.out.println( n10.toString() );
12247                 return false;
12248             }
12249             final PhylogenyNode n11 = PhylogenyNode
12250                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12251             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12252                 System.out.println( n11.toString() );
12253                 return false;
12254             }
12255             final PhylogenyNode n12 = PhylogenyNode
12256                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12257                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12258             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12259                 System.out.println( n12.toString() );
12260                 return false;
12261             }
12262             final PhylogenyNode n13 = PhylogenyNode
12263                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12264             if ( n13.getNodeData().isHasTaxonomy() ) {
12265                 System.out.println( n13.toString() );
12266                 return false;
12267             }
12268             final PhylogenyNode n14 = PhylogenyNode
12269                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12270             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12271                 System.out.println( n14.toString() );
12272                 return false;
12273             }
12274             final PhylogenyNode n15 = PhylogenyNode
12275                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12276             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12277                 System.out.println( n15.toString() );
12278                 return false;
12279             }
12280             final PhylogenyNode n16 = PhylogenyNode
12281                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12282             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12283                 System.out.println( n16.toString() );
12284                 return false;
12285             }
12286             final PhylogenyNode n17 = PhylogenyNode
12287                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12288             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12289                 System.out.println( n17.toString() );
12290                 return false;
12291             }
12292             //
12293             final PhylogenyNode n18 = PhylogenyNode
12294                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12295             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12296                 System.out.println( n18.toString() );
12297                 return false;
12298             }
12299             final PhylogenyNode n19 = PhylogenyNode
12300                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12301                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12302             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12303                 System.out.println( n19.toString() );
12304                 return false;
12305             }
12306             final PhylogenyNode n20 = PhylogenyNode
12307                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12308             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12309                 System.out.println( n20.toString() );
12310                 return false;
12311             }
12312             final PhylogenyNode n21 = PhylogenyNode
12313                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12314                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12315             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12316                 System.out.println( n21.toString() );
12317                 return false;
12318             }
12319             final PhylogenyNode n22 = PhylogenyNode
12320                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12321                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12322             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12323                 System.out.println( n22.toString() );
12324                 return false;
12325             }
12326             final PhylogenyNode n23 = PhylogenyNode
12327                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12328                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12329             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12330                 System.out.println( n23.toString() );
12331                 return false;
12332             }
12333             final PhylogenyNode n24 = PhylogenyNode
12334                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12335             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12336                 System.out.println( n24.toString() );
12337                 return false;
12338             }
12339             //
12340             final PhylogenyNode n25 = PhylogenyNode
12341                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12342                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12343             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12344                 System.out.println( n25.toString() );
12345                 return false;
12346             }
12347             final PhylogenyNode n26 = PhylogenyNode
12348                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12349                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12350             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12351                 System.out.println( n26.toString() );
12352                 return false;
12353             }
12354             final PhylogenyNode n27 = PhylogenyNode
12355                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12356             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12357                 System.out.println( n27.toString() );
12358                 return false;
12359             }
12360         }
12361         catch ( final Exception e ) {
12362             e.printStackTrace( System.out );
12363             return false;
12364         }
12365         return true;
12366     }
12367
12368     private static boolean testTreeCopy() {
12369         try {
12370             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12371             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12372             final Phylogeny t1 = t0.copy();
12373             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12374                 return false;
12375             }
12376             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12377                 return false;
12378             }
12379             t0.deleteSubtree( t0.getNode( "c" ), true );
12380             t0.deleteSubtree( t0.getNode( "a" ), true );
12381             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12382             t0.getNode( "b" ).setName( "Bee" );
12383             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12384                 return false;
12385             }
12386             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12387                 return false;
12388             }
12389             t0.deleteSubtree( t0.getNode( "e" ), true );
12390             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12391             t0.deleteSubtree( t0.getNode( "d" ), true );
12392             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12393                 return false;
12394             }
12395         }
12396         catch ( final Exception e ) {
12397             e.printStackTrace();
12398             return false;
12399         }
12400         return true;
12401     }
12402
12403     private static boolean testTreeMethods() {
12404         try {
12405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12406             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12407             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12408             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12409                 System.out.println( t0.toNewHampshireX() );
12410                 return false;
12411             }
12412             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12413             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12414             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12415                 return false;
12416             }
12417             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12418                 return false;
12419             }
12420             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12421                 return false;
12422             }
12423         }
12424         catch ( final Exception e ) {
12425             e.printStackTrace( System.out );
12426             return false;
12427         }
12428         return true;
12429     }
12430
12431     private static boolean testUniprotEntryRetrieval() {
12432         try {
12433             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12434             if ( !entry.getAccession().equals( "P12345" ) ) {
12435                 return false;
12436             }
12437             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12438                 return false;
12439             }
12440             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12441                 return false;
12442             }
12443             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12444                 return false;
12445             }
12446             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12447                 return false;
12448             }
12449             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12450                 return false;
12451             }
12452         }
12453         catch ( final IOException e ) {
12454             System.out.println();
12455             System.out.println( "the following might be due to absence internet connection:" );
12456             e.printStackTrace( System.out );
12457             return true;
12458         }
12459         catch ( final Exception e ) {
12460             return false;
12461         }
12462         return true;
12463     }
12464
12465     private static boolean testUniprotTaxonomySearch() {
12466         try {
12467             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12468                                                                                                  10 );
12469             if ( results.size() != 1 ) {
12470                 return false;
12471             }
12472             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12473                 return false;
12474             }
12475             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12476                 return false;
12477             }
12478             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12479                 return false;
12480             }
12481             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12482                 return false;
12483             }
12484             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12485                 return false;
12486             }
12487             results = null;
12488             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12489             if ( results.size() != 1 ) {
12490                 return false;
12491             }
12492             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12493                 return false;
12494             }
12495             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12496                 return false;
12497             }
12498             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12499                 return false;
12500             }
12501             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12502                 return false;
12503             }
12504             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12505                 return false;
12506             }
12507             results = null;
12508             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12509             if ( results.size() != 1 ) {
12510                 return false;
12511             }
12512             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12513                 return false;
12514             }
12515             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12516                 return false;
12517             }
12518             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12519                 return false;
12520             }
12521             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12522                 return false;
12523             }
12524             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12525                 return false;
12526             }
12527             results = null;
12528             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12529             if ( results.size() != 1 ) {
12530                 return false;
12531             }
12532             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12533                 return false;
12534             }
12535             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12536                 return false;
12537             }
12538             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12539                 return false;
12540             }
12541             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12542                 return false;
12543             }
12544             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12545                 return false;
12546             }
12547             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12548                 return false;
12549             }
12550             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12551                 return false;
12552             }
12553             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12554                     .equals( "Nematostella vectensis" ) ) {
12555                 System.out.println( results.get( 0 ).getLineage() );
12556                 return false;
12557             }
12558             //
12559             results = null;
12560             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12561             if ( results.size() != 1 ) {
12562                 return false;
12563             }
12564             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12565                 return false;
12566             }
12567             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12568                 return false;
12569             }
12570             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12571                 return false;
12572             }
12573             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12574                 return false;
12575             }
12576             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12577                 return false;
12578             }
12579             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12580                     .equals( "Xenopus tropicalis" ) ) {
12581                 System.out.println( results.get( 0 ).getLineage() );
12582                 return false;
12583             }
12584             //
12585             results = null;
12586             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12587             if ( results.size() != 1 ) {
12588                 return false;
12589             }
12590             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12591                 return false;
12592             }
12593             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12594                 return false;
12595             }
12596             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12597                 return false;
12598             }
12599             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12600                 return false;
12601             }
12602             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12603                 return false;
12604             }
12605             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12606                     .equals( "Xenopus tropicalis" ) ) {
12607                 System.out.println( results.get( 0 ).getLineage() );
12608                 return false;
12609             }
12610             //
12611             results = null;
12612             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12613             if ( results.size() != 1 ) {
12614                 return false;
12615             }
12616             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12617                 return false;
12618             }
12619             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12620                 return false;
12621             }
12622             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12623                 return false;
12624             }
12625             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12626                 return false;
12627             }
12628             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12629                 return false;
12630             }
12631             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12632                     .equals( "Xenopus tropicalis" ) ) {
12633                 System.out.println( results.get( 0 ).getLineage() );
12634                 return false;
12635             }
12636         }
12637         catch ( final IOException e ) {
12638             System.out.println();
12639             System.out.println( "the following might be due to absence internet connection:" );
12640             e.printStackTrace( System.out );
12641             return true;
12642         }
12643         catch ( final Exception e ) {
12644             return false;
12645         }
12646         return true;
12647     }
12648
12649     private static boolean testWabiTxSearch() {
12650         try {
12651             String result = "";
12652             result = TxSearch.searchSimple( "nematostella" );
12653             result = TxSearch.getTxId( "nematostella" );
12654             if ( !result.equals( "45350" ) ) {
12655                 return false;
12656             }
12657             result = TxSearch.getTxName( "45350" );
12658             if ( !result.equals( "Nematostella" ) ) {
12659                 return false;
12660             }
12661             result = TxSearch.getTxId( "nematostella vectensis" );
12662             if ( !result.equals( "45351" ) ) {
12663                 return false;
12664             }
12665             result = TxSearch.getTxName( "45351" );
12666             if ( !result.equals( "Nematostella vectensis" ) ) {
12667                 return false;
12668             }
12669             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12670             if ( !result.equals( "536089" ) ) {
12671                 return false;
12672             }
12673             result = TxSearch.getTxName( "536089" );
12674             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12675                 return false;
12676             }
12677             final List<String> queries = new ArrayList<String>();
12678             queries.add( "Campylobacter coli" );
12679             queries.add( "Escherichia coli" );
12680             queries.add( "Arabidopsis" );
12681             queries.add( "Trichoplax" );
12682             queries.add( "Samanea saman" );
12683             queries.add( "Kluyveromyces marxianus" );
12684             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12685             queries.add( "Bornavirus parrot/PDD/2008" );
12686             final List<RANKS> ranks = new ArrayList<RANKS>();
12687             ranks.add( RANKS.SUPERKINGDOM );
12688             ranks.add( RANKS.KINGDOM );
12689             ranks.add( RANKS.FAMILY );
12690             ranks.add( RANKS.GENUS );
12691             ranks.add( RANKS.TRIBE );
12692             result = TxSearch.searchLineage( queries, ranks );
12693             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12694             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12695         }
12696         catch ( final Exception e ) {
12697             System.out.println();
12698             System.out.println( "the following might be due to absence internet connection:" );
12699             e.printStackTrace( System.out );
12700             return false;
12701         }
12702         return true;
12703     }
12704 }