inprogress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.net.URL;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.SortedSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.archaeopteryx.webservices.WebserviceUtil;
45 import org.forester.development.DevelopmentTools;
46 import org.forester.evoinference.TestPhylogenyReconstruction;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
49 import org.forester.go.TestGo;
50 import org.forester.io.parsers.FastaParser;
51 import org.forester.io.parsers.GeneralMsaParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
54 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
55 import org.forester.io.parsers.nexus.NexusCharactersParser;
56 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
57 import org.forester.io.parsers.nhx.NHXParser;
58 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
59 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
60 import org.forester.io.parsers.tol.TolParser;
61 import org.forester.io.parsers.util.ParserUtils;
62 import org.forester.io.writers.PhylogenyWriter;
63 import org.forester.io.writers.SequenceWriter;
64 import org.forester.msa.BasicMsa;
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         if ( PERFORM_DB_TESTS ) {
904             System.out.print( "Uniprot Entry Retrieval: " );
905             if ( Test.testUniprotEntryRetrieval() ) {
906                 System.out.println( "OK." );
907                 succeeded++;
908             }
909             else {
910                 System.out.println( "failed." );
911                 failed++;
912             }
913             System.out.print( "Ebi Entry Retrieval: " );
914             if ( Test.testEbiEntryRetrieval() ) {
915                 System.out.println( "OK." );
916                 succeeded++;
917             }
918             else {
919                 System.out.println( "failed." );
920                 failed++;
921             }
922             System.out.print( "Sequence DB tools 2: " );
923             if ( testSequenceDbWsTools2() ) {
924                 System.out.println( "OK." );
925                 succeeded++;
926             }
927             else {
928                 System.out.println( "failed." );
929                 failed++;
930                 System.exit( -1 );
931             }
932             System.out.print( "Uniprot Taxonomy Search: " );
933             if ( Test.testUniprotTaxonomySearch() ) {
934                 System.out.println( "OK." );
935                 succeeded++;
936             }
937             else {
938                 System.out.println( "failed." );
939                 failed++;
940             }
941         }
942         if ( PERFORM_WEB_TREE_ACCESS ) {
943             System.out.print( "NHX parsing from URL: " );
944             if ( Test.testNHXparsingFromURL() ) {
945                 System.out.println( "OK." );
946                 succeeded++;
947             }
948             else {
949                 System.out.println( "failed." );
950                 failed++;
951             }
952             System.out.print( "phyloXML parsing from URL: " );
953             if ( Test.testPhyloXMLparsingFromURL() ) {
954                 System.out.println( "OK." );
955                 succeeded++;
956             }
957             else {
958                 System.out.println( "failed." );
959                 failed++;
960             }
961             System.out.print( "TreeBase acccess: " );
962             if ( Test.testTreeBaseReading() ) {
963                 System.out.println( "OK." );
964                 succeeded++;
965             }
966             else {
967                 System.out.println( "failed." );
968                 failed++;
969             }
970             //
971             System.out.print( "ToL access: " );
972             if ( Test.testToLReading() ) {
973                 System.out.println( "OK." );
974                 succeeded++;
975             }
976             else {
977                 System.out.println( "failed." );
978                 failed++;
979             }
980             //
981             System.out.print( "TreeFam access: " );
982             if ( Test.testTreeFamReading() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990             //
991             //
992             System.out.print( "Pfam tree access: " );
993             if ( Test.testPfamTreeReading() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001         }
1002         System.out.println();
1003         final Runtime rt = java.lang.Runtime.getRuntime();
1004         final long free_memory = rt.freeMemory() / 1000000;
1005         final long total_memory = rt.totalMemory() / 1000000;
1006         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1007                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1008         System.out.println();
1009         System.out.println( "Successful tests: " + succeeded );
1010         System.out.println( "Failed     tests: " + failed );
1011         System.out.println();
1012         if ( failed < 1 ) {
1013             System.out.println( "OK." );
1014         }
1015         else {
1016             System.out.println( "Not OK." );
1017         }
1018     }
1019
1020     public static boolean testEngulfingOverlapRemoval() {
1021         try {
1022             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1023             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1024             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1025             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1026             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1027             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1028             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1029             final List<Boolean> covered = new ArrayList<Boolean>();
1030             covered.add( true ); // 0
1031             covered.add( false ); // 1
1032             covered.add( true ); // 2
1033             covered.add( false ); // 3
1034             covered.add( true ); // 4
1035             covered.add( true ); // 5
1036             covered.add( false ); // 6
1037             covered.add( true ); // 7
1038             covered.add( true ); // 8
1039             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1040                 return false;
1041             }
1042             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1043                 return false;
1044             }
1045             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1046                 return false;
1047             }
1048             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1049                 return false;
1050             }
1051             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1052                 return false;
1053             }
1054             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1055                 return false;
1056             }
1057             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1058                 return false;
1059             }
1060             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1061             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1062             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1063             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1064             abc.addProteinDomain( a );
1065             abc.addProteinDomain( b );
1066             abc.addProteinDomain( c );
1067             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1068             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1069             if ( abc.getNumberOfProteinDomains() != 3 ) {
1070                 return false;
1071             }
1072             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1073                 return false;
1074             }
1075             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1076                 return false;
1077             }
1078             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1079                 return false;
1080             }
1081             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1082                 return false;
1083             }
1084             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1085             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1086             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1087             final Protein def = new BasicProtein( "def", "nemve", 0 );
1088             def.addProteinDomain( d );
1089             def.addProteinDomain( e );
1090             def.addProteinDomain( f );
1091             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1092             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1093             if ( def.getNumberOfProteinDomains() != 3 ) {
1094                 return false;
1095             }
1096             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1097                 return false;
1098             }
1099             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1100                 return false;
1101             }
1102             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1103                 return false;
1104             }
1105             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1106                 return false;
1107             }
1108             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1109                 return false;
1110             }
1111         }
1112         catch ( final Exception e ) {
1113             e.printStackTrace( System.out );
1114             return false;
1115         }
1116         return true;
1117     }
1118
1119     public static final boolean testNHXparsingFromURL() {
1120         try {
1121             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1122             final URL u = new URL( s );
1123             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1124             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1125             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1126                 return false;
1127             }
1128             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1129                 System.out.println( phys[ 0 ].toNewHampshire() );
1130                 return false;
1131             }
1132             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1133                 System.out.println( phys[ 1 ].toNewHampshire() );
1134                 return false;
1135             }
1136             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1137             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1138                 return false;
1139             }
1140             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1141                 System.out.println( phys2[ 0 ].toNewHampshire() );
1142                 return false;
1143             }
1144             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1145             final NHXParser p = new NHXParser();
1146             final URL u2 = new URL( s );
1147             p.setSource( u2 );
1148             if ( !p.hasNext() ) {
1149                 return false;
1150             }
1151             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1152                 return false;
1153             }
1154             if ( !p.hasNext() ) {
1155                 return false;
1156             }
1157             p.reset();
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.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
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         }
1178         catch ( final Exception e ) {
1179             e.printStackTrace();
1180         }
1181         return true;
1182     }
1183
1184     public static boolean testOverlapRemoval() {
1185         try {
1186             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1187             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1188             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1189             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1190             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1191             final List<Boolean> covered = new ArrayList<Boolean>();
1192             covered.add( true ); // 0
1193             covered.add( false ); // 1
1194             covered.add( true ); // 2
1195             covered.add( false ); // 3
1196             covered.add( true ); // 4
1197             covered.add( true ); // 5
1198             covered.add( false ); // 6
1199             covered.add( true ); // 7
1200             covered.add( true ); // 8
1201             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1202                 return false;
1203             }
1204             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1205                 return false;
1206             }
1207             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1208                 return false;
1209             }
1210             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1211                 return false;
1212             }
1213             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1214                 return false;
1215             }
1216             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1217             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1218             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1219             ab.addProteinDomain( a );
1220             ab.addProteinDomain( b );
1221             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1222             if ( ab.getNumberOfProteinDomains() != 2 ) {
1223                 return false;
1224             }
1225             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1226                 return false;
1227             }
1228             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1229                 return false;
1230             }
1231             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1232             if ( ab.getNumberOfProteinDomains() != 2 ) {
1233                 return false;
1234             }
1235             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1236                 return false;
1237             }
1238             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1239             final Domain d = new BasicDomain( "d",
1240                                               ( short ) 10000,
1241                                               ( short ) 10500,
1242                                               ( short ) 1,
1243                                               ( short ) 1,
1244                                               0.0000001,
1245                                               1 );
1246             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1247             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1248             cde.addProteinDomain( c );
1249             cde.addProteinDomain( d );
1250             cde.addProteinDomain( e );
1251             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1252             if ( cde.getNumberOfProteinDomains() != 3 ) {
1253                 return false;
1254             }
1255             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1256                 return false;
1257             }
1258             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1259             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1260             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1261             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1262             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1263             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1264             fghi.addProteinDomain( f );
1265             fghi.addProteinDomain( g );
1266             fghi.addProteinDomain( h );
1267             fghi.addProteinDomain( i );
1268             fghi.addProteinDomain( i );
1269             fghi.addProteinDomain( i );
1270             fghi.addProteinDomain( i2 );
1271             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1272             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1273                 return false;
1274             }
1275             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1276                 return false;
1277             }
1278             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1279                 return false;
1280             }
1281             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1282             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1283                 return false;
1284             }
1285             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1286                 return false;
1287             }
1288             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1289             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1290             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1291             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1292             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1293             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1294             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1295             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1296             jklm.addProteinDomain( j );
1297             jklm.addProteinDomain( k );
1298             jklm.addProteinDomain( l );
1299             jklm.addProteinDomain( m );
1300             jklm.addProteinDomain( m0 );
1301             jklm.addProteinDomain( m1 );
1302             jklm.addProteinDomain( m2 );
1303             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1304             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1305                 return false;
1306             }
1307             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1308                 return false;
1309             }
1310             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1311                 return false;
1312             }
1313             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1314             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1315                 return false;
1316             }
1317             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1318                 return false;
1319             }
1320             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1321             final Protein od = new BasicProtein( "od", "varanus", 0 );
1322             od.addProteinDomain( only );
1323             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1324             if ( od.getNumberOfProteinDomains() != 1 ) {
1325                 return false;
1326             }
1327             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1328                 return false;
1329             }
1330         }
1331         catch ( final Exception e ) {
1332             e.printStackTrace( System.out );
1333             return false;
1334         }
1335         return true;
1336     }
1337
1338     public static final boolean testPfamTreeReading() {
1339         try {
1340             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1341             final NHXParser parser = new NHXParser();
1342             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1343             parser.setReplaceUnderscores( false );
1344             parser.setGuessRootedness( true );
1345             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1346             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1347             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1348                 return false;
1349             }
1350             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1351                 return false;
1352             }
1353         }
1354         catch ( final Exception e ) {
1355             e.printStackTrace();
1356         }
1357         return true;
1358     }
1359
1360     public static final boolean testPhyloXMLparsingFromURL() {
1361         try {
1362             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1363             final URL u = new URL( s );
1364             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1365             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1366             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1367                 return false;
1368             }
1369         }
1370         catch ( final Exception e ) {
1371             e.printStackTrace();
1372         }
1373         return true;
1374     }
1375
1376     public static final boolean testToLReading() {
1377         try {
1378             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1380             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1381             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1382                 return false;
1383             }
1384             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1385                 return false;
1386             }
1387             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1388                 return false;
1389             }
1390             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1391                 return false;
1392             }
1393         }
1394         catch ( final Exception e ) {
1395             e.printStackTrace();
1396         }
1397         return true;
1398     }
1399
1400     public static final boolean testTreeBaseReading() {
1401         try {
1402             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1403             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1404             parser.setReplaceUnderscores( true );
1405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1406             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1407             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1408                 return false;
1409             }
1410             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1411             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1412             parser2.setReplaceUnderscores( true );
1413             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1414             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1415             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1416                 return false;
1417             }
1418         }
1419         catch ( final Exception e ) {
1420             e.printStackTrace();
1421         }
1422         return true;
1423     }
1424
1425     public static final boolean testTreeFamReading() {
1426         try {
1427             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1428             final NHXParser parser = new NHXParser();
1429             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1430             parser.setReplaceUnderscores( false );
1431             parser.setGuessRootedness( true );
1432             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1433             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1434             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1435                 return false;
1436             }
1437             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace();
1443         }
1444         return true;
1445     }
1446
1447     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1448         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1449         return p;
1450     }
1451
1452     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1453         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1454     }
1455
1456     private static boolean testAminoAcidSequence() {
1457         try {
1458             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1459             if ( aa1.getLength() != 13 ) {
1460                 return false;
1461             }
1462             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1463                 return false;
1464             }
1465             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1466                 return false;
1467             }
1468             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1469                 return false;
1470             }
1471             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1472             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1473                 return false;
1474             }
1475             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1476             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1477                 return false;
1478             }
1479             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1480             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1481                 return false;
1482             }
1483         }
1484         catch ( final Exception e ) {
1485             e.printStackTrace();
1486             return false;
1487         }
1488         return true;
1489     }
1490
1491     private static boolean testBasicDomain() {
1492         try {
1493             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1494             if ( !pd.getDomainId().equals( "id" ) ) {
1495                 return false;
1496             }
1497             if ( pd.getNumber() != 1 ) {
1498                 return false;
1499             }
1500             if ( pd.getTotalCount() != 4 ) {
1501                 return false;
1502             }
1503             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1504                 return false;
1505             }
1506             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1507             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1508             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1509             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1510             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1511             if ( !a1.equals( a1 ) ) {
1512                 return false;
1513             }
1514             if ( !a1.equals( a1_copy ) ) {
1515                 return false;
1516             }
1517             if ( !a1.equals( a1_equal ) ) {
1518                 return false;
1519             }
1520             if ( !a1.equals( a2 ) ) {
1521                 return false;
1522             }
1523             if ( a1.equals( a3 ) ) {
1524                 return false;
1525             }
1526             if ( a1.compareTo( a1 ) != 0 ) {
1527                 return false;
1528             }
1529             if ( a1.compareTo( a1_copy ) != 0 ) {
1530                 return false;
1531             }
1532             if ( a1.compareTo( a1_equal ) != 0 ) {
1533                 return false;
1534             }
1535             if ( a1.compareTo( a2 ) != 0 ) {
1536                 return false;
1537             }
1538             if ( a1.compareTo( a3 ) == 0 ) {
1539                 return false;
1540             }
1541         }
1542         catch ( final Exception e ) {
1543             e.printStackTrace( System.out );
1544             return false;
1545         }
1546         return true;
1547     }
1548
1549     private static boolean testBasicNodeMethods() {
1550         try {
1551             if ( PhylogenyNode.getNodeCount() != 0 ) {
1552                 return false;
1553             }
1554             final PhylogenyNode n1 = new PhylogenyNode();
1555             final PhylogenyNode n2 = PhylogenyNode
1556                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1557             final PhylogenyNode n3 = PhylogenyNode
1558                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1559             final PhylogenyNode n4 = PhylogenyNode
1560                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1561             if ( n1.isHasAssignedEvent() ) {
1562                 return false;
1563             }
1564             if ( PhylogenyNode.getNodeCount() != 4 ) {
1565                 return false;
1566             }
1567             if ( n3.getIndicator() != 0 ) {
1568                 return false;
1569             }
1570             if ( n3.getNumberOfExternalNodes() != 1 ) {
1571                 return false;
1572             }
1573             if ( !n3.isExternal() ) {
1574                 return false;
1575             }
1576             if ( !n3.isRoot() ) {
1577                 return false;
1578             }
1579             if ( !n4.getName().equals( "n4" ) ) {
1580                 return false;
1581             }
1582         }
1583         catch ( final Exception e ) {
1584             e.printStackTrace( System.out );
1585             return false;
1586         }
1587         return true;
1588     }
1589
1590     private static boolean testBasicPhyloXMLparsing() {
1591         try {
1592             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1593             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1594             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1595                                                               xml_parser );
1596             if ( xml_parser.getErrorCount() > 0 ) {
1597                 System.out.println( xml_parser.getErrorMessages().toString() );
1598                 return false;
1599             }
1600             if ( phylogenies_0.length != 4 ) {
1601                 return false;
1602             }
1603             final Phylogeny t1 = phylogenies_0[ 0 ];
1604             final Phylogeny t2 = phylogenies_0[ 1 ];
1605             final Phylogeny t3 = phylogenies_0[ 2 ];
1606             final Phylogeny t4 = phylogenies_0[ 3 ];
1607             if ( t1.getNumberOfExternalNodes() != 1 ) {
1608                 return false;
1609             }
1610             if ( !t1.isRooted() ) {
1611                 return false;
1612             }
1613             if ( t1.isRerootable() ) {
1614                 return false;
1615             }
1616             if ( !t1.getType().equals( "gene_tree" ) ) {
1617                 return false;
1618             }
1619             if ( t2.getNumberOfExternalNodes() != 2 ) {
1620                 return false;
1621             }
1622             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1623                 return false;
1624             }
1625             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1626                 return false;
1627             }
1628             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1629                 return false;
1630             }
1631             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1632                 return false;
1633             }
1634             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1635                 return false;
1636             }
1637             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1638                 return false;
1639             }
1640             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1641                     .startsWith( "actgtgggggt" ) ) {
1642                 return false;
1643             }
1644             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1645                     .startsWith( "ctgtgatgcat" ) ) {
1646                 return false;
1647             }
1648             if ( t3.getNumberOfExternalNodes() != 4 ) {
1649                 return false;
1650             }
1651             if ( !t1.getName().equals( "t1" ) ) {
1652                 return false;
1653             }
1654             if ( !t2.getName().equals( "t2" ) ) {
1655                 return false;
1656             }
1657             if ( !t3.getName().equals( "t3" ) ) {
1658                 return false;
1659             }
1660             if ( !t4.getName().equals( "t4" ) ) {
1661                 return false;
1662             }
1663             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1664                 return false;
1665             }
1666             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1667                 return false;
1668             }
1669             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1670                 return false;
1671             }
1672             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1673                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1674                 return false;
1675             }
1676             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1677                 return false;
1678             }
1679             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1680                 return false;
1681             }
1682             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1683                 return false;
1684             }
1685             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1686                     .equals( "apoptosis" ) ) {
1687                 return false;
1688             }
1689             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1690                     .equals( "GO:0006915" ) ) {
1691                 return false;
1692             }
1693             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1694                     .equals( "UniProtKB" ) ) {
1695                 return false;
1696             }
1697             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1698                     .equals( "experimental" ) ) {
1699                 return false;
1700             }
1701             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1702                     .equals( "function" ) ) {
1703                 return false;
1704             }
1705             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1706                     .getValue() != 1 ) {
1707                 return false;
1708             }
1709             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1710                     .getType().equals( "ml" ) ) {
1711                 return false;
1712             }
1713             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1714                     .equals( "apoptosis" ) ) {
1715                 return false;
1716             }
1717             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1718                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1719                 return false;
1720             }
1721             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1722                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1723                 return false;
1724             }
1725             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1726                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1727                 return false;
1728             }
1729             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1730                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1731                 return false;
1732             }
1733             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1734                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1735                 return false;
1736             }
1737             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1738                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1739                 return false;
1740             }
1741             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1742                     .equals( "GO:0005829" ) ) {
1743                 return false;
1744             }
1745             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1746                     .equals( "intracellular organelle" ) ) {
1747                 return false;
1748             }
1749             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1750                 return false;
1751             }
1752             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1753                     .equals( "UniProt link" ) ) ) {
1754                 return false;
1755             }
1756             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1757                 return false;
1758             }
1759             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1760             if ( x.size() != 4 ) {
1761                 return false;
1762             }
1763             int c = 0;
1764             for( final Accession acc : x ) {
1765                 if ( c == 0 ) {
1766                     if ( !acc.getSource().equals( "KEGG" ) ) {
1767                         return false;
1768                     }
1769                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1770                         return false;
1771                     }
1772                 }
1773                 c++;
1774             }
1775         }
1776         catch ( final Exception e ) {
1777             e.printStackTrace( System.out );
1778             return false;
1779         }
1780         return true;
1781     }
1782
1783     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1784         try {
1785             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1786             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1787             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1788                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1789             }
1790             else {
1791                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1792             }
1793             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1794                                                               xml_parser );
1795             if ( xml_parser.getErrorCount() > 0 ) {
1796                 System.out.println( xml_parser.getErrorMessages().toString() );
1797                 return false;
1798             }
1799             if ( phylogenies_0.length != 4 ) {
1800                 return false;
1801             }
1802             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1803             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1804             if ( phylogenies_t1.length != 1 ) {
1805                 return false;
1806             }
1807             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1808             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1809                 return false;
1810             }
1811             if ( !t1_rt.isRooted() ) {
1812                 return false;
1813             }
1814             if ( t1_rt.isRerootable() ) {
1815                 return false;
1816             }
1817             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1818                 return false;
1819             }
1820             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1821             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1822             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1823             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1824                 return false;
1825             }
1826             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1827                 return false;
1828             }
1829             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1830                 return false;
1831             }
1832             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1833                 return false;
1834             }
1835             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1836                     .startsWith( "actgtgggggt" ) ) {
1837                 return false;
1838             }
1839             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1840                     .startsWith( "ctgtgatgcat" ) ) {
1841                 return false;
1842             }
1843             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1844             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1845             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1846             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1847             if ( phylogenies_1.length != 1 ) {
1848                 return false;
1849             }
1850             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1851             if ( !t3_rt.getName().equals( "t3" ) ) {
1852                 return false;
1853             }
1854             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1855                 return false;
1856             }
1857             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1858                 return false;
1859             }
1860             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1861                 return false;
1862             }
1863             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1864                 return false;
1865             }
1866             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1867                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1868                 return false;
1869             }
1870             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1871                 return false;
1872             }
1873             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1874                 return false;
1875             }
1876             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1877                     .equals( "UniProtKB" ) ) {
1878                 return false;
1879             }
1880             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1881                     .equals( "apoptosis" ) ) {
1882                 return false;
1883             }
1884             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1885                     .equals( "GO:0006915" ) ) {
1886                 return false;
1887             }
1888             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1889                     .equals( "UniProtKB" ) ) {
1890                 return false;
1891             }
1892             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1893                     .equals( "experimental" ) ) {
1894                 return false;
1895             }
1896             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1897                     .equals( "function" ) ) {
1898                 return false;
1899             }
1900             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1901                     .getValue() != 1 ) {
1902                 return false;
1903             }
1904             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1905                     .getType().equals( "ml" ) ) {
1906                 return false;
1907             }
1908             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1909                     .equals( "apoptosis" ) ) {
1910                 return false;
1911             }
1912             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1913                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1914                 return false;
1915             }
1916             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1917                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1918                 return false;
1919             }
1920             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1921                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1922                 return false;
1923             }
1924             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1925                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1926                 return false;
1927             }
1928             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1929                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1930                 return false;
1931             }
1932             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1933                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1934                 return false;
1935             }
1936             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1937                     .equals( "GO:0005829" ) ) {
1938                 return false;
1939             }
1940             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1941                     .equals( "intracellular organelle" ) ) {
1942                 return false;
1943             }
1944             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1945                 return false;
1946             }
1947             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1948                     .equals( "UniProt link" ) ) ) {
1949                 return false;
1950             }
1951             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1952                 return false;
1953             }
1954             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1955                 return false;
1956             }
1957             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1958                     .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." ) ) ) {
1959                 return false;
1960             }
1961             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1962                 return false;
1963             }
1964             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1974                     .equals( "ncbi" ) ) {
1975                 return false;
1976             }
1977             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1978                 return false;
1979             }
1980             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1981                     .getName().equals( "B" ) ) {
1982                 return false;
1983             }
1984             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1985                     .getFrom() != 21 ) {
1986                 return false;
1987             }
1988             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1989                 return false;
1990             }
1991             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1992                     .getLength() != 24 ) {
1993                 return false;
1994             }
1995             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1996                     .getConfidence() != 2144 ) {
1997                 return false;
1998             }
1999             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2000                     .equals( "pfam" ) ) {
2001                 return false;
2002             }
2003             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2004                 return false;
2005             }
2006             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2007                 return false;
2008             }
2009             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2010                 return false;
2011             }
2012             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2013                 return false;
2014             }
2015             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2016             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2017                 return false;
2018             }
2019             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2020                 return false;
2021             }
2022             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2023                 return false;
2024             }
2025             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2026                 return false;
2027             }
2028             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2029                 return false;
2030             }
2031             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2032                 return false;
2033             }
2034             if ( taxbb.getSynonyms().size() != 2 ) {
2035                 return false;
2036             }
2037             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2038                 return false;
2039             }
2040             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2041                 return false;
2042             }
2043             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2044                 return false;
2045             }
2046             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2047                 return false;
2048             }
2049             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2050                 return false;
2051             }
2052             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2053                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2054                 return false;
2055             }
2056             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2057                 return false;
2058             }
2059             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2060                 return false;
2061             }
2062             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2063                 return false;
2064             }
2065             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2066                 return false;
2067             }
2068             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2069                 return false;
2070             }
2071             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2072                 return false;
2073             }
2074             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2075                 return false;
2076             }
2077             //
2078             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2079                 return false;
2080             }
2081             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2082                     .equalsIgnoreCase( "435" ) ) {
2083                 return false;
2084             }
2085             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2086                 return false;
2087             }
2088             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2089                     .equalsIgnoreCase( "443.7" ) ) {
2090                 return false;
2091             }
2092             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2096                 return false;
2097             }
2098             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2099                     .equalsIgnoreCase( "433" ) ) {
2100                 return false;
2101             }
2102             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2103                     .getCrossReferences();
2104             if ( x.size() != 4 ) {
2105                 return false;
2106             }
2107             int c = 0;
2108             for( final Accession acc : x ) {
2109                 if ( c == 0 ) {
2110                     if ( !acc.getSource().equals( "KEGG" ) ) {
2111                         return false;
2112                     }
2113                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2114                         return false;
2115                     }
2116                 }
2117                 c++;
2118             }
2119         }
2120         catch ( final Exception e ) {
2121             e.printStackTrace( System.out );
2122             return false;
2123         }
2124         return true;
2125     }
2126
2127     private static boolean testBasicPhyloXMLparsingValidating() {
2128         try {
2129             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2130             PhyloXmlParser xml_parser = null;
2131             try {
2132                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2133             }
2134             catch ( final Exception e ) {
2135                 // Do nothing -- means were not running from jar.
2136             }
2137             if ( xml_parser == null ) {
2138                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2139                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2140                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2141                 }
2142                 else {
2143                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2144                 }
2145             }
2146             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2147                                                               xml_parser );
2148             if ( xml_parser.getErrorCount() > 0 ) {
2149                 System.out.println( xml_parser.getErrorMessages().toString() );
2150                 return false;
2151             }
2152             if ( phylogenies_0.length != 4 ) {
2153                 return false;
2154             }
2155             final Phylogeny t1 = phylogenies_0[ 0 ];
2156             final Phylogeny t2 = phylogenies_0[ 1 ];
2157             final Phylogeny t3 = phylogenies_0[ 2 ];
2158             final Phylogeny t4 = phylogenies_0[ 3 ];
2159             if ( !t1.getName().equals( "t1" ) ) {
2160                 return false;
2161             }
2162             if ( !t2.getName().equals( "t2" ) ) {
2163                 return false;
2164             }
2165             if ( !t3.getName().equals( "t3" ) ) {
2166                 return false;
2167             }
2168             if ( !t4.getName().equals( "t4" ) ) {
2169                 return false;
2170             }
2171             if ( t1.getNumberOfExternalNodes() != 1 ) {
2172                 return false;
2173             }
2174             if ( t2.getNumberOfExternalNodes() != 2 ) {
2175                 return false;
2176             }
2177             if ( t3.getNumberOfExternalNodes() != 4 ) {
2178                 return false;
2179             }
2180             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2181             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2182             if ( xml_parser.getErrorCount() > 0 ) {
2183                 System.out.println( "errors:" );
2184                 System.out.println( xml_parser.getErrorMessages().toString() );
2185                 return false;
2186             }
2187             if ( phylogenies_1.length != 4 ) {
2188                 return false;
2189             }
2190             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2191                                                               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_2.length != 1 ) {
2198                 return false;
2199             }
2200             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2201                 return false;
2202             }
2203             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2204                                                               xml_parser );
2205             if ( xml_parser.getErrorCount() > 0 ) {
2206                 System.out.println( xml_parser.getErrorMessages().toString() );
2207                 return false;
2208             }
2209             if ( phylogenies_3.length != 2 ) {
2210                 return false;
2211             }
2212             final Phylogeny a = phylogenies_3[ 0 ];
2213             if ( !a.getName().equals( "tree 4" ) ) {
2214                 return false;
2215             }
2216             if ( a.getNumberOfExternalNodes() != 3 ) {
2217                 return false;
2218             }
2219             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2220                 return false;
2221             }
2222             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2223                 return false;
2224             }
2225             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2226                                                               xml_parser );
2227             if ( xml_parser.getErrorCount() > 0 ) {
2228                 System.out.println( xml_parser.getErrorMessages().toString() );
2229                 return false;
2230             }
2231             if ( phylogenies_4.length != 1 ) {
2232                 return false;
2233             }
2234             final Phylogeny s = phylogenies_4[ 0 ];
2235             if ( s.getNumberOfExternalNodes() != 6 ) {
2236                 return false;
2237             }
2238             s.getNode( "first" );
2239             s.getNode( "<>" );
2240             s.getNode( "\"<a'b&c'd\">\"" );
2241             s.getNode( "'''\"" );
2242             s.getNode( "\"\"\"" );
2243             s.getNode( "dick & doof" );
2244         }
2245         catch ( final Exception e ) {
2246             e.printStackTrace( System.out );
2247             return false;
2248         }
2249         return true;
2250     }
2251
2252     private static boolean testBasicProtein() {
2253         try {
2254             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2255             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2256             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2257             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2258             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2259             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2260             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2261             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2262             p0.addProteinDomain( y );
2263             p0.addProteinDomain( e );
2264             p0.addProteinDomain( b );
2265             p0.addProteinDomain( c );
2266             p0.addProteinDomain( d );
2267             p0.addProteinDomain( a );
2268             p0.addProteinDomain( x );
2269             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2270                 return false;
2271             }
2272             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2273                 return false;
2274             }
2275             //
2276             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2277             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2278             aa0.addProteinDomain( a1 );
2279             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2280                 return false;
2281             }
2282             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2283                 return false;
2284             }
2285             //
2286             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2287             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2288             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2289             aa1.addProteinDomain( a11 );
2290             aa1.addProteinDomain( a12 );
2291             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2292                 return false;
2293             }
2294             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2295                 return false;
2296             }
2297             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2298             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2299                 return false;
2300             }
2301             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2302                 return false;
2303             }
2304             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2305                 return false;
2306             }
2307             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2308             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2309                 return false;
2310             }
2311             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2312                 return false;
2313             }
2314             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2315                 return false;
2316             }
2317             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2318                 return false;
2319             }
2320             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2321             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2322                 return false;
2323             }
2324             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2325                 return false;
2326             }
2327             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2328                 return false;
2329             }
2330             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2331                 return false;
2332             }
2333             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2334             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2335                 return false;
2336             }
2337             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2338                 return false;
2339             }
2340             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2341                 return false;
2342             }
2343             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2344                 return false;
2345             }
2346             //
2347             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2348             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2349             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2350             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2351             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2352             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2360             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             p00.addProteinDomain( y0 );
2369             p00.addProteinDomain( e0 );
2370             p00.addProteinDomain( b0 );
2371             p00.addProteinDomain( c0 );
2372             p00.addProteinDomain( d0 );
2373             p00.addProteinDomain( a0 );
2374             p00.addProteinDomain( x0 );
2375             p00.addProteinDomain( y1 );
2376             p00.addProteinDomain( y2 );
2377             p00.addProteinDomain( y3 );
2378             p00.addProteinDomain( e1 );
2379             p00.addProteinDomain( e2 );
2380             p00.addProteinDomain( e3 );
2381             p00.addProteinDomain( e4 );
2382             p00.addProteinDomain( e5 );
2383             p00.addProteinDomain( z0 );
2384             p00.addProteinDomain( z1 );
2385             p00.addProteinDomain( z2 );
2386             p00.addProteinDomain( zz0 );
2387             p00.addProteinDomain( zz1 );
2388             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2389                 return false;
2390             }
2391             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2392                 return false;
2393             }
2394             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2395                 return false;
2396             }
2397             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2398                 return false;
2399             }
2400             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" ) ) {
2401                 return false;
2402             }
2403             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2404             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2405             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2406             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2407             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2408             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2409             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2410             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2411             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2412             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2413             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2414             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2415             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2416             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2417             p.addProteinDomain( B15 );
2418             p.addProteinDomain( C50 );
2419             p.addProteinDomain( A60 );
2420             p.addProteinDomain( A30 );
2421             p.addProteinDomain( C70 );
2422             p.addProteinDomain( B35 );
2423             p.addProteinDomain( B40 );
2424             p.addProteinDomain( A0 );
2425             p.addProteinDomain( A10 );
2426             p.addProteinDomain( A20 );
2427             p.addProteinDomain( B25 );
2428             p.addProteinDomain( D80 );
2429             List<String> domains_ids = new ArrayList<String>();
2430             domains_ids.add( "A" );
2431             domains_ids.add( "B" );
2432             domains_ids.add( "C" );
2433             if ( !p.contains( domains_ids, false ) ) {
2434                 return false;
2435             }
2436             if ( !p.contains( domains_ids, true ) ) {
2437                 return false;
2438             }
2439             domains_ids.add( "X" );
2440             if ( p.contains( domains_ids, false ) ) {
2441                 return false;
2442             }
2443             if ( p.contains( domains_ids, true ) ) {
2444                 return false;
2445             }
2446             domains_ids = new ArrayList<String>();
2447             domains_ids.add( "A" );
2448             domains_ids.add( "C" );
2449             domains_ids.add( "D" );
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( "D" );
2459             domains_ids.add( "C" );
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( "A" );
2469             domains_ids.add( "B" );
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( "A" );
2480             domains_ids.add( "B" );
2481             domains_ids.add( "B" );
2482             if ( !p.contains( domains_ids, false ) ) {
2483                 return false;
2484             }
2485             if ( !p.contains( domains_ids, true ) ) {
2486                 return false;
2487             }
2488             domains_ids = new ArrayList<String>();
2489             domains_ids.add( "A" );
2490             domains_ids.add( "A" );
2491             domains_ids.add( "B" );
2492             domains_ids.add( "A" );
2493             domains_ids.add( "B" );
2494             domains_ids.add( "B" );
2495             domains_ids.add( "A" );
2496             domains_ids.add( "B" );
2497             domains_ids.add( "C" );
2498             domains_ids.add( "A" );
2499             domains_ids.add( "C" );
2500             domains_ids.add( "D" );
2501             if ( !p.contains( domains_ids, false ) ) {
2502                 return false;
2503             }
2504             if ( p.contains( domains_ids, true ) ) {
2505                 return false;
2506             }
2507         }
2508         catch ( final Exception e ) {
2509             e.printStackTrace( System.out );
2510             return false;
2511         }
2512         return true;
2513     }
2514
2515     private static boolean testBasicTable() {
2516         try {
2517             final BasicTable<String> t0 = new BasicTable<String>();
2518             if ( t0.getNumberOfColumns() != 0 ) {
2519                 return false;
2520             }
2521             if ( t0.getNumberOfRows() != 0 ) {
2522                 return false;
2523             }
2524             t0.setValue( 3, 2, "23" );
2525             t0.setValue( 10, 1, "error" );
2526             t0.setValue( 10, 1, "110" );
2527             t0.setValue( 9, 1, "19" );
2528             t0.setValue( 1, 10, "101" );
2529             t0.setValue( 10, 10, "1010" );
2530             t0.setValue( 100, 10, "10100" );
2531             t0.setValue( 0, 0, "00" );
2532             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2533                 return false;
2534             }
2535             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2536                 return false;
2537             }
2538             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2539                 return false;
2540             }
2541             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2542                 return false;
2543             }
2544             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2545                 return false;
2546             }
2547             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2548                 return false;
2549             }
2550             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2551                 return false;
2552             }
2553             if ( t0.getNumberOfColumns() != 101 ) {
2554                 return false;
2555             }
2556             if ( t0.getNumberOfRows() != 11 ) {
2557                 return false;
2558             }
2559             if ( t0.getValueAsString( 49, 4 ) != null ) {
2560                 return false;
2561             }
2562             final String l = ForesterUtil.getLineSeparator();
2563             final StringBuffer source = new StringBuffer();
2564             source.append( "" + l );
2565             source.append( "# 1 1 1 1 1 1 1 1" + l );
2566             source.append( " 00 01 02 03" + l );
2567             source.append( "   10 11 12 13  " + l );
2568             source.append( "20 21 22 23 " + l );
2569             source.append( "    30  31    32 33" + l );
2570             source.append( "40 41 42 43" + l );
2571             source.append( "  # 1 1 1 1 1 " + l );
2572             source.append( "50 51 52 53 54" + l );
2573             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2574             if ( t1.getNumberOfColumns() != 5 ) {
2575                 return false;
2576             }
2577             if ( t1.getNumberOfRows() != 6 ) {
2578                 return false;
2579             }
2580             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2581                 return false;
2582             }
2583             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2584                 return false;
2585             }
2586             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2587                 return false;
2588             }
2589             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2590                 return false;
2591             }
2592             final StringBuffer source1 = new StringBuffer();
2593             source1.append( "" + l );
2594             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2595             source1.append( " 00; 01 ;02;03" + l );
2596             source1.append( "   10; 11; 12; 13  " + l );
2597             source1.append( "20; 21; 22; 23 " + l );
2598             source1.append( "    30;  31;    32; 33" + l );
2599             source1.append( "40;41;42;43" + l );
2600             source1.append( "  # 1 1 1 1 1 " + l );
2601             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2602             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2603             if ( t2.getNumberOfColumns() != 5 ) {
2604                 return false;
2605             }
2606             if ( t2.getNumberOfRows() != 6 ) {
2607                 return false;
2608             }
2609             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2610                 return false;
2611             }
2612             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2613                 return false;
2614             }
2615             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2616                 return false;
2617             }
2618             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2619                 return false;
2620             }
2621             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2622                 return false;
2623             }
2624             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2625                 return false;
2626             }
2627             final StringBuffer source2 = new StringBuffer();
2628             source2.append( "" + l );
2629             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2630             source2.append( " 00; 01 ;02;03" + l );
2631             source2.append( "   10; 11; 12; 13  " + l );
2632             source2.append( "20; 21; 22; 23 " + l );
2633             source2.append( "                     " + l );
2634             source2.append( "    30;  31;    32; 33" + l );
2635             source2.append( "40;41;42;43" + l );
2636             source2.append( "  comment: 1 1 1 1 1 " + l );
2637             source2.append( ";;;50  ;   52; 53;;54   " + l );
2638             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2639                                                                         ';',
2640                                                                         false,
2641                                                                         false,
2642                                                                         "comment:",
2643                                                                         false );
2644             if ( tl.size() != 2 ) {
2645                 return false;
2646             }
2647             final BasicTable<String> t3 = tl.get( 0 );
2648             final BasicTable<String> t4 = tl.get( 1 );
2649             if ( t3.getNumberOfColumns() != 4 ) {
2650                 return false;
2651             }
2652             if ( t3.getNumberOfRows() != 3 ) {
2653                 return false;
2654             }
2655             if ( t4.getNumberOfColumns() != 4 ) {
2656                 return false;
2657             }
2658             if ( t4.getNumberOfRows() != 3 ) {
2659                 return false;
2660             }
2661             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2662                 return false;
2663             }
2664             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2665                 return false;
2666             }
2667         }
2668         catch ( final Exception e ) {
2669             e.printStackTrace( System.out );
2670             return false;
2671         }
2672         return true;
2673     }
2674
2675     private static boolean testBasicTolXMLparsing() {
2676         try {
2677             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2678             final TolParser parser = new TolParser();
2679             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2680             if ( parser.getErrorCount() > 0 ) {
2681                 System.out.println( parser.getErrorMessages().toString() );
2682                 return false;
2683             }
2684             if ( phylogenies_0.length != 1 ) {
2685                 return false;
2686             }
2687             final Phylogeny t1 = phylogenies_0[ 0 ];
2688             if ( t1.getNumberOfExternalNodes() != 5 ) {
2689                 return false;
2690             }
2691             if ( !t1.isRooted() ) {
2692                 return false;
2693             }
2694             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2695                 return false;
2696             }
2697             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2698                 return false;
2699             }
2700             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2701                 return false;
2702             }
2703             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2704                 return false;
2705             }
2706             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2707             if ( parser.getErrorCount() > 0 ) {
2708                 System.out.println( parser.getErrorMessages().toString() );
2709                 return false;
2710             }
2711             if ( phylogenies_1.length != 1 ) {
2712                 return false;
2713             }
2714             final Phylogeny t2 = phylogenies_1[ 0 ];
2715             if ( t2.getNumberOfExternalNodes() != 664 ) {
2716                 return false;
2717             }
2718             if ( !t2.isRooted() ) {
2719                 return false;
2720             }
2721             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2722                 return false;
2723             }
2724             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2725                 return false;
2726             }
2727             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2728                 return false;
2729             }
2730             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2731                 return false;
2732             }
2733             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2737                     .equals( "Aquifex" ) ) {
2738                 return false;
2739             }
2740             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2741             if ( parser.getErrorCount() > 0 ) {
2742                 System.out.println( parser.getErrorMessages().toString() );
2743                 return false;
2744             }
2745             if ( phylogenies_2.length != 1 ) {
2746                 return false;
2747             }
2748             final Phylogeny t3 = phylogenies_2[ 0 ];
2749             if ( t3.getNumberOfExternalNodes() != 184 ) {
2750                 return false;
2751             }
2752             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2753                 return false;
2754             }
2755             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2756                 return false;
2757             }
2758             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2759                 return false;
2760             }
2761             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2762             if ( parser.getErrorCount() > 0 ) {
2763                 System.out.println( parser.getErrorMessages().toString() );
2764                 return false;
2765             }
2766             if ( phylogenies_3.length != 1 ) {
2767                 return false;
2768             }
2769             final Phylogeny t4 = phylogenies_3[ 0 ];
2770             if ( t4.getNumberOfExternalNodes() != 1 ) {
2771                 return false;
2772             }
2773             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2774                 return false;
2775             }
2776             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2777                 return false;
2778             }
2779             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2780                 return false;
2781             }
2782             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2783             if ( parser.getErrorCount() > 0 ) {
2784                 System.out.println( parser.getErrorMessages().toString() );
2785                 return false;
2786             }
2787             if ( phylogenies_4.length != 1 ) {
2788                 return false;
2789             }
2790             final Phylogeny t5 = phylogenies_4[ 0 ];
2791             if ( t5.getNumberOfExternalNodes() != 13 ) {
2792                 return false;
2793             }
2794             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2795                 return false;
2796             }
2797             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2798                 return false;
2799             }
2800             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2801                 return false;
2802             }
2803         }
2804         catch ( final Exception e ) {
2805             e.printStackTrace( System.out );
2806             return false;
2807         }
2808         return true;
2809     }
2810
2811     private static boolean testBasicTreeMethods() {
2812         try {
2813             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2814             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2815             if ( t2.getNumberOfExternalNodes() != 4 ) {
2816                 return false;
2817             }
2818             if ( t2.getHeight() != 8.5 ) {
2819                 return false;
2820             }
2821             if ( !t2.isCompletelyBinary() ) {
2822                 return false;
2823             }
2824             if ( t2.isEmpty() ) {
2825                 return false;
2826             }
2827             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2828             if ( t3.getNumberOfExternalNodes() != 5 ) {
2829                 return false;
2830             }
2831             if ( t3.getHeight() != 11 ) {
2832                 return false;
2833             }
2834             if ( t3.isCompletelyBinary() ) {
2835                 return false;
2836             }
2837             final PhylogenyNode n = t3.getNode( "ABC" );
2838             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 ];
2839             if ( t4.getNumberOfExternalNodes() != 9 ) {
2840                 return false;
2841             }
2842             if ( t4.getHeight() != 11 ) {
2843                 return false;
2844             }
2845             if ( t4.isCompletelyBinary() ) {
2846                 return false;
2847             }
2848             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)" );
2849             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2850             if ( t5.getNumberOfExternalNodes() != 8 ) {
2851                 return false;
2852             }
2853             if ( t5.getHeight() != 15 ) {
2854                 return false;
2855             }
2856             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)" );
2857             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2858             if ( t6.getHeight() != 15 ) {
2859                 return false;
2860             }
2861             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)" );
2862             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2863             if ( t7.getHeight() != 15 ) {
2864                 return false;
2865             }
2866             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)" );
2867             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2868             if ( t8.getNumberOfExternalNodes() != 10 ) {
2869                 return false;
2870             }
2871             if ( t8.getHeight() != 15 ) {
2872                 return false;
2873             }
2874             final char[] a9 = new char[] { 'a' };
2875             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2876             if ( t9.getHeight() != 0 ) {
2877                 return false;
2878             }
2879             final char[] a10 = new char[] { 'a', ':', '6' };
2880             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2881             if ( t10.getHeight() != 6 ) {
2882                 return false;
2883             }
2884         }
2885         catch ( final Exception e ) {
2886             e.printStackTrace( System.out );
2887             return false;
2888         }
2889         return true;
2890     }
2891
2892     private static boolean testConfidenceAssessor() {
2893         try {
2894             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2895             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2896             final Phylogeny[] ev0 = factory
2897                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2898                              new NHXParser() );
2899             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2900             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2901                 return false;
2902             }
2903             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2904                 return false;
2905             }
2906             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2907             final Phylogeny[] ev1 = factory
2908                     .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)));",
2909                              new NHXParser() );
2910             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2911             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2912                 return false;
2913             }
2914             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2915                 return false;
2916             }
2917             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2918             final Phylogeny[] ev_b = factory
2919                     .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",
2920                              new NHXParser() );
2921             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2922             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2923                 return false;
2924             }
2925             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2926                 return false;
2927             }
2928             //
2929             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2930             final Phylogeny[] ev1x = factory
2931                     .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)));",
2932                              new NHXParser() );
2933             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2934             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2935                 return false;
2936             }
2937             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2938                 return false;
2939             }
2940             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2941             final Phylogeny[] ev_bx = factory
2942                     .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",
2943                              new NHXParser() );
2944             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2945             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2946                 return false;
2947             }
2948             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2949                 return false;
2950             }
2951             //
2952             final Phylogeny[] t2 = factory
2953                     .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);",
2954                              new NHXParser() );
2955             final Phylogeny[] ev2 = factory
2956                     .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);",
2957                              new NHXParser() );
2958             for( final Phylogeny target : t2 ) {
2959                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2960             }
2961             //
2962             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2963                                                  new NHXParser() )[ 0 ];
2964             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2965             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2966             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2967                 return false;
2968             }
2969             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2970                 return false;
2971             }
2972             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2973                 return false;
2974             }
2975         }
2976         catch ( final Exception e ) {
2977             e.printStackTrace();
2978             return false;
2979         }
2980         return true;
2981     }
2982
2983     private static boolean testCopyOfNodeData() {
2984         try {
2985             final PhylogenyNode n1 = PhylogenyNode
2986                     .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]" );
2987             final PhylogenyNode n2 = n1.copyNodeData();
2988             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2989                 return false;
2990             }
2991         }
2992         catch ( final Exception e ) {
2993             e.printStackTrace();
2994             return false;
2995         }
2996         return true;
2997     }
2998
2999     private static boolean testCreateBalancedPhylogeny() {
3000         try {
3001             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3002             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3003                 return false;
3004             }
3005             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3006                 return false;
3007             }
3008             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3009             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3010                 return false;
3011             }
3012             if ( p1.getNumberOfExternalNodes() != 100 ) {
3013                 return false;
3014             }
3015         }
3016         catch ( final Exception e ) {
3017             e.printStackTrace();
3018             return false;
3019         }
3020         return true;
3021     }
3022
3023     private static boolean testCreateUriForSeqWeb() {
3024         try {
3025             final PhylogenyNode n = new PhylogenyNode();
3026             n.setName( "tr|B3RJ64" );
3027             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3028                 return false;
3029             }
3030             n.setName( "B0LM41_HUMAN" );
3031             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3032                 return false;
3033             }
3034             n.setName( "NP_001025424" );
3035             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3036                 return false;
3037             }
3038             n.setName( "_NM_001030253-" );
3039             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3040                 return false;
3041             }
3042             n.setName( "XM_002122186" );
3043             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3044                 return false;
3045             }
3046             n.setName( "dgh_AAA34956_gdg" );
3047             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3048                 return false;
3049             }
3050             n.setName( "AAA34956" );
3051             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3052                 return false;
3053             }
3054             n.setName( "GI:394892" );
3055             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3056                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3057                 return false;
3058             }
3059             n.setName( "gi_394892" );
3060             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3061                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3062                 return false;
3063             }
3064             n.setName( "gi6335_gi_394892_56635_Gi_43" );
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( "P12345" );
3070             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3071                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3072                 return false;
3073             }
3074             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3075             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3076                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3077                 return false;
3078             }
3079         }
3080         catch ( final Exception e ) {
3081             e.printStackTrace( System.out );
3082             return false;
3083         }
3084         return true;
3085     }
3086
3087     private static boolean testDataObjects() {
3088         try {
3089             final Confidence s0 = new Confidence();
3090             final Confidence s1 = new Confidence();
3091             if ( !s0.isEqual( s1 ) ) {
3092                 return false;
3093             }
3094             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3095             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3096             if ( s2.isEqual( s1 ) ) {
3097                 return false;
3098             }
3099             if ( !s2.isEqual( s3 ) ) {
3100                 return false;
3101             }
3102             final Confidence s4 = ( Confidence ) s3.copy();
3103             if ( !s4.isEqual( s3 ) ) {
3104                 return false;
3105             }
3106             s3.asSimpleText();
3107             s3.asText();
3108             // Taxonomy
3109             // ----------
3110             final Taxonomy t1 = new Taxonomy();
3111             final Taxonomy t2 = new Taxonomy();
3112             final Taxonomy t3 = new Taxonomy();
3113             final Taxonomy t4 = new Taxonomy();
3114             final Taxonomy t5 = new Taxonomy();
3115             t1.setIdentifier( new Identifier( "ecoli" ) );
3116             t1.setTaxonomyCode( "ECOLI" );
3117             t1.setScientificName( "E. coli" );
3118             t1.setCommonName( "coli" );
3119             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3120             if ( !t1.isEqual( t0 ) ) {
3121                 return false;
3122             }
3123             t2.setIdentifier( new Identifier( "ecoli" ) );
3124             t2.setTaxonomyCode( "OTHER" );
3125             t2.setScientificName( "what" );
3126             t2.setCommonName( "something" );
3127             if ( !t1.isEqual( t2 ) ) {
3128                 return false;
3129             }
3130             t2.setIdentifier( new Identifier( "nemve" ) );
3131             if ( t1.isEqual( t2 ) ) {
3132                 return false;
3133             }
3134             t1.setIdentifier( null );
3135             t3.setTaxonomyCode( "ECOLI" );
3136             t3.setScientificName( "what" );
3137             t3.setCommonName( "something" );
3138             if ( !t1.isEqual( t3 ) ) {
3139                 return false;
3140             }
3141             t1.setIdentifier( null );
3142             t1.setTaxonomyCode( "" );
3143             t4.setScientificName( "E. ColI" );
3144             t4.setCommonName( "something" );
3145             if ( !t1.isEqual( t4 ) ) {
3146                 return false;
3147             }
3148             t4.setScientificName( "B. subtilis" );
3149             t4.setCommonName( "something" );
3150             if ( t1.isEqual( t4 ) ) {
3151                 return false;
3152             }
3153             t1.setIdentifier( null );
3154             t1.setTaxonomyCode( "" );
3155             t1.setScientificName( "" );
3156             t5.setCommonName( "COLI" );
3157             if ( !t1.isEqual( t5 ) ) {
3158                 return false;
3159             }
3160             t5.setCommonName( "vibrio" );
3161             if ( t1.isEqual( t5 ) ) {
3162                 return false;
3163             }
3164             // Identifier
3165             // ----------
3166             final Identifier id0 = new Identifier( "123", "pfam" );
3167             final Identifier id1 = ( Identifier ) id0.copy();
3168             if ( !id1.isEqual( id1 ) ) {
3169                 return false;
3170             }
3171             if ( !id1.isEqual( id0 ) ) {
3172                 return false;
3173             }
3174             if ( !id0.isEqual( id1 ) ) {
3175                 return false;
3176             }
3177             id1.asSimpleText();
3178             id1.asText();
3179             // ProteinDomain
3180             // ---------------
3181             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3182             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3183             if ( !pd1.isEqual( pd1 ) ) {
3184                 return false;
3185             }
3186             if ( !pd1.isEqual( pd0 ) ) {
3187                 return false;
3188             }
3189             pd1.asSimpleText();
3190             pd1.asText();
3191             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3192             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3193             if ( !pd3.isEqual( pd3 ) ) {
3194                 return false;
3195             }
3196             if ( !pd2.isEqual( pd3 ) ) {
3197                 return false;
3198             }
3199             if ( !pd0.isEqual( pd3 ) ) {
3200                 return false;
3201             }
3202             pd3.asSimpleText();
3203             pd3.asText();
3204             // DomainArchitecture
3205             // ------------------
3206             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3207             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3208             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3209             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3210             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3211             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3212             domains0.add( d2 );
3213             domains0.add( d0 );
3214             domains0.add( d3 );
3215             domains0.add( d1 );
3216             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3217             if ( ds0.getNumberOfDomains() != 4 ) {
3218                 return false;
3219             }
3220             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3221             if ( !ds0.isEqual( ds0 ) ) {
3222                 return false;
3223             }
3224             if ( !ds0.isEqual( ds1 ) ) {
3225                 return false;
3226             }
3227             if ( ds1.getNumberOfDomains() != 4 ) {
3228                 return false;
3229             }
3230             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3231             domains1.add( d1 );
3232             domains1.add( d2 );
3233             domains1.add( d4 );
3234             domains1.add( d0 );
3235             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3236             if ( ds0.isEqual( ds2 ) ) {
3237                 return false;
3238             }
3239             ds1.asSimpleText();
3240             ds1.asText();
3241             ds1.toNHX();
3242             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3243             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3244                 System.out.println( ds3.toNHX() );
3245                 return false;
3246             }
3247             if ( ds3.getNumberOfDomains() != 3 ) {
3248                 return false;
3249             }
3250             // Event
3251             // -----
3252             final Event e1 = new Event( Event.EventType.fusion );
3253             if ( e1.isDuplication() ) {
3254                 return false;
3255             }
3256             if ( !e1.isFusion() ) {
3257                 return false;
3258             }
3259             if ( !e1.asText().toString().equals( "fusion" ) ) {
3260                 return false;
3261             }
3262             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3263                 return false;
3264             }
3265             final Event e11 = new Event( Event.EventType.fusion );
3266             if ( !e11.isEqual( e1 ) ) {
3267                 return false;
3268             }
3269             if ( !e11.toNHX().toString().equals( "" ) ) {
3270                 return false;
3271             }
3272             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3273             if ( e2.isDuplication() ) {
3274                 return false;
3275             }
3276             if ( !e2.isSpeciationOrDuplication() ) {
3277                 return false;
3278             }
3279             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3280                 return false;
3281             }
3282             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3283                 return false;
3284             }
3285             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3286                 return false;
3287             }
3288             if ( e11.isEqual( e2 ) ) {
3289                 return false;
3290             }
3291             final Event e2c = ( Event ) e2.copy();
3292             if ( !e2c.isEqual( e2 ) ) {
3293                 return false;
3294             }
3295             Event e3 = new Event( 1, 2, 3 );
3296             if ( e3.isDuplication() ) {
3297                 return false;
3298             }
3299             if ( e3.isSpeciation() ) {
3300                 return false;
3301             }
3302             if ( e3.isGeneLoss() ) {
3303                 return false;
3304             }
3305             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3306                 return false;
3307             }
3308             final Event e3c = ( Event ) e3.copy();
3309             final Event e3cc = ( Event ) e3c.copy();
3310             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3311                 return false;
3312             }
3313             e3 = null;
3314             if ( !e3c.isEqual( e3cc ) ) {
3315                 return false;
3316             }
3317             Event e4 = new Event( 1, 2, 3 );
3318             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3319                 return false;
3320             }
3321             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3322                 return false;
3323             }
3324             final Event e4c = ( Event ) e4.copy();
3325             e4 = null;
3326             final Event e4cc = ( Event ) e4c.copy();
3327             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3328                 return false;
3329             }
3330             if ( !e4c.isEqual( e4cc ) ) {
3331                 return false;
3332             }
3333             final Event e5 = new Event();
3334             if ( !e5.isUnassigned() ) {
3335                 return false;
3336             }
3337             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3338                 return false;
3339             }
3340             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3341                 return false;
3342             }
3343             final Event e6 = new Event( 1, 0, 0 );
3344             if ( !e6.asText().toString().equals( "duplication" ) ) {
3345                 return false;
3346             }
3347             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3348                 return false;
3349             }
3350             final Event e7 = new Event( 0, 1, 0 );
3351             if ( !e7.asText().toString().equals( "speciation" ) ) {
3352                 return false;
3353             }
3354             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3355                 return false;
3356             }
3357             final Event e8 = new Event( 0, 0, 1 );
3358             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3359                 return false;
3360             }
3361             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3362                 return false;
3363             }
3364         }
3365         catch ( final Exception e ) {
3366             e.printStackTrace( System.out );
3367             return false;
3368         }
3369         return true;
3370     }
3371
3372     private static boolean testDeletionOfExternalNodes() {
3373         try {
3374             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3375             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3376             final PhylogenyWriter w = new PhylogenyWriter();
3377             if ( t0.isEmpty() ) {
3378                 return false;
3379             }
3380             if ( t0.getNumberOfExternalNodes() != 1 ) {
3381                 return false;
3382             }
3383             t0.deleteSubtree( t0.getNode( "A" ), false );
3384             if ( t0.getNumberOfExternalNodes() != 0 ) {
3385                 return false;
3386             }
3387             if ( !t0.isEmpty() ) {
3388                 return false;
3389             }
3390             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3391             if ( t1.getNumberOfExternalNodes() != 2 ) {
3392                 return false;
3393             }
3394             t1.deleteSubtree( t1.getNode( "A" ), false );
3395             if ( t1.getNumberOfExternalNodes() != 1 ) {
3396                 return false;
3397             }
3398             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3399                 return false;
3400             }
3401             t1.deleteSubtree( t1.getNode( "B" ), false );
3402             if ( t1.getNumberOfExternalNodes() != 1 ) {
3403                 return false;
3404             }
3405             t1.deleteSubtree( t1.getNode( "r" ), false );
3406             if ( !t1.isEmpty() ) {
3407                 return false;
3408             }
3409             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3410             if ( t2.getNumberOfExternalNodes() != 3 ) {
3411                 return false;
3412             }
3413             t2.deleteSubtree( t2.getNode( "B" ), false );
3414             if ( t2.getNumberOfExternalNodes() != 2 ) {
3415                 return false;
3416             }
3417             t2.toNewHampshireX();
3418             PhylogenyNode n = t2.getNode( "A" );
3419             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3420                 return false;
3421             }
3422             t2.deleteSubtree( t2.getNode( "A" ), false );
3423             if ( t2.getNumberOfExternalNodes() != 2 ) {
3424                 return false;
3425             }
3426             t2.deleteSubtree( t2.getNode( "C" ), true );
3427             if ( t2.getNumberOfExternalNodes() != 1 ) {
3428                 return false;
3429             }
3430             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3431             if ( t3.getNumberOfExternalNodes() != 4 ) {
3432                 return false;
3433             }
3434             t3.deleteSubtree( t3.getNode( "B" ), true );
3435             if ( t3.getNumberOfExternalNodes() != 3 ) {
3436                 return false;
3437             }
3438             n = t3.getNode( "A" );
3439             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3440                 return false;
3441             }
3442             n = n.getNextExternalNode();
3443             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3444                 return false;
3445             }
3446             t3.deleteSubtree( t3.getNode( "A" ), true );
3447             if ( t3.getNumberOfExternalNodes() != 2 ) {
3448                 return false;
3449             }
3450             n = t3.getNode( "C" );
3451             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3452                 return false;
3453             }
3454             t3.deleteSubtree( t3.getNode( "C" ), true );
3455             if ( t3.getNumberOfExternalNodes() != 1 ) {
3456                 return false;
3457             }
3458             t3.deleteSubtree( t3.getNode( "D" ), true );
3459             if ( t3.getNumberOfExternalNodes() != 0 ) {
3460                 return false;
3461             }
3462             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3463             if ( t4.getNumberOfExternalNodes() != 6 ) {
3464                 return false;
3465             }
3466             t4.deleteSubtree( t4.getNode( "B2" ), true );
3467             if ( t4.getNumberOfExternalNodes() != 5 ) {
3468                 return false;
3469             }
3470             String s = w.toNewHampshire( t4, false, true ).toString();
3471             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3472                 return false;
3473             }
3474             t4.deleteSubtree( t4.getNode( "B11" ), true );
3475             if ( t4.getNumberOfExternalNodes() != 4 ) {
3476                 return false;
3477             }
3478             t4.deleteSubtree( t4.getNode( "C" ), true );
3479             if ( t4.getNumberOfExternalNodes() != 3 ) {
3480                 return false;
3481             }
3482             n = t4.getNode( "A" );
3483             n = n.getNextExternalNode();
3484             if ( !n.getName().equals( "B12" ) ) {
3485                 return false;
3486             }
3487             n = n.getNextExternalNode();
3488             if ( !n.getName().equals( "D" ) ) {
3489                 return false;
3490             }
3491             s = w.toNewHampshire( t4, false, true ).toString();
3492             if ( !s.equals( "((A,B12),D);" ) ) {
3493                 return false;
3494             }
3495             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3496             t5.deleteSubtree( t5.getNode( "A" ), true );
3497             if ( t5.getNumberOfExternalNodes() != 5 ) {
3498                 return false;
3499             }
3500             s = w.toNewHampshire( t5, false, true ).toString();
3501             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3502                 return false;
3503             }
3504             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3505             t6.deleteSubtree( t6.getNode( "B11" ), true );
3506             if ( t6.getNumberOfExternalNodes() != 5 ) {
3507                 return false;
3508             }
3509             s = w.toNewHampshire( t6, false, false ).toString();
3510             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3511                 return false;
3512             }
3513             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3514             t7.deleteSubtree( t7.getNode( "B12" ), true );
3515             if ( t7.getNumberOfExternalNodes() != 5 ) {
3516                 return false;
3517             }
3518             s = w.toNewHampshire( t7, false, true ).toString();
3519             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3520                 return false;
3521             }
3522             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3523             t8.deleteSubtree( t8.getNode( "B2" ), true );
3524             if ( t8.getNumberOfExternalNodes() != 5 ) {
3525                 return false;
3526             }
3527             s = w.toNewHampshire( t8, false, false ).toString();
3528             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3529                 return false;
3530             }
3531             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3532             t9.deleteSubtree( t9.getNode( "C" ), true );
3533             if ( t9.getNumberOfExternalNodes() != 5 ) {
3534                 return false;
3535             }
3536             s = w.toNewHampshire( t9, false, true ).toString();
3537             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3538                 return false;
3539             }
3540             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3541             t10.deleteSubtree( t10.getNode( "D" ), true );
3542             if ( t10.getNumberOfExternalNodes() != 5 ) {
3543                 return false;
3544             }
3545             s = w.toNewHampshire( t10, false, true ).toString();
3546             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3547                 return false;
3548             }
3549             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3550             t11.deleteSubtree( t11.getNode( "A" ), true );
3551             if ( t11.getNumberOfExternalNodes() != 2 ) {
3552                 return false;
3553             }
3554             s = w.toNewHampshire( t11, false, true ).toString();
3555             if ( !s.equals( "(B,C);" ) ) {
3556                 return false;
3557             }
3558             t11.deleteSubtree( t11.getNode( "C" ), true );
3559             if ( t11.getNumberOfExternalNodes() != 1 ) {
3560                 return false;
3561             }
3562             s = w.toNewHampshire( t11, false, false ).toString();
3563             if ( !s.equals( "B;" ) ) {
3564                 return false;
3565             }
3566             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3567             t12.deleteSubtree( t12.getNode( "B2" ), true );
3568             if ( t12.getNumberOfExternalNodes() != 8 ) {
3569                 return false;
3570             }
3571             s = w.toNewHampshire( t12, false, true ).toString();
3572             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3573                 return false;
3574             }
3575             t12.deleteSubtree( t12.getNode( "B3" ), true );
3576             if ( t12.getNumberOfExternalNodes() != 7 ) {
3577                 return false;
3578             }
3579             s = w.toNewHampshire( t12, false, true ).toString();
3580             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3581                 return false;
3582             }
3583             t12.deleteSubtree( t12.getNode( "C3" ), true );
3584             if ( t12.getNumberOfExternalNodes() != 6 ) {
3585                 return false;
3586             }
3587             s = w.toNewHampshire( t12, false, true ).toString();
3588             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3589                 return false;
3590             }
3591             t12.deleteSubtree( t12.getNode( "A1" ), true );
3592             if ( t12.getNumberOfExternalNodes() != 5 ) {
3593                 return false;
3594             }
3595             s = w.toNewHampshire( t12, false, true ).toString();
3596             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3597                 return false;
3598             }
3599             t12.deleteSubtree( t12.getNode( "B1" ), true );
3600             if ( t12.getNumberOfExternalNodes() != 4 ) {
3601                 return false;
3602             }
3603             s = w.toNewHampshire( t12, false, true ).toString();
3604             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3605                 return false;
3606             }
3607             t12.deleteSubtree( t12.getNode( "A3" ), true );
3608             if ( t12.getNumberOfExternalNodes() != 3 ) {
3609                 return false;
3610             }
3611             s = w.toNewHampshire( t12, false, true ).toString();
3612             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3613                 return false;
3614             }
3615             t12.deleteSubtree( t12.getNode( "A2" ), true );
3616             if ( t12.getNumberOfExternalNodes() != 2 ) {
3617                 return false;
3618             }
3619             s = w.toNewHampshire( t12, false, true ).toString();
3620             if ( !s.equals( "(C1,C2);" ) ) {
3621                 return false;
3622             }
3623             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3624             t13.deleteSubtree( t13.getNode( "D" ), true );
3625             if ( t13.getNumberOfExternalNodes() != 4 ) {
3626                 return false;
3627             }
3628             s = w.toNewHampshire( t13, false, true ).toString();
3629             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3630                 return false;
3631             }
3632             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3633             t14.deleteSubtree( t14.getNode( "E" ), true );
3634             if ( t14.getNumberOfExternalNodes() != 5 ) {
3635                 return false;
3636             }
3637             s = w.toNewHampshire( t14, false, true ).toString();
3638             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3639                 return false;
3640             }
3641             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3642             t15.deleteSubtree( t15.getNode( "B2" ), true );
3643             if ( t15.getNumberOfExternalNodes() != 11 ) {
3644                 return false;
3645             }
3646             t15.deleteSubtree( t15.getNode( "B1" ), true );
3647             if ( t15.getNumberOfExternalNodes() != 10 ) {
3648                 return false;
3649             }
3650             t15.deleteSubtree( t15.getNode( "B3" ), true );
3651             if ( t15.getNumberOfExternalNodes() != 9 ) {
3652                 return false;
3653             }
3654             t15.deleteSubtree( t15.getNode( "B4" ), true );
3655             if ( t15.getNumberOfExternalNodes() != 8 ) {
3656                 return false;
3657             }
3658             t15.deleteSubtree( t15.getNode( "A1" ), true );
3659             if ( t15.getNumberOfExternalNodes() != 7 ) {
3660                 return false;
3661             }
3662             t15.deleteSubtree( t15.getNode( "C4" ), true );
3663             if ( t15.getNumberOfExternalNodes() != 6 ) {
3664                 return false;
3665             }
3666         }
3667         catch ( final Exception e ) {
3668             e.printStackTrace( System.out );
3669             return false;
3670         }
3671         return true;
3672     }
3673
3674     private static boolean testDescriptiveStatistics() {
3675         try {
3676             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3677             dss1.addValue( 82 );
3678             dss1.addValue( 78 );
3679             dss1.addValue( 70 );
3680             dss1.addValue( 58 );
3681             dss1.addValue( 42 );
3682             if ( dss1.getN() != 5 ) {
3683                 return false;
3684             }
3685             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3686                 return false;
3687             }
3688             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3689                 return false;
3690             }
3691             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3692                 return false;
3693             }
3694             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3695                 return false;
3696             }
3697             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3698                 return false;
3699             }
3700             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3701                 return false;
3702             }
3703             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3704                 return false;
3705             }
3706             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3707                 return false;
3708             }
3709             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3710                 return false;
3711             }
3712             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3713                 return false;
3714             }
3715             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3716                 return false;
3717             }
3718             dss1.addValue( 123 );
3719             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3720                 return false;
3721             }
3722             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3723                 return false;
3724             }
3725             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3726                 return false;
3727             }
3728             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3729             dss2.addValue( -1.85 );
3730             dss2.addValue( 57.5 );
3731             dss2.addValue( 92.78 );
3732             dss2.addValue( 57.78 );
3733             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3734                 return false;
3735             }
3736             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3737                 return false;
3738             }
3739             final double[] a = dss2.getDataAsDoubleArray();
3740             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3741                 return false;
3742             }
3743             dss2.addValue( -100 );
3744             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3745                 return false;
3746             }
3747             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3748                 return false;
3749             }
3750             final double[] ds = new double[ 14 ];
3751             ds[ 0 ] = 34;
3752             ds[ 1 ] = 23;
3753             ds[ 2 ] = 1;
3754             ds[ 3 ] = 32;
3755             ds[ 4 ] = 11;
3756             ds[ 5 ] = 2;
3757             ds[ 6 ] = 12;
3758             ds[ 7 ] = 33;
3759             ds[ 8 ] = 13;
3760             ds[ 9 ] = 22;
3761             ds[ 10 ] = 21;
3762             ds[ 11 ] = 35;
3763             ds[ 12 ] = 24;
3764             ds[ 13 ] = 31;
3765             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3766             if ( bins.length != 4 ) {
3767                 return false;
3768             }
3769             if ( bins[ 0 ] != 2 ) {
3770                 return false;
3771             }
3772             if ( bins[ 1 ] != 3 ) {
3773                 return false;
3774             }
3775             if ( bins[ 2 ] != 4 ) {
3776                 return false;
3777             }
3778             if ( bins[ 3 ] != 5 ) {
3779                 return false;
3780             }
3781             final double[] ds1 = new double[ 9 ];
3782             ds1[ 0 ] = 10.0;
3783             ds1[ 1 ] = 19.0;
3784             ds1[ 2 ] = 9.999;
3785             ds1[ 3 ] = 0.0;
3786             ds1[ 4 ] = 39.9;
3787             ds1[ 5 ] = 39.999;
3788             ds1[ 6 ] = 30.0;
3789             ds1[ 7 ] = 19.999;
3790             ds1[ 8 ] = 30.1;
3791             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3792             if ( bins1.length != 4 ) {
3793                 return false;
3794             }
3795             if ( bins1[ 0 ] != 2 ) {
3796                 return false;
3797             }
3798             if ( bins1[ 1 ] != 3 ) {
3799                 return false;
3800             }
3801             if ( bins1[ 2 ] != 0 ) {
3802                 return false;
3803             }
3804             if ( bins1[ 3 ] != 4 ) {
3805                 return false;
3806             }
3807             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3808             if ( bins1_1.length != 3 ) {
3809                 return false;
3810             }
3811             if ( bins1_1[ 0 ] != 3 ) {
3812                 return false;
3813             }
3814             if ( bins1_1[ 1 ] != 2 ) {
3815                 return false;
3816             }
3817             if ( bins1_1[ 2 ] != 4 ) {
3818                 return false;
3819             }
3820             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3821             if ( bins1_2.length != 3 ) {
3822                 return false;
3823             }
3824             if ( bins1_2[ 0 ] != 2 ) {
3825                 return false;
3826             }
3827             if ( bins1_2[ 1 ] != 2 ) {
3828                 return false;
3829             }
3830             if ( bins1_2[ 2 ] != 2 ) {
3831                 return false;
3832             }
3833             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3834             dss3.addValue( 1 );
3835             dss3.addValue( 1 );
3836             dss3.addValue( 1 );
3837             dss3.addValue( 2 );
3838             dss3.addValue( 3 );
3839             dss3.addValue( 4 );
3840             dss3.addValue( 5 );
3841             dss3.addValue( 5 );
3842             dss3.addValue( 5 );
3843             dss3.addValue( 6 );
3844             dss3.addValue( 7 );
3845             dss3.addValue( 8 );
3846             dss3.addValue( 9 );
3847             dss3.addValue( 10 );
3848             dss3.addValue( 10 );
3849             dss3.addValue( 10 );
3850             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3851             histo.toStringBuffer( 10, '=', 40, 5 );
3852             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3853         }
3854         catch ( final Exception e ) {
3855             e.printStackTrace( System.out );
3856             return false;
3857         }
3858         return true;
3859     }
3860
3861     private static boolean testDir( final String file ) {
3862         try {
3863             final File f = new File( file );
3864             if ( !f.exists() ) {
3865                 return false;
3866             }
3867             if ( !f.isDirectory() ) {
3868                 return false;
3869             }
3870             if ( !f.canRead() ) {
3871                 return false;
3872             }
3873         }
3874         catch ( final Exception e ) {
3875             return false;
3876         }
3877         return true;
3878     }
3879
3880     private static boolean testEbiEntryRetrieval() {
3881         try {
3882             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3883             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3884                 System.out.println( entry.getAccession() );
3885                 return false;
3886             }
3887             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3888                 System.out.println( entry.getTaxonomyScientificName() );
3889                 return false;
3890             }
3891             if ( !entry.getSequenceName()
3892                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3893                 System.out.println( entry.getSequenceName() );
3894                 return false;
3895             }
3896             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3897             //     System.out.println( entry.getSequenceSymbol() );
3898             //     return false;
3899             // }
3900             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3901                 System.out.println( entry.getGeneName() );
3902                 return false;
3903             }
3904             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3905                 System.out.println( entry.getTaxonomyIdentifier() );
3906                 return false;
3907             }
3908             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3909                 System.out.println( entry.getAnnotations().first().getRefValue() );
3910                 return false;
3911             }
3912             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3913                 System.out.println( entry.getAnnotations().first().getRefSource() );
3914                 return false;
3915             }
3916             if ( entry.getCrossReferences().size() != 5 ) {
3917                 return false;
3918             }
3919             //
3920             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3921             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3922                 return false;
3923             }
3924             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3925                 System.out.println( entry1.getTaxonomyScientificName() );
3926                 return false;
3927             }
3928             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3929                 System.out.println( entry1.getSequenceName() );
3930                 return false;
3931             }
3932             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3933                 System.out.println( entry1.getTaxonomyIdentifier() );
3934                 return false;
3935             }
3936             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3937                 System.out.println( entry1.getGeneName() );
3938                 return false;
3939             }
3940             if ( entry1.getCrossReferences().size() != 6 ) {
3941                 return false;
3942             }
3943             //
3944             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3945             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3946                 return false;
3947             }
3948             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3949                 System.out.println( entry2.getTaxonomyScientificName() );
3950                 return false;
3951             }
3952             if ( !entry2.getSequenceName()
3953                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3954                 System.out.println( entry2.getSequenceName() );
3955                 return false;
3956             }
3957             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3958                 System.out.println( entry2.getTaxonomyIdentifier() );
3959                 return false;
3960             }
3961             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3962                 System.out.println( entry2.getGeneName() );
3963                 return false;
3964             }
3965             if ( entry2.getCrossReferences().size() != 3 ) {
3966                 return false;
3967             }
3968             //
3969             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3970             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3971                 return false;
3972             }
3973             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3974                 System.out.println( entry3.getTaxonomyScientificName() );
3975                 return false;
3976             }
3977             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3978                 System.out.println( entry3.getSequenceName() );
3979                 return false;
3980             }
3981             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3982                 System.out.println( entry3.getTaxonomyIdentifier() );
3983                 return false;
3984             }
3985             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3986                 System.out.println( entry3.getSequenceSymbol() );
3987                 return false;
3988             }
3989             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3990                 return false;
3991             }
3992             if ( entry3.getCrossReferences().size() != 8 ) {
3993                 return false;
3994             }
3995             //
3996             //
3997             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3998             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3999                 return false;
4000             }
4001             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4002                 System.out.println( entry4.getTaxonomyScientificName() );
4003                 return false;
4004             }
4005             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4006                 System.out.println( entry4.getSequenceName() );
4007                 return false;
4008             }
4009             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4010                 System.out.println( entry4.getTaxonomyIdentifier() );
4011                 return false;
4012             }
4013             if ( !entry4.getGeneName().equals( "ras" ) ) {
4014                 System.out.println( entry4.getGeneName() );
4015                 return false;
4016             }
4017             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4018             //     System.out.println( entry4.getChromosome() );
4019             //     return false;
4020             // }
4021             // if ( !entry4.getMap().equals( "ras" ) ) {
4022             //     System.out.println( entry4.getMap() );
4023             //     return false;
4024             // }
4025             //TODO FIXME gi...
4026             //
4027             //TODO fails:
4028             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4029             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4030             //                return false;
4031             //            }
4032             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4033             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4034                 return false;
4035             }
4036             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4037                 System.out.println( entry5.getTaxonomyScientificName() );
4038                 return false;
4039             }
4040             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4041                 System.out.println( entry5.getSequenceName() );
4042                 return false;
4043             }
4044             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4045                 System.out.println( entry5.getTaxonomyIdentifier() );
4046                 return false;
4047             }
4048         }
4049         catch ( final IOException e ) {
4050             System.out.println();
4051             System.out.println( "the following might be due to absence internet connection:" );
4052             e.printStackTrace( System.out );
4053             return true;
4054         }
4055         catch ( final Exception e ) {
4056             e.printStackTrace();
4057             return false;
4058         }
4059         return true;
4060     }
4061
4062     private static boolean testExternalNodeRelatedMethods() {
4063         try {
4064             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4065             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4066             PhylogenyNode n = t1.getNode( "A" );
4067             n = n.getNextExternalNode();
4068             if ( !n.getName().equals( "B" ) ) {
4069                 return false;
4070             }
4071             n = n.getNextExternalNode();
4072             if ( !n.getName().equals( "C" ) ) {
4073                 return false;
4074             }
4075             n = n.getNextExternalNode();
4076             if ( !n.getName().equals( "D" ) ) {
4077                 return false;
4078             }
4079             n = t1.getNode( "B" );
4080             while ( !n.isLastExternalNode() ) {
4081                 n = n.getNextExternalNode();
4082             }
4083             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4084             n = t2.getNode( "A" );
4085             n = n.getNextExternalNode();
4086             if ( !n.getName().equals( "B" ) ) {
4087                 return false;
4088             }
4089             n = n.getNextExternalNode();
4090             if ( !n.getName().equals( "C" ) ) {
4091                 return false;
4092             }
4093             n = n.getNextExternalNode();
4094             if ( !n.getName().equals( "D" ) ) {
4095                 return false;
4096             }
4097             n = t2.getNode( "B" );
4098             while ( !n.isLastExternalNode() ) {
4099                 n = n.getNextExternalNode();
4100             }
4101             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4102             n = t3.getNode( "A" );
4103             n = n.getNextExternalNode();
4104             if ( !n.getName().equals( "B" ) ) {
4105                 return false;
4106             }
4107             n = n.getNextExternalNode();
4108             if ( !n.getName().equals( "C" ) ) {
4109                 return false;
4110             }
4111             n = n.getNextExternalNode();
4112             if ( !n.getName().equals( "D" ) ) {
4113                 return false;
4114             }
4115             n = n.getNextExternalNode();
4116             if ( !n.getName().equals( "E" ) ) {
4117                 return false;
4118             }
4119             n = n.getNextExternalNode();
4120             if ( !n.getName().equals( "F" ) ) {
4121                 return false;
4122             }
4123             n = n.getNextExternalNode();
4124             if ( !n.getName().equals( "G" ) ) {
4125                 return false;
4126             }
4127             n = n.getNextExternalNode();
4128             if ( !n.getName().equals( "H" ) ) {
4129                 return false;
4130             }
4131             n = t3.getNode( "B" );
4132             while ( !n.isLastExternalNode() ) {
4133                 n = n.getNextExternalNode();
4134             }
4135             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4136             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4137                 final PhylogenyNode node = iter.next();
4138             }
4139             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4140             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4141                 final PhylogenyNode node = iter.next();
4142             }
4143             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4144             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4145             if ( !iter.next().getName().equals( "A" ) ) {
4146                 return false;
4147             }
4148             if ( !iter.next().getName().equals( "B" ) ) {
4149                 return false;
4150             }
4151             if ( !iter.next().getName().equals( "C" ) ) {
4152                 return false;
4153             }
4154             if ( !iter.next().getName().equals( "D" ) ) {
4155                 return false;
4156             }
4157             if ( !iter.next().getName().equals( "E" ) ) {
4158                 return false;
4159             }
4160             if ( !iter.next().getName().equals( "F" ) ) {
4161                 return false;
4162             }
4163             if ( iter.hasNext() ) {
4164                 return false;
4165             }
4166         }
4167         catch ( final Exception e ) {
4168             e.printStackTrace( System.out );
4169             return false;
4170         }
4171         return true;
4172     }
4173
4174     private static boolean testExtractSNFromNodeName() {
4175         try {
4176             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4177                 return false;
4178             }
4179             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4180                     .equals( "Mus musculus musculus" ) ) {
4181                 return false;
4182             }
4183             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4184                     .equals( "Mus musculus musculus" ) ) {
4185                 return false;
4186             }
4187             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4188                 return false;
4189             }
4190             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4191                     .equals( "Mus musculus" ) ) {
4192                 return false;
4193             }
4194             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4195                 return false;
4196             }
4197             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus" )
4198                     .equals( "Mus musculus musculus" ) ) {
4199                 return false;
4200             }
4201             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4202                 return false;
4203             }
4204         }
4205         catch ( final Exception e ) {
4206             e.printStackTrace( System.out );
4207             return false;
4208         }
4209         return true;
4210     }
4211
4212     private static boolean testExtractTaxonomyCodeFromNodeName() {
4213         try {
4214             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4215                 return false;
4216             }
4217             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4218                     .equals( "SOYBN" ) ) {
4219                 return false;
4220             }
4221             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4222                     .equals( "ARATH" ) ) {
4223                 return false;
4224             }
4225             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4226                     .equals( "ARATH" ) ) {
4227                 return false;
4228             }
4229             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4230                 return false;
4231             }
4232             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4233                 return false;
4234             }
4235             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4236                 return false;
4237             }
4238             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4239                     .equals( "SOYBN" ) ) {
4240                 return false;
4241             }
4242             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4243                     .equals( "SOYBN" ) ) {
4244                 return false;
4245             }
4246             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4247                     .equals( "SOYBN" ) ) {
4248                 return false;
4249             }
4250             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4251                     .equals( "SOYBN" ) ) {
4252                 return false;
4253             }
4254             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4255                     .equals( "SOYBN" ) ) {
4256                 return false;
4257             }
4258             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4259                     .equals( "SOYBN" ) ) {
4260                 return false;
4261             }
4262             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4263                     .equals( "SOYBN" ) ) {
4264                 return false;
4265             }
4266             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4267                     .equals( "SOYBN" ) ) {
4268                 return false;
4269             }
4270             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4271                 return false;
4272             }
4273             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4274                     .equals( "SOYBN" ) ) {
4275                 return false;
4276             }
4277             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4278                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4279                 return false;
4280             }
4281             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4282                     .equals( "9YX45" ) ) {
4283                 return false;
4284             }
4285             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4286                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4287                     .equals( "MOUSE" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4291                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4292                     .equals( "MOUSE" ) ) {
4293                 return false;
4294             }
4295             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4296                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4297                     .equals( "MOUSE" ) ) {
4298                 return false;
4299             }
4300             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4301                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4302                 return false;
4303             }
4304             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4305                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4309                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4313                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4314                 return false;
4315             }
4316             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4317                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4318                 return false;
4319             }
4320             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4321                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4322                 return false;
4323             }
4324             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4325                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4329                     .equals( "RAT" ) ) {
4330                 return false;
4331             }
4332             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4333                     .equals( "PIG" ) ) {
4334                 return false;
4335             }
4336             if ( !ParserUtils
4337                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4338                     .equals( "MOUSE" ) ) {
4339                 return false;
4340             }
4341             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4342                     .equals( "MOUSE" ) ) {
4343                 return false;
4344             }
4345             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4346                 return false;
4347             }
4348         }
4349         catch ( final Exception e ) {
4350             e.printStackTrace( System.out );
4351             return false;
4352         }
4353         return true;
4354     }
4355
4356     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4357         try {
4358             PhylogenyNode n = new PhylogenyNode();
4359             n.setName( "tr|B3RJ64" );
4360             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4361                 return false;
4362             }
4363             n.setName( "tr.B3RJ64" );
4364             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4365                 return false;
4366             }
4367             n.setName( "tr=B3RJ64" );
4368             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4369                 return false;
4370             }
4371             n.setName( "tr-B3RJ64" );
4372             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4373                 return false;
4374             }
4375             n.setName( "tr/B3RJ64" );
4376             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4377                 return false;
4378             }
4379             n.setName( "tr\\B3RJ64" );
4380             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4381                 return false;
4382             }
4383             n.setName( "tr_B3RJ64" );
4384             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4385                 return false;
4386             }
4387             n.setName( " tr|B3RJ64 " );
4388             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4389                 return false;
4390             }
4391             n.setName( "-tr|B3RJ64-" );
4392             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4393                 return false;
4394             }
4395             n.setName( "-tr=B3RJ64-" );
4396             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4397                 return false;
4398             }
4399             n.setName( "_tr=B3RJ64_" );
4400             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4401                 return false;
4402             }
4403             n.setName( " tr_tr|B3RJ64_sp|123 " );
4404             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4405                 return false;
4406             }
4407             n.setName( "B3RJ64" );
4408             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4409                 return false;
4410             }
4411             n.setName( "sp|B3RJ64" );
4412             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4413                 return false;
4414             }
4415             n.setName( "sp|B3RJ64C" );
4416             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4417                 return false;
4418             }
4419             n.setName( "sp B3RJ64" );
4420             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4421                 return false;
4422             }
4423             n.setName( "sp|B3RJ6X" );
4424             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4425                 return false;
4426             }
4427             n.setName( "sp|B3RJ6" );
4428             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4429                 return false;
4430             }
4431             n.setName( "K1PYK7_CRAGI" );
4432             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4433                 return false;
4434             }
4435             n.setName( "K1PYK7_PEA" );
4436             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4437                 return false;
4438             }
4439             n.setName( "K1PYK7_RAT" );
4440             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4441                 return false;
4442             }
4443             n.setName( "K1PYK7_PIG" );
4444             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4445                 return false;
4446             }
4447             n.setName( "~K1PYK7_PIG~" );
4448             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4449                 return false;
4450             }
4451             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4452             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4453                 return false;
4454             }
4455             n.setName( "K1PYKX_CRAGI" );
4456             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4457                 return false;
4458             }
4459             n.setName( "XXXXX_CRAGI" );
4460             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4461                 return false;
4462             }
4463             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4464             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4465                 return false;
4466             }
4467             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4468             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4469                 return false;
4470             }
4471             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4472             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4473                 return false;
4474             }
4475             n = new PhylogenyNode();
4476             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4477             seq.setSymbol( "K1PYK7_CRAGI" );
4478             n.getNodeData().addSequence( seq );
4479             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4480                 return false;
4481             }
4482             seq.setSymbol( "tr|B3RJ64" );
4483             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4484                 return false;
4485             }
4486             n = new PhylogenyNode();
4487             seq = new org.forester.phylogeny.data.Sequence();
4488             seq.setName( "K1PYK7_CRAGI" );
4489             n.getNodeData().addSequence( seq );
4490             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4491                 return false;
4492             }
4493             seq.setName( "tr|B3RJ64" );
4494             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4495                 return false;
4496             }
4497             n = new PhylogenyNode();
4498             seq = new org.forester.phylogeny.data.Sequence();
4499             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4500             n.getNodeData().addSequence( seq );
4501             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4502                 return false;
4503             }
4504             n = new PhylogenyNode();
4505             seq = new org.forester.phylogeny.data.Sequence();
4506             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4507             n.getNodeData().addSequence( seq );
4508             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4509                 return false;
4510             }
4511             //
4512             n = new PhylogenyNode();
4513             n.setName( "ACP19736" );
4514             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4515                 return false;
4516             }
4517             n = new PhylogenyNode();
4518             n.setName( "|ACP19736|" );
4519             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4520                 return false;
4521             }
4522         }
4523         catch ( final Exception e ) {
4524             e.printStackTrace( System.out );
4525             return false;
4526         }
4527         return true;
4528     }
4529
4530     private static boolean testFastaParser() {
4531         try {
4532             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4533                 return false;
4534             }
4535             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4536                 return false;
4537             }
4538             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4539             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4540                 return false;
4541             }
4542             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4543                 return false;
4544             }
4545             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4546                 return false;
4547             }
4548             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4549                 return false;
4550             }
4551             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4552                 return false;
4553             }
4554             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4555                 return false;
4556             }
4557         }
4558         catch ( final Exception e ) {
4559             e.printStackTrace();
4560             return false;
4561         }
4562         return true;
4563     }
4564
4565     private static boolean testGenbankAccessorParsing() {
4566         //The format for GenBank Accession numbers are:
4567         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4568         //Protein:    3 letters + 5 numerals
4569         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4570         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4571             return false;
4572         }
4573         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4574             return false;
4575         }
4576         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4577             return false;
4578         }
4579         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4580             return false;
4581         }
4582         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4583             return false;
4584         }
4585         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4586             return false;
4587         }
4588         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4589             return false;
4590         }
4591         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4592             return false;
4593         }
4594         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4595             return false;
4596         }
4597         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4598             return false;
4599         }
4600         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4601             return false;
4602         }
4603         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4604             return false;
4605         }
4606         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4607             return false;
4608         }
4609         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4610             return false;
4611         }
4612         return true;
4613     }
4614
4615     private static boolean testGeneralMsaParser() {
4616         try {
4617             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4618             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4619             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4620             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4621             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4622             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4623             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4624             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4625             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4626                 return false;
4627             }
4628             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4629                 return false;
4630             }
4631             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4632                 return false;
4633             }
4634             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4635                 return false;
4636             }
4637             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4638                 return false;
4639             }
4640             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4641                 return false;
4642             }
4643             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4644                 return false;
4645             }
4646             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4647                 return false;
4648             }
4649             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4650                 return false;
4651             }
4652             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4653                 return false;
4654             }
4655             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4656                 return false;
4657             }
4658             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4659                 return false;
4660             }
4661             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4662             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4663                 return false;
4664             }
4665             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4666                 return false;
4667             }
4668             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4669                 return false;
4670             }
4671             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4672             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4673                 return false;
4674             }
4675             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4676                 return false;
4677             }
4678             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4679                 return false;
4680             }
4681             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4682             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4683                 return false;
4684             }
4685             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4686                 return false;
4687             }
4688             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4689                 return false;
4690             }
4691         }
4692         catch ( final Exception e ) {
4693             e.printStackTrace();
4694             return false;
4695         }
4696         return true;
4697     }
4698
4699     private static boolean testGeneralTable() {
4700         try {
4701             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4702             t0.setValue( 3, 2, "23" );
4703             t0.setValue( 10, 1, "error" );
4704             t0.setValue( 10, 1, "110" );
4705             t0.setValue( 9, 1, "19" );
4706             t0.setValue( 1, 10, "101" );
4707             t0.setValue( 10, 10, "1010" );
4708             t0.setValue( 100, 10, "10100" );
4709             t0.setValue( 0, 0, "00" );
4710             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4711                 return false;
4712             }
4713             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4714                 return false;
4715             }
4716             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4717                 return false;
4718             }
4719             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4720                 return false;
4721             }
4722             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4723                 return false;
4724             }
4725             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4726                 return false;
4727             }
4728             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4729                 return false;
4730             }
4731             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4732                 return false;
4733             }
4734             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4735                 return false;
4736             }
4737             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4738             t1.setValue( "3", "2", "23" );
4739             t1.setValue( "10", "1", "error" );
4740             t1.setValue( "10", "1", "110" );
4741             t1.setValue( "9", "1", "19" );
4742             t1.setValue( "1", "10", "101" );
4743             t1.setValue( "10", "10", "1010" );
4744             t1.setValue( "100", "10", "10100" );
4745             t1.setValue( "0", "0", "00" );
4746             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4747             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4748                 return false;
4749             }
4750             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4751                 return false;
4752             }
4753             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4754                 return false;
4755             }
4756             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4757                 return false;
4758             }
4759             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4760                 return false;
4761             }
4762             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4763                 return false;
4764             }
4765             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4766                 return false;
4767             }
4768             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4769                 return false;
4770             }
4771             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4772                 return false;
4773             }
4774             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4775                 return false;
4776             }
4777         }
4778         catch ( final Exception e ) {
4779             e.printStackTrace( System.out );
4780             return false;
4781         }
4782         return true;
4783     }
4784
4785     private static boolean testGetDistance() {
4786         try {
4787             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4788             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",
4789                                                  new NHXParser() )[ 0 ];
4790             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4791                 return false;
4792             }
4793             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4794                 return false;
4795             }
4796             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4797                 return false;
4798             }
4799             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4800                 return false;
4801             }
4802             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4803                 return false;
4804             }
4805             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4806                 return false;
4807             }
4808             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4809                 return false;
4810             }
4811             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4812                 return false;
4813             }
4814             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4815                 return false;
4816             }
4817             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4818                 return false;
4819             }
4820             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4821                 return false;
4822             }
4823             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4824                 return false;
4825             }
4826             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4827                 return false;
4828             }
4829             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4830                 return false;
4831             }
4832             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4833                 return false;
4834             }
4835             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4836                 return false;
4837             }
4838             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4839                 return false;
4840             }
4841             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4842                 return false;
4843             }
4844             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4845                 return false;
4846             }
4847             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4848                 return false;
4849             }
4850             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4851                 return false;
4852             }
4853             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4854                 return false;
4855             }
4856             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4857                 return false;
4858             }
4859             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4860                 return false;
4861             }
4862             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4863                 return false;
4864             }
4865             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4866                 return false;
4867             }
4868             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4869                 return false;
4870             }
4871             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4872                 return false;
4873             }
4874             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4875                 return false;
4876             }
4877             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4878                 return false;
4879             }
4880             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4881                 return false;
4882             }
4883             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",
4884                                                  new NHXParser() )[ 0 ];
4885             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4886                 return false;
4887             }
4888             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4889                 return false;
4890             }
4891             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4892                 return false;
4893             }
4894             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4895                 return false;
4896             }
4897             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4898                 return false;
4899             }
4900             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4901                 return false;
4902             }
4903             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4904                 return false;
4905             }
4906             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4907                 return false;
4908             }
4909             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4910                 return false;
4911             }
4912             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4913                 return false;
4914             }
4915             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4916                 return false;
4917             }
4918         }
4919         catch ( final Exception e ) {
4920             e.printStackTrace( System.out );
4921             return false;
4922         }
4923         return true;
4924     }
4925
4926     private static boolean testGetLCA() {
4927         try {
4928             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4929             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4930                                                  new NHXParser() )[ 0 ];
4931             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4932             if ( !A.getName().equals( "A" ) ) {
4933                 return false;
4934             }
4935             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4936             if ( !gh.getName().equals( "gh" ) ) {
4937                 return false;
4938             }
4939             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4940             if ( !ab.getName().equals( "ab" ) ) {
4941                 return false;
4942             }
4943             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4944             if ( !ab2.getName().equals( "ab" ) ) {
4945                 return false;
4946             }
4947             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4948             if ( !gh2.getName().equals( "gh" ) ) {
4949                 return false;
4950             }
4951             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4952             if ( !gh3.getName().equals( "gh" ) ) {
4953                 return false;
4954             }
4955             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4956             if ( !abc.getName().equals( "abc" ) ) {
4957                 return false;
4958             }
4959             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4960             if ( !abc2.getName().equals( "abc" ) ) {
4961                 return false;
4962             }
4963             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4964             if ( !abcd.getName().equals( "abcd" ) ) {
4965                 return false;
4966             }
4967             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4968             if ( !abcd2.getName().equals( "abcd" ) ) {
4969                 return false;
4970             }
4971             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4972             if ( !abcdef.getName().equals( "abcdef" ) ) {
4973                 return false;
4974             }
4975             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4976             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4977                 return false;
4978             }
4979             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4980             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4981                 return false;
4982             }
4983             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4984             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4985                 return false;
4986             }
4987             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4988             if ( !abcde.getName().equals( "abcde" ) ) {
4989                 return false;
4990             }
4991             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4992             if ( !abcde2.getName().equals( "abcde" ) ) {
4993                 return false;
4994             }
4995             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4996             if ( !r.getName().equals( "abcdefgh" ) ) {
4997                 return false;
4998             }
4999             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5000             if ( !r2.getName().equals( "abcdefgh" ) ) {
5001                 return false;
5002             }
5003             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5004             if ( !r3.getName().equals( "abcdefgh" ) ) {
5005                 return false;
5006             }
5007             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5008             if ( !abcde3.getName().equals( "abcde" ) ) {
5009                 return false;
5010             }
5011             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5012             if ( !abcde4.getName().equals( "abcde" ) ) {
5013                 return false;
5014             }
5015             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5016             if ( !ab3.getName().equals( "ab" ) ) {
5017                 return false;
5018             }
5019             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5020             if ( !ab4.getName().equals( "ab" ) ) {
5021                 return false;
5022             }
5023             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5024             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5025             if ( !cd.getName().equals( "cd" ) ) {
5026                 return false;
5027             }
5028             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5029             if ( !cd2.getName().equals( "cd" ) ) {
5030                 return false;
5031             }
5032             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5033             if ( !cde.getName().equals( "cde" ) ) {
5034                 return false;
5035             }
5036             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5037             if ( !cde2.getName().equals( "cde" ) ) {
5038                 return false;
5039             }
5040             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5041             if ( !cdef.getName().equals( "cdef" ) ) {
5042                 return false;
5043             }
5044             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5045             if ( !cdef2.getName().equals( "cdef" ) ) {
5046                 return false;
5047             }
5048             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5049             if ( !cdef3.getName().equals( "cdef" ) ) {
5050                 return false;
5051             }
5052             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5053             if ( !rt.getName().equals( "r" ) ) {
5054                 return false;
5055             }
5056             final Phylogeny p3 = factory
5057                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5058                              new NHXParser() )[ 0 ];
5059             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5060             if ( !bc_3.getName().equals( "bc" ) ) {
5061                 return false;
5062             }
5063             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5064             if ( !ac_3.getName().equals( "abc" ) ) {
5065                 return false;
5066             }
5067             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5068             if ( !ad_3.getName().equals( "abcde" ) ) {
5069                 return false;
5070             }
5071             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5072             if ( !af_3.getName().equals( "abcdef" ) ) {
5073                 return false;
5074             }
5075             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5076             if ( !ag_3.getName().equals( "" ) ) {
5077                 return false;
5078             }
5079             if ( !ag_3.isRoot() ) {
5080                 return false;
5081             }
5082             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5083             if ( !al_3.getName().equals( "" ) ) {
5084                 return false;
5085             }
5086             if ( !al_3.isRoot() ) {
5087                 return false;
5088             }
5089             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5090             if ( !kl_3.getName().equals( "" ) ) {
5091                 return false;
5092             }
5093             if ( !kl_3.isRoot() ) {
5094                 return false;
5095             }
5096             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5097             if ( !fl_3.getName().equals( "" ) ) {
5098                 return false;
5099             }
5100             if ( !fl_3.isRoot() ) {
5101                 return false;
5102             }
5103             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5104             if ( !gk_3.getName().equals( "ghijk" ) ) {
5105                 return false;
5106             }
5107             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5108             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5109             if ( !r_4.getName().equals( "r" ) ) {
5110                 return false;
5111             }
5112             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5113             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5114             if ( !r_5.getName().equals( "root" ) ) {
5115                 return false;
5116             }
5117             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5118             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5119             if ( !r_6.getName().equals( "rot" ) ) {
5120                 return false;
5121             }
5122             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5123             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5124             if ( !r_7.getName().equals( "rott" ) ) {
5125                 return false;
5126             }
5127         }
5128         catch ( final Exception e ) {
5129             e.printStackTrace( System.out );
5130             return false;
5131         }
5132         return true;
5133     }
5134
5135     private static boolean testGetLCA2() {
5136         try {
5137             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5138             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5139             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5140             PhylogenyMethods.preOrderReId( p_a );
5141             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5142                                                                                               p_a.getNode( "a" ) );
5143             if ( !p_a_1.getName().equals( "a" ) ) {
5144                 return false;
5145             }
5146             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5147             PhylogenyMethods.preOrderReId( p_b );
5148             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5149                                                                                               p_b.getNode( "a" ) );
5150             if ( !p_b_1.getName().equals( "b" ) ) {
5151                 return false;
5152             }
5153             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5154                                                                                               p_b.getNode( "b" ) );
5155             if ( !p_b_2.getName().equals( "b" ) ) {
5156                 return false;
5157             }
5158             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5159             PhylogenyMethods.preOrderReId( p_c );
5160             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5161                                                                                               p_c.getNode( "a" ) );
5162             if ( !p_c_1.getName().equals( "b" ) ) {
5163                 return false;
5164             }
5165             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5166                                                                                               p_c.getNode( "c" ) );
5167             if ( !p_c_2.getName().equals( "c" ) ) {
5168                 System.out.println( p_c_2.getName() );
5169                 System.exit( -1 );
5170                 return false;
5171             }
5172             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5173                                                                                               p_c.getNode( "b" ) );
5174             if ( !p_c_3.getName().equals( "b" ) ) {
5175                 return false;
5176             }
5177             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5178                                                                                               p_c.getNode( "a" ) );
5179             if ( !p_c_4.getName().equals( "c" ) ) {
5180                 return false;
5181             }
5182             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5183                                                  new NHXParser() )[ 0 ];
5184             PhylogenyMethods.preOrderReId( p1 );
5185             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5186                                                                                           p1.getNode( "A" ) );
5187             if ( !A.getName().equals( "A" ) ) {
5188                 return false;
5189             }
5190             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5191                                                                                            p1.getNode( "gh" ) );
5192             if ( !gh.getName().equals( "gh" ) ) {
5193                 return false;
5194             }
5195             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5196                                                                                            p1.getNode( "B" ) );
5197             if ( !ab.getName().equals( "ab" ) ) {
5198                 return false;
5199             }
5200             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5201                                                                                             p1.getNode( "A" ) );
5202             if ( !ab2.getName().equals( "ab" ) ) {
5203                 return false;
5204             }
5205             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5206                                                                                             p1.getNode( "G" ) );
5207             if ( !gh2.getName().equals( "gh" ) ) {
5208                 return false;
5209             }
5210             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5211                                                                                             p1.getNode( "H" ) );
5212             if ( !gh3.getName().equals( "gh" ) ) {
5213                 return false;
5214             }
5215             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5216                                                                                             p1.getNode( "A" ) );
5217             if ( !abc.getName().equals( "abc" ) ) {
5218                 return false;
5219             }
5220             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5221                                                                                              p1.getNode( "C" ) );
5222             if ( !abc2.getName().equals( "abc" ) ) {
5223                 return false;
5224             }
5225             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5226                                                                                              p1.getNode( "D" ) );
5227             if ( !abcd.getName().equals( "abcd" ) ) {
5228                 return false;
5229             }
5230             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5231                                                                                               p1.getNode( "A" ) );
5232             if ( !abcd2.getName().equals( "abcd" ) ) {
5233                 return false;
5234             }
5235             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5236                                                                                                p1.getNode( "F" ) );
5237             if ( !abcdef.getName().equals( "abcdef" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5241                                                                                                 p1.getNode( "A" ) );
5242             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5243                 return false;
5244             }
5245             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5246                                                                                                 p1.getNode( "F" ) );
5247             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5248                 return false;
5249             }
5250             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5251                                                                                                 p1.getNode( "ab" ) );
5252             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5253                 return false;
5254             }
5255             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5256                                                                                               p1.getNode( "E" ) );
5257             if ( !abcde.getName().equals( "abcde" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5261                                                                                                p1.getNode( "A" ) );
5262             if ( !abcde2.getName().equals( "abcde" ) ) {
5263                 return false;
5264             }
5265             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5266                                                                                           p1.getNode( "abcdefgh" ) );
5267             if ( !r.getName().equals( "abcdefgh" ) ) {
5268                 return false;
5269             }
5270             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5271                                                                                            p1.getNode( "H" ) );
5272             if ( !r2.getName().equals( "abcdefgh" ) ) {
5273                 return false;
5274             }
5275             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5276                                                                                            p1.getNode( "A" ) );
5277             if ( !r3.getName().equals( "abcdefgh" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5281                                                                                                p1.getNode( "abcde" ) );
5282             if ( !abcde3.getName().equals( "abcde" ) ) {
5283                 return false;
5284             }
5285             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5286                                                                                                p1.getNode( "E" ) );
5287             if ( !abcde4.getName().equals( "abcde" ) ) {
5288                 return false;
5289             }
5290             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5291                                                                                             p1.getNode( "B" ) );
5292             if ( !ab3.getName().equals( "ab" ) ) {
5293                 return false;
5294             }
5295             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5296                                                                                             p1.getNode( "ab" ) );
5297             if ( !ab4.getName().equals( "ab" ) ) {
5298                 return false;
5299             }
5300             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5301             PhylogenyMethods.preOrderReId( p2 );
5302             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5303                                                                                            p2.getNode( "d" ) );
5304             if ( !cd.getName().equals( "cd" ) ) {
5305                 return false;
5306             }
5307             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5308                                                                                             p2.getNode( "c" ) );
5309             if ( !cd2.getName().equals( "cd" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5313                                                                                             p2.getNode( "e" ) );
5314             if ( !cde.getName().equals( "cde" ) ) {
5315                 return false;
5316             }
5317             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5318                                                                                              p2.getNode( "c" ) );
5319             if ( !cde2.getName().equals( "cde" ) ) {
5320                 return false;
5321             }
5322             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5323                                                                                              p2.getNode( "f" ) );
5324             if ( !cdef.getName().equals( "cdef" ) ) {
5325                 return false;
5326             }
5327             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5328                                                                                               p2.getNode( "f" ) );
5329             if ( !cdef2.getName().equals( "cdef" ) ) {
5330                 return false;
5331             }
5332             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5333                                                                                               p2.getNode( "d" ) );
5334             if ( !cdef3.getName().equals( "cdef" ) ) {
5335                 return false;
5336             }
5337             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5338                                                                                            p2.getNode( "a" ) );
5339             if ( !rt.getName().equals( "r" ) ) {
5340                 return false;
5341             }
5342             final Phylogeny p3 = factory
5343                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5344                              new NHXParser() )[ 0 ];
5345             PhylogenyMethods.preOrderReId( p3 );
5346             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5347                                                                                              p3.getNode( "c" ) );
5348             if ( !bc_3.getName().equals( "bc" ) ) {
5349                 return false;
5350             }
5351             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5352                                                                                              p3.getNode( "c" ) );
5353             if ( !ac_3.getName().equals( "abc" ) ) {
5354                 return false;
5355             }
5356             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5357                                                                                              p3.getNode( "d" ) );
5358             if ( !ad_3.getName().equals( "abcde" ) ) {
5359                 return false;
5360             }
5361             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5362                                                                                              p3.getNode( "f" ) );
5363             if ( !af_3.getName().equals( "abcdef" ) ) {
5364                 return false;
5365             }
5366             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5367                                                                                              p3.getNode( "g" ) );
5368             if ( !ag_3.getName().equals( "" ) ) {
5369                 return false;
5370             }
5371             if ( !ag_3.isRoot() ) {
5372                 return false;
5373             }
5374             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5375                                                                                              p3.getNode( "l" ) );
5376             if ( !al_3.getName().equals( "" ) ) {
5377                 return false;
5378             }
5379             if ( !al_3.isRoot() ) {
5380                 return false;
5381             }
5382             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5383                                                                                              p3.getNode( "l" ) );
5384             if ( !kl_3.getName().equals( "" ) ) {
5385                 return false;
5386             }
5387             if ( !kl_3.isRoot() ) {
5388                 return false;
5389             }
5390             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5391                                                                                              p3.getNode( "l" ) );
5392             if ( !fl_3.getName().equals( "" ) ) {
5393                 return false;
5394             }
5395             if ( !fl_3.isRoot() ) {
5396                 return false;
5397             }
5398             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5399                                                                                              p3.getNode( "k" ) );
5400             if ( !gk_3.getName().equals( "ghijk" ) ) {
5401                 return false;
5402             }
5403             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5404             PhylogenyMethods.preOrderReId( p4 );
5405             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5406                                                                                             p4.getNode( "c" ) );
5407             if ( !r_4.getName().equals( "r" ) ) {
5408                 return false;
5409             }
5410             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5411             PhylogenyMethods.preOrderReId( p5 );
5412             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5413                                                                                             p5.getNode( "c" ) );
5414             if ( !r_5.getName().equals( "root" ) ) {
5415                 return false;
5416             }
5417             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5418             PhylogenyMethods.preOrderReId( p6 );
5419             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5420                                                                                             p6.getNode( "a" ) );
5421             if ( !r_6.getName().equals( "rot" ) ) {
5422                 return false;
5423             }
5424             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5425             PhylogenyMethods.preOrderReId( p7 );
5426             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5427                                                                                             p7.getNode( "e" ) );
5428             if ( !r_7.getName().equals( "rott" ) ) {
5429                 return false;
5430             }
5431             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5432                                                                                              p7.getNode( "a" ) );
5433             if ( !r_71.getName().equals( "rott" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5437                                                                                              p7.getNode( "rott" ) );
5438             if ( !r_72.getName().equals( "rott" ) ) {
5439                 return false;
5440             }
5441             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5442                                                                                              p7.getNode( "a" ) );
5443             if ( !r_73.getName().equals( "rott" ) ) {
5444                 return false;
5445             }
5446             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5447                                                                                              p7.getNode( "rott" ) );
5448             if ( !r_74.getName().equals( "rott" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5452                                                                                              p7.getNode( "e" ) );
5453             if ( !r_75.getName().equals( "e" ) ) {
5454                 return false;
5455             }
5456         }
5457         catch ( final Exception e ) {
5458             e.printStackTrace( System.out );
5459             return false;
5460         }
5461         return true;
5462     }
5463
5464     private static boolean testHmmscanOutputParser() {
5465         final String test_dir = Test.PATH_TO_TEST_DATA;
5466         try {
5467             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5468                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5469             parser1.parse();
5470             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5471                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5472             final List<Protein> proteins = parser2.parse();
5473             if ( parser2.getProteinsEncountered() != 4 ) {
5474                 return false;
5475             }
5476             if ( proteins.size() != 4 ) {
5477                 return false;
5478             }
5479             if ( parser2.getDomainsEncountered() != 69 ) {
5480                 return false;
5481             }
5482             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5483                 return false;
5484             }
5485             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5486                 return false;
5487             }
5488             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5489                 return false;
5490             }
5491             final Protein p1 = proteins.get( 0 );
5492             if ( p1.getNumberOfProteinDomains() != 15 ) {
5493                 return false;
5494             }
5495             if ( p1.getLength() != 850 ) {
5496                 return false;
5497             }
5498             final Protein p2 = proteins.get( 1 );
5499             if ( p2.getNumberOfProteinDomains() != 51 ) {
5500                 return false;
5501             }
5502             if ( p2.getLength() != 1291 ) {
5503                 return false;
5504             }
5505             final Protein p3 = proteins.get( 2 );
5506             if ( p3.getNumberOfProteinDomains() != 2 ) {
5507                 return false;
5508             }
5509             final Protein p4 = proteins.get( 3 );
5510             if ( p4.getNumberOfProteinDomains() != 1 ) {
5511                 return false;
5512             }
5513             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5514                 return false;
5515             }
5516             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5517                 return false;
5518             }
5519             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5520                 return false;
5521             }
5522             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5523                 return false;
5524             }
5525             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5526                 return false;
5527             }
5528             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5529                 return false;
5530             }
5531             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5532                 return false;
5533             }
5534         }
5535         catch ( final Exception e ) {
5536             e.printStackTrace( System.out );
5537             return false;
5538         }
5539         return true;
5540     }
5541
5542     private static boolean testLastExternalNodeMethods() {
5543         try {
5544             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5545             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5546             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5547             final PhylogenyNode n1 = t0.getNode( "A" );
5548             if ( n1.isLastExternalNode() ) {
5549                 return false;
5550             }
5551             final PhylogenyNode n2 = t0.getNode( "B" );
5552             if ( n2.isLastExternalNode() ) {
5553                 return false;
5554             }
5555             final PhylogenyNode n3 = t0.getNode( "C" );
5556             if ( n3.isLastExternalNode() ) {
5557                 return false;
5558             }
5559             final PhylogenyNode n4 = t0.getNode( "D" );
5560             if ( !n4.isLastExternalNode() ) {
5561                 return false;
5562             }
5563         }
5564         catch ( final Exception e ) {
5565             e.printStackTrace( System.out );
5566             return false;
5567         }
5568         return true;
5569     }
5570
5571     private static boolean testLevelOrderIterator() {
5572         try {
5573             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5574             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5575             PhylogenyNodeIterator it0;
5576             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5577                 it0.next();
5578             }
5579             for( it0.reset(); it0.hasNext(); ) {
5580                 it0.next();
5581             }
5582             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5583             if ( !it.next().getName().equals( "r" ) ) {
5584                 return false;
5585             }
5586             if ( !it.next().getName().equals( "ab" ) ) {
5587                 return false;
5588             }
5589             if ( !it.next().getName().equals( "cd" ) ) {
5590                 return false;
5591             }
5592             if ( !it.next().getName().equals( "A" ) ) {
5593                 return false;
5594             }
5595             if ( !it.next().getName().equals( "B" ) ) {
5596                 return false;
5597             }
5598             if ( !it.next().getName().equals( "C" ) ) {
5599                 return false;
5600             }
5601             if ( !it.next().getName().equals( "D" ) ) {
5602                 return false;
5603             }
5604             if ( it.hasNext() ) {
5605                 return false;
5606             }
5607             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",
5608                                                  new NHXParser() )[ 0 ];
5609             PhylogenyNodeIterator it2;
5610             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5611                 it2.next();
5612             }
5613             for( it2.reset(); it2.hasNext(); ) {
5614                 it2.next();
5615             }
5616             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5617             if ( !it3.next().getName().equals( "r" ) ) {
5618                 return false;
5619             }
5620             if ( !it3.next().getName().equals( "abc" ) ) {
5621                 return false;
5622             }
5623             if ( !it3.next().getName().equals( "defg" ) ) {
5624                 return false;
5625             }
5626             if ( !it3.next().getName().equals( "A" ) ) {
5627                 return false;
5628             }
5629             if ( !it3.next().getName().equals( "B" ) ) {
5630                 return false;
5631             }
5632             if ( !it3.next().getName().equals( "C" ) ) {
5633                 return false;
5634             }
5635             if ( !it3.next().getName().equals( "D" ) ) {
5636                 return false;
5637             }
5638             if ( !it3.next().getName().equals( "E" ) ) {
5639                 return false;
5640             }
5641             if ( !it3.next().getName().equals( "F" ) ) {
5642                 return false;
5643             }
5644             if ( !it3.next().getName().equals( "G" ) ) {
5645                 return false;
5646             }
5647             if ( !it3.next().getName().equals( "1" ) ) {
5648                 return false;
5649             }
5650             if ( !it3.next().getName().equals( "2" ) ) {
5651                 return false;
5652             }
5653             if ( !it3.next().getName().equals( "3" ) ) {
5654                 return false;
5655             }
5656             if ( !it3.next().getName().equals( "4" ) ) {
5657                 return false;
5658             }
5659             if ( !it3.next().getName().equals( "5" ) ) {
5660                 return false;
5661             }
5662             if ( !it3.next().getName().equals( "6" ) ) {
5663                 return false;
5664             }
5665             if ( !it3.next().getName().equals( "f1" ) ) {
5666                 return false;
5667             }
5668             if ( !it3.next().getName().equals( "f2" ) ) {
5669                 return false;
5670             }
5671             if ( !it3.next().getName().equals( "f3" ) ) {
5672                 return false;
5673             }
5674             if ( !it3.next().getName().equals( "a" ) ) {
5675                 return false;
5676             }
5677             if ( !it3.next().getName().equals( "b" ) ) {
5678                 return false;
5679             }
5680             if ( !it3.next().getName().equals( "f21" ) ) {
5681                 return false;
5682             }
5683             if ( !it3.next().getName().equals( "X" ) ) {
5684                 return false;
5685             }
5686             if ( !it3.next().getName().equals( "Y" ) ) {
5687                 return false;
5688             }
5689             if ( !it3.next().getName().equals( "Z" ) ) {
5690                 return false;
5691             }
5692             if ( it3.hasNext() ) {
5693                 return false;
5694             }
5695             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5696             PhylogenyNodeIterator it4;
5697             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5698                 it4.next();
5699             }
5700             for( it4.reset(); it4.hasNext(); ) {
5701                 it4.next();
5702             }
5703             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5704             if ( !it5.next().getName().equals( "r" ) ) {
5705                 return false;
5706             }
5707             if ( !it5.next().getName().equals( "A" ) ) {
5708                 return false;
5709             }
5710             if ( !it5.next().getName().equals( "B" ) ) {
5711                 return false;
5712             }
5713             if ( !it5.next().getName().equals( "C" ) ) {
5714                 return false;
5715             }
5716             if ( !it5.next().getName().equals( "D" ) ) {
5717                 return false;
5718             }
5719             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5720             PhylogenyNodeIterator it6;
5721             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5722                 it6.next();
5723             }
5724             for( it6.reset(); it6.hasNext(); ) {
5725                 it6.next();
5726             }
5727             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5728             if ( !it7.next().getName().equals( "A" ) ) {
5729                 return false;
5730             }
5731             if ( it.hasNext() ) {
5732                 return false;
5733             }
5734         }
5735         catch ( final Exception e ) {
5736             e.printStackTrace( System.out );
5737             return false;
5738         }
5739         return true;
5740     }
5741
5742     private static boolean testMafft( final String path ) {
5743         try {
5744             final List<String> opts = new ArrayList<String>();
5745             opts.add( "--maxiterate" );
5746             opts.add( "1000" );
5747             opts.add( "--localpair" );
5748             opts.add( "--quiet" );
5749             Msa msa = null;
5750             final MsaInferrer mafft = Mafft.createInstance( path );
5751             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5752             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5753                 return false;
5754             }
5755             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5756                 return false;
5757             }
5758         }
5759         catch ( final Exception e ) {
5760             e.printStackTrace( System.out );
5761             return false;
5762         }
5763         return true;
5764     }
5765
5766     private static boolean testMidpointrooting() {
5767         try {
5768             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5769             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5770             PhylogenyMethods.midpointRoot( t0 );
5771             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5772                 return false;
5773             }
5774             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5775                 return false;
5776             }
5777             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5778                            1 ) ) {
5779                 return false;
5780             }
5781             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",
5782                                                  new NHXParser() )[ 0 ];
5783             if ( !t1.isRooted() ) {
5784                 return false;
5785             }
5786             PhylogenyMethods.midpointRoot( t1 );
5787             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5788                 return false;
5789             }
5790             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5791                 return false;
5792             }
5793             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5794                 return false;
5795             }
5796             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5797                 return false;
5798             }
5799             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5800                 return false;
5801             }
5802             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5803                 return false;
5804             }
5805             t1.reRoot( t1.getNode( "A" ) );
5806             PhylogenyMethods.midpointRoot( t1 );
5807             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5808                 return false;
5809             }
5810             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5811                 return false;
5812             }
5813             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5814                 return false;
5815             }
5816             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5817                 return false;
5818             }
5819             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5820                 System.exit( -1 );
5821                 return false;
5822             }
5823             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5824                 return false;
5825             }
5826         }
5827         catch ( final Exception e ) {
5828             e.printStackTrace( System.out );
5829             return false;
5830         }
5831         return true;
5832     }
5833
5834     private static boolean testMsaQualityMethod() {
5835         try {
5836             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
5837             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
5838             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
5839             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
5840             final List<Sequence> l = new ArrayList<Sequence>();
5841             l.add( s0 );
5842             l.add( s1 );
5843             l.add( s2 );
5844             l.add( s3 );
5845             final Msa msa = BasicMsa.createInstance( l );
5846             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5847                 return false;
5848             }
5849             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5850                 return false;
5851             }
5852             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5853                 return false;
5854             }
5855             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5856                 return false;
5857             }
5858             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
5859                 return false;
5860             }
5861             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
5862                 return false;
5863             }
5864             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
5865                 return false;
5866             }
5867         }
5868         catch ( final Exception e ) {
5869             e.printStackTrace( System.out );
5870             return false;
5871         }
5872         return true;
5873     }
5874
5875     private static boolean testNextNodeWithCollapsing() {
5876         try {
5877             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5878             PhylogenyNode n;
5879             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5880             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5881             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5882             t0.getNode( "cd" ).setCollapse( true );
5883             t0.getNode( "cde" ).setCollapse( true );
5884             n = t0.getFirstExternalNode();
5885             while ( n != null ) {
5886                 ext.add( n );
5887                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5888             }
5889             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5890                 return false;
5891             }
5892             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5893                 return false;
5894             }
5895             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5896                 return false;
5897             }
5898             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5899                 return false;
5900             }
5901             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5902                 return false;
5903             }
5904             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5905                 return false;
5906             }
5907             ext.clear();
5908             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5909             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5910             t1.getNode( "ab" ).setCollapse( true );
5911             t1.getNode( "cd" ).setCollapse( true );
5912             t1.getNode( "cde" ).setCollapse( true );
5913             n = t1.getNode( "ab" );
5914             ext = new ArrayList<PhylogenyNode>();
5915             while ( n != null ) {
5916                 ext.add( n );
5917                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5918             }
5919             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5920                 return false;
5921             }
5922             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5923                 return false;
5924             }
5925             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5926                 return false;
5927             }
5928             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5929                 return false;
5930             }
5931             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5932                 return false;
5933             }
5934             //
5935             //
5936             ext.clear();
5937             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5938             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5939             t2.getNode( "ab" ).setCollapse( true );
5940             t2.getNode( "cd" ).setCollapse( true );
5941             t2.getNode( "cde" ).setCollapse( true );
5942             t2.getNode( "c" ).setCollapse( true );
5943             t2.getNode( "d" ).setCollapse( true );
5944             t2.getNode( "e" ).setCollapse( true );
5945             t2.getNode( "gh" ).setCollapse( true );
5946             n = t2.getNode( "ab" );
5947             ext = new ArrayList<PhylogenyNode>();
5948             while ( n != null ) {
5949                 ext.add( n );
5950                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5951             }
5952             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5953                 return false;
5954             }
5955             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5956                 return false;
5957             }
5958             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5959                 return false;
5960             }
5961             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5962                 return false;
5963             }
5964             //
5965             //
5966             ext.clear();
5967             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5968             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5969             t3.getNode( "ab" ).setCollapse( true );
5970             t3.getNode( "cd" ).setCollapse( true );
5971             t3.getNode( "cde" ).setCollapse( true );
5972             t3.getNode( "c" ).setCollapse( true );
5973             t3.getNode( "d" ).setCollapse( true );
5974             t3.getNode( "e" ).setCollapse( true );
5975             t3.getNode( "gh" ).setCollapse( true );
5976             t3.getNode( "fgh" ).setCollapse( true );
5977             n = t3.getNode( "ab" );
5978             ext = new ArrayList<PhylogenyNode>();
5979             while ( n != null ) {
5980                 ext.add( n );
5981                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5982             }
5983             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5984                 return false;
5985             }
5986             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5987                 return false;
5988             }
5989             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5990                 return false;
5991             }
5992             //
5993             //
5994             ext.clear();
5995             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5996             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5997             t4.getNode( "ab" ).setCollapse( true );
5998             t4.getNode( "cd" ).setCollapse( true );
5999             t4.getNode( "cde" ).setCollapse( true );
6000             t4.getNode( "c" ).setCollapse( true );
6001             t4.getNode( "d" ).setCollapse( true );
6002             t4.getNode( "e" ).setCollapse( true );
6003             t4.getNode( "gh" ).setCollapse( true );
6004             t4.getNode( "fgh" ).setCollapse( true );
6005             t4.getNode( "abcdefgh" ).setCollapse( true );
6006             n = t4.getNode( "abcdefgh" );
6007             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6008                 return false;
6009             }
6010             //
6011             //
6012             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6013             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6014             ext.clear();
6015             n = t5.getFirstExternalNode();
6016             while ( n != null ) {
6017                 ext.add( n );
6018                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6019             }
6020             if ( ext.size() != 8 ) {
6021                 return false;
6022             }
6023             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6024                 return false;
6025             }
6026             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6027                 return false;
6028             }
6029             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6030                 return false;
6031             }
6032             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6033                 return false;
6034             }
6035             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6036                 return false;
6037             }
6038             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6039                 return false;
6040             }
6041             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6042                 return false;
6043             }
6044             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6045                 return false;
6046             }
6047             //
6048             //
6049             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6050             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6051             ext.clear();
6052             t6.getNode( "ab" ).setCollapse( true );
6053             n = t6.getNode( "ab" );
6054             while ( n != null ) {
6055                 ext.add( n );
6056                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6057             }
6058             if ( ext.size() != 7 ) {
6059                 return false;
6060             }
6061             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6062                 return false;
6063             }
6064             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6065                 return false;
6066             }
6067             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6068                 return false;
6069             }
6070             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6071                 return false;
6072             }
6073             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6074                 return false;
6075             }
6076             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6077                 return false;
6078             }
6079             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6080                 return false;
6081             }
6082             //
6083             //
6084             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6085             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6086             ext.clear();
6087             t7.getNode( "cd" ).setCollapse( true );
6088             n = t7.getNode( "a" );
6089             while ( n != null ) {
6090                 ext.add( n );
6091                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6092             }
6093             if ( ext.size() != 7 ) {
6094                 return false;
6095             }
6096             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6097                 return false;
6098             }
6099             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6100                 return false;
6101             }
6102             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6103                 return false;
6104             }
6105             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6106                 return false;
6107             }
6108             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6109                 return false;
6110             }
6111             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6112                 return false;
6113             }
6114             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6115                 return false;
6116             }
6117             //
6118             //
6119             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6120             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6121             ext.clear();
6122             t8.getNode( "cd" ).setCollapse( true );
6123             t8.getNode( "c" ).setCollapse( true );
6124             t8.getNode( "d" ).setCollapse( true );
6125             n = t8.getNode( "a" );
6126             while ( n != null ) {
6127                 ext.add( n );
6128                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6129             }
6130             if ( ext.size() != 7 ) {
6131                 return false;
6132             }
6133             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6134                 return false;
6135             }
6136             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6137                 return false;
6138             }
6139             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6140                 System.out.println( "2 fail" );
6141                 return false;
6142             }
6143             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6144                 return false;
6145             }
6146             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6147                 return false;
6148             }
6149             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6150                 return false;
6151             }
6152             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6153                 return false;
6154             }
6155             //
6156             //
6157             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6158             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6159             ext.clear();
6160             t9.getNode( "gh" ).setCollapse( true );
6161             n = t9.getNode( "a" );
6162             while ( n != null ) {
6163                 ext.add( n );
6164                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6165             }
6166             if ( ext.size() != 7 ) {
6167                 return false;
6168             }
6169             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6170                 return false;
6171             }
6172             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6173                 return false;
6174             }
6175             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6176                 return false;
6177             }
6178             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6179                 return false;
6180             }
6181             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6182                 return false;
6183             }
6184             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6185                 return false;
6186             }
6187             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6188                 return false;
6189             }
6190             //
6191             //
6192             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6193             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6194             ext.clear();
6195             t10.getNode( "gh" ).setCollapse( true );
6196             t10.getNode( "g" ).setCollapse( true );
6197             t10.getNode( "h" ).setCollapse( true );
6198             n = t10.getNode( "a" );
6199             while ( n != null ) {
6200                 ext.add( n );
6201                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6202             }
6203             if ( ext.size() != 7 ) {
6204                 return false;
6205             }
6206             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6207                 return false;
6208             }
6209             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6210                 return false;
6211             }
6212             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6213                 return false;
6214             }
6215             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6216                 return false;
6217             }
6218             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6219                 return false;
6220             }
6221             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6222                 return false;
6223             }
6224             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6225                 return false;
6226             }
6227             //
6228             //
6229             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6230             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6231             ext.clear();
6232             t11.getNode( "gh" ).setCollapse( true );
6233             t11.getNode( "fgh" ).setCollapse( true );
6234             n = t11.getNode( "a" );
6235             while ( n != null ) {
6236                 ext.add( n );
6237                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6238             }
6239             if ( ext.size() != 6 ) {
6240                 return false;
6241             }
6242             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6243                 return false;
6244             }
6245             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6246                 return false;
6247             }
6248             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6249                 return false;
6250             }
6251             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6252                 return false;
6253             }
6254             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6255                 return false;
6256             }
6257             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6258                 return false;
6259             }
6260             //
6261             //
6262             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6263             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6264             ext.clear();
6265             t12.getNode( "gh" ).setCollapse( true );
6266             t12.getNode( "fgh" ).setCollapse( true );
6267             t12.getNode( "g" ).setCollapse( true );
6268             t12.getNode( "h" ).setCollapse( true );
6269             t12.getNode( "f" ).setCollapse( true );
6270             n = t12.getNode( "a" );
6271             while ( n != null ) {
6272                 ext.add( n );
6273                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6274             }
6275             if ( ext.size() != 6 ) {
6276                 return false;
6277             }
6278             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6279                 return false;
6280             }
6281             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6282                 return false;
6283             }
6284             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6285                 return false;
6286             }
6287             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6288                 return false;
6289             }
6290             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6291                 return false;
6292             }
6293             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6294                 return false;
6295             }
6296             //
6297             //
6298             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6299             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6300             ext.clear();
6301             t13.getNode( "ab" ).setCollapse( true );
6302             t13.getNode( "b" ).setCollapse( true );
6303             t13.getNode( "fgh" ).setCollapse( true );
6304             t13.getNode( "gh" ).setCollapse( true );
6305             n = t13.getNode( "ab" );
6306             while ( n != null ) {
6307                 ext.add( n );
6308                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6309             }
6310             if ( ext.size() != 5 ) {
6311                 return false;
6312             }
6313             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6314                 return false;
6315             }
6316             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6317                 return false;
6318             }
6319             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6320                 return false;
6321             }
6322             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6323                 return false;
6324             }
6325             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6326                 return false;
6327             }
6328             //
6329             //
6330             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6331             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6332             ext.clear();
6333             t14.getNode( "ab" ).setCollapse( true );
6334             t14.getNode( "a" ).setCollapse( true );
6335             t14.getNode( "fgh" ).setCollapse( true );
6336             t14.getNode( "gh" ).setCollapse( true );
6337             n = t14.getNode( "ab" );
6338             while ( n != null ) {
6339                 ext.add( n );
6340                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6341             }
6342             if ( ext.size() != 5 ) {
6343                 return false;
6344             }
6345             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6346                 return false;
6347             }
6348             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6349                 return false;
6350             }
6351             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6352                 return false;
6353             }
6354             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6355                 return false;
6356             }
6357             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6358                 return false;
6359             }
6360             //
6361             //
6362             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" );
6363             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6364             ext.clear();
6365             t15.getNode( "ab" ).setCollapse( true );
6366             t15.getNode( "a" ).setCollapse( true );
6367             t15.getNode( "fgh" ).setCollapse( true );
6368             t15.getNode( "gh" ).setCollapse( true );
6369             n = t15.getNode( "ab" );
6370             while ( n != null ) {
6371                 ext.add( n );
6372                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6373             }
6374             if ( ext.size() != 6 ) {
6375                 return false;
6376             }
6377             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6378                 return false;
6379             }
6380             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6381                 return false;
6382             }
6383             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6384                 return false;
6385             }
6386             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6387                 return false;
6388             }
6389             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6390                 return false;
6391             }
6392             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6393                 return false;
6394             }
6395             //
6396             //
6397             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" );
6398             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6399             ext.clear();
6400             t16.getNode( "ab" ).setCollapse( true );
6401             t16.getNode( "a" ).setCollapse( true );
6402             t16.getNode( "fgh" ).setCollapse( true );
6403             t16.getNode( "gh" ).setCollapse( true );
6404             t16.getNode( "cd" ).setCollapse( true );
6405             t16.getNode( "cde" ).setCollapse( true );
6406             t16.getNode( "d" ).setCollapse( true );
6407             t16.getNode( "x" ).setCollapse( true );
6408             n = t16.getNode( "ab" );
6409             while ( n != null ) {
6410                 ext.add( n );
6411                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6412             }
6413             if ( ext.size() != 4 ) {
6414                 return false;
6415             }
6416             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6417                 return false;
6418             }
6419             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6420                 return false;
6421             }
6422             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6423                 return false;
6424             }
6425             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6426                 return false;
6427             }
6428         }
6429         catch ( final Exception e ) {
6430             e.printStackTrace( System.out );
6431             return false;
6432         }
6433         return true;
6434     }
6435
6436     private static boolean testNexusCharactersParsing() {
6437         try {
6438             final NexusCharactersParser parser = new NexusCharactersParser();
6439             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6440             parser.parse();
6441             String[] labels = parser.getCharStateLabels();
6442             if ( labels.length != 7 ) {
6443                 return false;
6444             }
6445             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6446                 return false;
6447             }
6448             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6449                 return false;
6450             }
6451             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6452                 return false;
6453             }
6454             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6455                 return false;
6456             }
6457             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6458                 return false;
6459             }
6460             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6461                 return false;
6462             }
6463             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6464                 return false;
6465             }
6466             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6467             parser.parse();
6468             labels = parser.getCharStateLabels();
6469             if ( labels.length != 7 ) {
6470                 return false;
6471             }
6472             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6473                 return false;
6474             }
6475             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6476                 return false;
6477             }
6478             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6479                 return false;
6480             }
6481             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6482                 return false;
6483             }
6484             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6485                 return false;
6486             }
6487             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6488                 return false;
6489             }
6490             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6491                 return false;
6492             }
6493         }
6494         catch ( final Exception e ) {
6495             e.printStackTrace( System.out );
6496             return false;
6497         }
6498         return true;
6499     }
6500
6501     private static boolean testNexusMatrixParsing() {
6502         try {
6503             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6504             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6505             parser.parse();
6506             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6507             if ( m.getNumberOfCharacters() != 9 ) {
6508                 return false;
6509             }
6510             if ( m.getNumberOfIdentifiers() != 5 ) {
6511                 return false;
6512             }
6513             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6514                 return false;
6515             }
6516             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6517                 return false;
6518             }
6519             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6520                 return false;
6521             }
6522             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6523                 return false;
6524             }
6525             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6526                 return false;
6527             }
6528             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6529                 return false;
6530             }
6531             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6532                 return false;
6533             }
6534             //            if ( labels.length != 7 ) {
6535             //                return false;
6536             //            }
6537             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6538             //                return false;
6539             //            }
6540             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6541             //                return false;
6542             //            }
6543             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6544             //                return false;
6545             //            }
6546             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6547             //                return false;
6548             //            }
6549             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6550             //                return false;
6551             //            }
6552             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6553             //                return false;
6554             //            }
6555             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6556             //                return false;
6557             //            }
6558             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6559             //            parser.parse();
6560             //            labels = parser.getCharStateLabels();
6561             //            if ( labels.length != 7 ) {
6562             //                return false;
6563             //            }
6564             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6565             //                return false;
6566             //            }
6567             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6568             //                return false;
6569             //            }
6570             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6571             //                return false;
6572             //            }
6573             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6574             //                return false;
6575             //            }
6576             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6577             //                return false;
6578             //            }
6579             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6580             //                return false;
6581             //            }
6582             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6583             //                return false;
6584             //            }
6585         }
6586         catch ( final Exception e ) {
6587             e.printStackTrace( System.out );
6588             return false;
6589         }
6590         return true;
6591     }
6592
6593     private static boolean testNexusTreeParsing() {
6594         try {
6595             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6596             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6597             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6598             if ( phylogenies.length != 1 ) {
6599                 return false;
6600             }
6601             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6602                 return false;
6603             }
6604             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6605                 return false;
6606             }
6607             phylogenies = null;
6608             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6609             if ( phylogenies.length != 1 ) {
6610                 return false;
6611             }
6612             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6613                 return false;
6614             }
6615             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6616                 return false;
6617             }
6618             phylogenies = null;
6619             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6620             if ( phylogenies.length != 1 ) {
6621                 return false;
6622             }
6623             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6624                 return false;
6625             }
6626             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6627                 return false;
6628             }
6629             if ( phylogenies[ 0 ].isRooted() ) {
6630                 return false;
6631             }
6632             phylogenies = null;
6633             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6634             if ( phylogenies.length != 18 ) {
6635                 return false;
6636             }
6637             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6638                 return false;
6639             }
6640             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6641                 return false;
6642             }
6643             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6644                 return false;
6645             }
6646             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6647                 return false;
6648             }
6649             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6650                 return false;
6651             }
6652             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6653                 return false;
6654             }
6655             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6656                 return false;
6657             }
6658             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6659                 return false;
6660             }
6661             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6662                 return false;
6663             }
6664             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6665                 return false;
6666             }
6667             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6668                 return false;
6669             }
6670             if ( phylogenies[ 8 ].isRooted() ) {
6671                 return false;
6672             }
6673             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6674                 return false;
6675             }
6676             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6677                 return false;
6678             }
6679             if ( !phylogenies[ 9 ].isRooted() ) {
6680                 return false;
6681             }
6682             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6683                 return false;
6684             }
6685             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6686                 return false;
6687             }
6688             if ( !phylogenies[ 10 ].isRooted() ) {
6689                 return false;
6690             }
6691             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6692                 return false;
6693             }
6694             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6695                 return false;
6696             }
6697             if ( phylogenies[ 11 ].isRooted() ) {
6698                 return false;
6699             }
6700             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6701                 return false;
6702             }
6703             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6704                 return false;
6705             }
6706             if ( !phylogenies[ 12 ].isRooted() ) {
6707                 return false;
6708             }
6709             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6710                 return false;
6711             }
6712             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6713                 return false;
6714             }
6715             if ( !phylogenies[ 13 ].isRooted() ) {
6716                 return false;
6717             }
6718             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6719                 return false;
6720             }
6721             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6722                 return false;
6723             }
6724             if ( !phylogenies[ 14 ].isRooted() ) {
6725                 return false;
6726             }
6727             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6728                 return false;
6729             }
6730             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6731                 return false;
6732             }
6733             if ( phylogenies[ 15 ].isRooted() ) {
6734                 return false;
6735             }
6736             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6737                 return false;
6738             }
6739             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6740                 return false;
6741             }
6742             if ( !phylogenies[ 16 ].isRooted() ) {
6743                 return false;
6744             }
6745             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6746                 return false;
6747             }
6748             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6749                 return false;
6750             }
6751             if ( phylogenies[ 17 ].isRooted() ) {
6752                 return false;
6753             }
6754             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6755                 return false;
6756             }
6757             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
6758             phylogenies = null;
6759             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
6760             if ( phylogenies.length != 9 ) {
6761                 return false;
6762             }
6763             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
6764                     .getDistanceToParent() ) ) {
6765                 return false;
6766             }
6767             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
6768                     .getDistanceToParent() ) ) {
6769                 return false;
6770             }
6771             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
6772                 return false;
6773             }
6774             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6775                 return false;
6776             }
6777             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6778                 return false;
6779             }
6780             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6781                 return false;
6782             }
6783             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6784                 return false;
6785             }
6786         }
6787         catch ( final Exception e ) {
6788             e.printStackTrace( System.out );
6789             return false;
6790         }
6791         return true;
6792     }
6793
6794     private static boolean testNexusTreeParsingIterating() {
6795         try {
6796             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6797             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6798             if ( !p.hasNext() ) {
6799                 return false;
6800             }
6801             Phylogeny phy = p.next();
6802             if ( phy == null ) {
6803                 return false;
6804             }
6805             if ( phy.getNumberOfExternalNodes() != 25 ) {
6806                 return false;
6807             }
6808             if ( !phy.getName().equals( "" ) ) {
6809                 return false;
6810             }
6811             if ( p.hasNext() ) {
6812                 return false;
6813             }
6814             phy = p.next();
6815             if ( phy != null ) {
6816                 return false;
6817             }
6818             //
6819             p.reset();
6820             if ( !p.hasNext() ) {
6821                 return false;
6822             }
6823             phy = p.next();
6824             if ( phy == null ) {
6825                 return false;
6826             }
6827             if ( phy.getNumberOfExternalNodes() != 25 ) {
6828                 return false;
6829             }
6830             if ( !phy.getName().equals( "" ) ) {
6831                 return false;
6832             }
6833             if ( p.hasNext() ) {
6834                 return false;
6835             }
6836             phy = p.next();
6837             if ( phy != null ) {
6838                 return false;
6839             }
6840             ////
6841             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6842             if ( !p.hasNext() ) {
6843                 return false;
6844             }
6845             phy = p.next();
6846             if ( phy == null ) {
6847                 return false;
6848             }
6849             if ( phy.getNumberOfExternalNodes() != 10 ) {
6850                 return false;
6851             }
6852             if ( !phy.getName().equals( "name" ) ) {
6853                 return false;
6854             }
6855             if ( p.hasNext() ) {
6856                 return false;
6857             }
6858             phy = p.next();
6859             if ( phy != null ) {
6860                 return false;
6861             }
6862             //
6863             p.reset();
6864             if ( !p.hasNext() ) {
6865                 return false;
6866             }
6867             phy = p.next();
6868             if ( phy == null ) {
6869                 return false;
6870             }
6871             if ( phy.getNumberOfExternalNodes() != 10 ) {
6872                 return false;
6873             }
6874             if ( !phy.getName().equals( "name" ) ) {
6875                 return false;
6876             }
6877             if ( p.hasNext() ) {
6878                 return false;
6879             }
6880             phy = p.next();
6881             if ( phy != null ) {
6882                 return false;
6883             }
6884             //
6885             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6886             if ( !p.hasNext() ) {
6887                 return false;
6888             }
6889             phy = p.next();
6890             if ( phy == null ) {
6891                 return false;
6892             }
6893             if ( phy.getNumberOfExternalNodes() != 3 ) {
6894                 return false;
6895             }
6896             if ( !phy.getName().equals( "" ) ) {
6897                 return false;
6898             }
6899             if ( phy.isRooted() ) {
6900                 return false;
6901             }
6902             if ( p.hasNext() ) {
6903                 return false;
6904             }
6905             phy = p.next();
6906             if ( phy != null ) {
6907                 return false;
6908             }
6909             //
6910             p.reset();
6911             if ( !p.hasNext() ) {
6912                 return false;
6913             }
6914             phy = p.next();
6915             if ( phy == null ) {
6916                 return false;
6917             }
6918             if ( phy.getNumberOfExternalNodes() != 3 ) {
6919                 return false;
6920             }
6921             if ( !phy.getName().equals( "" ) ) {
6922                 return false;
6923             }
6924             if ( p.hasNext() ) {
6925                 return false;
6926             }
6927             phy = p.next();
6928             if ( phy != null ) {
6929                 return false;
6930             }
6931             //
6932             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6933             if ( !p.hasNext() ) {
6934                 return false;
6935             }
6936             //0
6937             phy = p.next();
6938             if ( phy == null ) {
6939                 return false;
6940             }
6941             if ( phy.getNumberOfExternalNodes() != 10 ) {
6942                 return false;
6943             }
6944             if ( !phy.getName().equals( "tree 0" ) ) {
6945                 return false;
6946             }
6947             //1
6948             if ( !p.hasNext() ) {
6949                 return false;
6950             }
6951             phy = p.next();
6952             if ( phy == null ) {
6953                 return false;
6954             }
6955             if ( phy.getNumberOfExternalNodes() != 10 ) {
6956                 return false;
6957             }
6958             if ( !phy.getName().equals( "tree 1" ) ) {
6959                 return false;
6960             }
6961             //2
6962             if ( !p.hasNext() ) {
6963                 return false;
6964             }
6965             phy = p.next();
6966             if ( phy == null ) {
6967                 return false;
6968             }
6969             if ( phy.getNumberOfExternalNodes() != 3 ) {
6970                 System.out.println( phy.toString() );
6971                 return false;
6972             }
6973             if ( !phy.getName().equals( "" ) ) {
6974                 return false;
6975             }
6976             if ( phy.isRooted() ) {
6977                 return false;
6978             }
6979             //3
6980             if ( !p.hasNext() ) {
6981                 return false;
6982             }
6983             phy = p.next();
6984             if ( phy == null ) {
6985                 return false;
6986             }
6987             if ( phy.getNumberOfExternalNodes() != 4 ) {
6988                 return false;
6989             }
6990             if ( !phy.getName().equals( "" ) ) {
6991                 return false;
6992             }
6993             if ( !phy.isRooted() ) {
6994                 return false;
6995             }
6996             //4
6997             if ( !p.hasNext() ) {
6998                 return false;
6999             }
7000             phy = p.next();
7001             if ( phy == null ) {
7002                 return false;
7003             }
7004             if ( phy.getNumberOfExternalNodes() != 5 ) {
7005                 System.out.println( phy.getNumberOfExternalNodes() );
7006                 return false;
7007             }
7008             if ( !phy.getName().equals( "" ) ) {
7009                 return false;
7010             }
7011             if ( !phy.isRooted() ) {
7012                 return false;
7013             }
7014             //5
7015             if ( !p.hasNext() ) {
7016                 return false;
7017             }
7018             phy = p.next();
7019             if ( phy == null ) {
7020                 return false;
7021             }
7022             if ( phy.getNumberOfExternalNodes() != 3 ) {
7023                 return false;
7024             }
7025             if ( !phy.getName().equals( "" ) ) {
7026                 return false;
7027             }
7028             if ( phy.isRooted() ) {
7029                 return false;
7030             }
7031             //6
7032             if ( !p.hasNext() ) {
7033                 return false;
7034             }
7035             phy = p.next();
7036             if ( phy == null ) {
7037                 return false;
7038             }
7039             if ( phy.getNumberOfExternalNodes() != 2 ) {
7040                 return false;
7041             }
7042             if ( !phy.getName().equals( "" ) ) {
7043                 return false;
7044             }
7045             if ( !phy.isRooted() ) {
7046                 return false;
7047             }
7048             //7
7049             if ( !p.hasNext() ) {
7050                 return false;
7051             }
7052             phy = p.next();
7053             if ( phy.getNumberOfExternalNodes() != 3 ) {
7054                 return false;
7055             }
7056             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7057                 return false;
7058             }
7059             if ( !phy.isRooted() ) {
7060                 return false;
7061             }
7062             //8
7063             if ( !p.hasNext() ) {
7064                 return false;
7065             }
7066             phy = p.next();
7067             if ( phy.getNumberOfExternalNodes() != 3 ) {
7068                 return false;
7069             }
7070             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7071                 return false;
7072             }
7073             if ( !phy.getName().equals( "tree 8" ) ) {
7074                 return false;
7075             }
7076             //9
7077             if ( !p.hasNext() ) {
7078                 return false;
7079             }
7080             phy = p.next();
7081             if ( phy.getNumberOfExternalNodes() != 3 ) {
7082                 return false;
7083             }
7084             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7085                 return false;
7086             }
7087             if ( !phy.getName().equals( "tree 9" ) ) {
7088                 return false;
7089             }
7090             //10
7091             if ( !p.hasNext() ) {
7092                 return false;
7093             }
7094             phy = p.next();
7095             if ( phy.getNumberOfExternalNodes() != 3 ) {
7096                 return false;
7097             }
7098             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7099                 return false;
7100             }
7101             if ( !phy.getName().equals( "tree 10" ) ) {
7102                 return false;
7103             }
7104             if ( !phy.isRooted() ) {
7105                 return false;
7106             }
7107             //11
7108             if ( !p.hasNext() ) {
7109                 return false;
7110             }
7111             phy = p.next();
7112             if ( phy.getNumberOfExternalNodes() != 3 ) {
7113                 return false;
7114             }
7115             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7116                 return false;
7117             }
7118             if ( !phy.getName().equals( "tree 11" ) ) {
7119                 return false;
7120             }
7121             if ( phy.isRooted() ) {
7122                 return false;
7123             }
7124             //12
7125             if ( !p.hasNext() ) {
7126                 return false;
7127             }
7128             phy = p.next();
7129             if ( phy.getNumberOfExternalNodes() != 3 ) {
7130                 return false;
7131             }
7132             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7133                 return false;
7134             }
7135             if ( !phy.getName().equals( "tree 12" ) ) {
7136                 return false;
7137             }
7138             if ( !phy.isRooted() ) {
7139                 return false;
7140             }
7141             //13
7142             if ( !p.hasNext() ) {
7143                 return false;
7144             }
7145             phy = p.next();
7146             if ( phy.getNumberOfExternalNodes() != 3 ) {
7147                 return false;
7148             }
7149             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7150                 return false;
7151             }
7152             if ( !phy.getName().equals( "tree 13" ) ) {
7153                 return false;
7154             }
7155             if ( !phy.isRooted() ) {
7156                 return false;
7157             }
7158             //14
7159             if ( !p.hasNext() ) {
7160                 return false;
7161             }
7162             phy = p.next();
7163             if ( phy.getNumberOfExternalNodes() != 10 ) {
7164                 System.out.println( phy.getNumberOfExternalNodes() );
7165                 return false;
7166             }
7167             if ( !phy
7168                     .toNewHampshire()
7169                     .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;" ) ) {
7170                 System.out.println( phy.toNewHampshire() );
7171                 return false;
7172             }
7173             if ( !phy.getName().equals( "tree 14" ) ) {
7174                 return false;
7175             }
7176             if ( !phy.isRooted() ) {
7177                 return false;
7178             }
7179             //15
7180             if ( !p.hasNext() ) {
7181                 return false;
7182             }
7183             phy = p.next();
7184             if ( phy.getNumberOfExternalNodes() != 10 ) {
7185                 System.out.println( phy.getNumberOfExternalNodes() );
7186                 return false;
7187             }
7188             if ( !phy
7189                     .toNewHampshire()
7190                     .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;" ) ) {
7191                 System.out.println( phy.toNewHampshire() );
7192                 return false;
7193             }
7194             if ( !phy.getName().equals( "tree 15" ) ) {
7195                 return false;
7196             }
7197             if ( phy.isRooted() ) {
7198                 return false;
7199             }
7200             //16
7201             if ( !p.hasNext() ) {
7202                 return false;
7203             }
7204             phy = p.next();
7205             if ( phy.getNumberOfExternalNodes() != 10 ) {
7206                 System.out.println( phy.getNumberOfExternalNodes() );
7207                 return false;
7208             }
7209             if ( !phy
7210                     .toNewHampshire()
7211                     .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;" ) ) {
7212                 System.out.println( phy.toNewHampshire() );
7213                 return false;
7214             }
7215             if ( !phy.getName().equals( "tree 16" ) ) {
7216                 return false;
7217             }
7218             if ( !phy.isRooted() ) {
7219                 return false;
7220             }
7221             //17
7222             if ( !p.hasNext() ) {
7223                 return false;
7224             }
7225             phy = p.next();
7226             if ( phy.getNumberOfExternalNodes() != 10 ) {
7227                 System.out.println( phy.getNumberOfExternalNodes() );
7228                 return false;
7229             }
7230             if ( !phy
7231                     .toNewHampshire()
7232                     .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;" ) ) {
7233                 System.out.println( phy.toNewHampshire() );
7234                 return false;
7235             }
7236             if ( !phy.getName().equals( "tree 17" ) ) {
7237                 return false;
7238             }
7239             if ( phy.isRooted() ) {
7240                 return false;
7241             }
7242             //
7243             if ( p.hasNext() ) {
7244                 return false;
7245             }
7246             phy = p.next();
7247             if ( phy != null ) {
7248                 return false;
7249             }
7250             p.reset();
7251             //0
7252             if ( !p.hasNext() ) {
7253                 return false;
7254             }
7255             phy = p.next();
7256             if ( phy == null ) {
7257                 return false;
7258             }
7259             if ( phy.getNumberOfExternalNodes() != 10 ) {
7260                 return false;
7261             }
7262             if ( !phy.getName().equals( "tree 0" ) ) {
7263                 return false;
7264             }
7265             //1
7266             if ( !p.hasNext() ) {
7267                 return false;
7268             }
7269             phy = p.next();
7270             if ( phy == null ) {
7271                 return false;
7272             }
7273             if ( phy.getNumberOfExternalNodes() != 10 ) {
7274                 return false;
7275             }
7276             if ( !phy.getName().equals( "tree 1" ) ) {
7277                 return false;
7278             }
7279             //2
7280             if ( !p.hasNext() ) {
7281                 return false;
7282             }
7283             phy = p.next();
7284             if ( phy == null ) {
7285                 return false;
7286             }
7287             if ( phy.getNumberOfExternalNodes() != 3 ) {
7288                 return false;
7289             }
7290             if ( !phy.getName().equals( "" ) ) {
7291                 return false;
7292             }
7293             if ( phy.isRooted() ) {
7294                 return false;
7295             }
7296             //3
7297             if ( !p.hasNext() ) {
7298                 return false;
7299             }
7300             phy = p.next();
7301             if ( phy == null ) {
7302                 return false;
7303             }
7304             if ( phy.getNumberOfExternalNodes() != 4 ) {
7305                 return false;
7306             }
7307             if ( !phy.getName().equals( "" ) ) {
7308                 return false;
7309             }
7310             if ( !phy.isRooted() ) {
7311                 return false;
7312             }
7313             //4
7314             if ( !p.hasNext() ) {
7315                 return false;
7316             }
7317             phy = p.next();
7318             if ( phy == null ) {
7319                 return false;
7320             }
7321             if ( phy.getNumberOfExternalNodes() != 5 ) {
7322                 System.out.println( phy.getNumberOfExternalNodes() );
7323                 return false;
7324             }
7325             if ( !phy.getName().equals( "" ) ) {
7326                 return false;
7327             }
7328             if ( !phy.isRooted() ) {
7329                 return false;
7330             }
7331             //5
7332             if ( !p.hasNext() ) {
7333                 return false;
7334             }
7335             phy = p.next();
7336             if ( phy == null ) {
7337                 return false;
7338             }
7339             if ( phy.getNumberOfExternalNodes() != 3 ) {
7340                 return false;
7341             }
7342             if ( !phy.getName().equals( "" ) ) {
7343                 return false;
7344             }
7345             if ( phy.isRooted() ) {
7346                 return false;
7347             }
7348             //
7349             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7350             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7351             // 0
7352             if ( !p2.hasNext() ) {
7353                 return false;
7354             }
7355             phy = p2.next();
7356             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7357                 return false;
7358             }
7359             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7360                 return false;
7361             }
7362             // 1
7363             if ( !p2.hasNext() ) {
7364                 return false;
7365             }
7366             phy = p2.next();
7367             // 2
7368             if ( !p2.hasNext() ) {
7369                 return false;
7370             }
7371             phy = p2.next();
7372             // 3
7373             if ( !p2.hasNext() ) {
7374                 return false;
7375             }
7376             phy = p2.next();
7377             // 4
7378             if ( !p2.hasNext() ) {
7379                 return false;
7380             }
7381             phy = p2.next();
7382             // 5
7383             if ( !p2.hasNext() ) {
7384                 return false;
7385             }
7386             phy = p2.next();
7387             // 6
7388             if ( !p2.hasNext() ) {
7389                 return false;
7390             }
7391             phy = p2.next();
7392             // 7
7393             if ( !p2.hasNext() ) {
7394                 return false;
7395             }
7396             phy = p2.next();
7397             // 8
7398             if ( !p2.hasNext() ) {
7399                 return false;
7400             }
7401             phy = p2.next();
7402             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7403                 return false;
7404             }
7405             if ( p2.hasNext() ) {
7406                 return false;
7407             }
7408             phy = p2.next();
7409             if ( phy != null ) {
7410                 return false;
7411             }
7412             // 0
7413             p2.reset();
7414             if ( !p2.hasNext() ) {
7415                 return false;
7416             }
7417             phy = p2.next();
7418             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7419                 return false;
7420             }
7421             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7422                 return false;
7423             }
7424         }
7425         catch ( final Exception e ) {
7426             e.printStackTrace( System.out );
7427             return false;
7428         }
7429         return true;
7430     }
7431
7432     private static boolean testNexusTreeParsingTranslating() {
7433         try {
7434             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7435             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7436             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7437             if ( phylogenies.length != 1 ) {
7438                 return false;
7439             }
7440             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7441                 return false;
7442             }
7443             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7444                 return false;
7445             }
7446             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7447                 return false;
7448             }
7449             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7450                 return false;
7451             }
7452             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7453                     .equals( "Aranaeus" ) ) {
7454                 return false;
7455             }
7456             phylogenies = null;
7457             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7458             if ( phylogenies.length != 3 ) {
7459                 return false;
7460             }
7461             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7462                 return false;
7463             }
7464             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7465                 return false;
7466             }
7467             if ( phylogenies[ 0 ].isRooted() ) {
7468                 return false;
7469             }
7470             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7471                 return false;
7472             }
7473             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7474                 return false;
7475             }
7476             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7477                     .equals( "Aranaeus" ) ) {
7478                 return false;
7479             }
7480             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7481                 return false;
7482             }
7483             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7484                 return false;
7485             }
7486             if ( phylogenies[ 1 ].isRooted() ) {
7487                 return false;
7488             }
7489             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7490                 return false;
7491             }
7492             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7493                 return false;
7494             }
7495             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7496                     .equals( "Aranaeus" ) ) {
7497                 return false;
7498             }
7499             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7500                 return false;
7501             }
7502             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7503                 return false;
7504             }
7505             if ( !phylogenies[ 2 ].isRooted() ) {
7506                 return false;
7507             }
7508             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7509                 return false;
7510             }
7511             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7512                 return false;
7513             }
7514             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7515                     .equals( "Aranaeus" ) ) {
7516                 return false;
7517             }
7518             phylogenies = null;
7519             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7520             if ( phylogenies.length != 3 ) {
7521                 return false;
7522             }
7523             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7524                 return false;
7525             }
7526             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7527                 return false;
7528             }
7529             if ( phylogenies[ 0 ].isRooted() ) {
7530                 return false;
7531             }
7532             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7533                 return false;
7534             }
7535             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7536                 return false;
7537             }
7538             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7539                     .equals( "Aranaeus" ) ) {
7540                 return false;
7541             }
7542             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7543                 return false;
7544             }
7545             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7546                 return false;
7547             }
7548             if ( phylogenies[ 1 ].isRooted() ) {
7549                 return false;
7550             }
7551             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7552                 return false;
7553             }
7554             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7555                 return false;
7556             }
7557             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7558                     .equals( "Aranaeus" ) ) {
7559                 return false;
7560             }
7561             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7562                 return false;
7563             }
7564             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7565                 return false;
7566             }
7567             if ( !phylogenies[ 2 ].isRooted() ) {
7568                 return false;
7569             }
7570             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7571                 return false;
7572             }
7573             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7574                 return false;
7575             }
7576             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7577                     .equals( "Aranaeus" ) ) {
7578                 return false;
7579             }
7580             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7581             if ( phylogenies.length != 3 ) {
7582                 return false;
7583             }
7584             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7585                            0.00100049 ) ) {
7586                 return false;
7587             }
7588         }
7589         catch ( final Exception e ) {
7590             e.printStackTrace( System.out );
7591             return false;
7592         }
7593         return true;
7594     }
7595
7596     private static boolean testNHParsing() {
7597         try {
7598             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7599             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7600             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7601                 return false;
7602             }
7603             final NHXParser nhxp = new NHXParser();
7604             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7605             nhxp.setReplaceUnderscores( true );
7606             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7607             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7608                 return false;
7609             }
7610             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7611                 return false;
7612             }
7613             final Phylogeny p1b = factory
7614                     .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 ",
7615                              new NHXParser() )[ 0 ];
7616             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7617                 return false;
7618             }
7619             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7620                 return false;
7621             }
7622             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7623             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7624             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7625             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7626             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7627             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7628             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7629             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7630             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7631             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7632             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7633                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7634                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7635                                                     new NHXParser() );
7636             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7637                 return false;
7638             }
7639             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7640                 return false;
7641             }
7642             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7643                 return false;
7644             }
7645             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7646                 return false;
7647             }
7648             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7649             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7650             final String p16_S = "((A,B),C)";
7651             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7652             if ( p16.length != 1 ) {
7653                 return false;
7654             }
7655             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7656                 return false;
7657             }
7658             final String p17_S = "(C,(A,B))";
7659             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7660             if ( p17.length != 1 ) {
7661                 return false;
7662             }
7663             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7664                 return false;
7665             }
7666             final String p18_S = "((A,B),(C,D))";
7667             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7668             if ( p18.length != 1 ) {
7669                 return false;
7670             }
7671             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7672                 return false;
7673             }
7674             final String p19_S = "(((A,B),C),D)";
7675             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7676             if ( p19.length != 1 ) {
7677                 return false;
7678             }
7679             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7680                 return false;
7681             }
7682             final String p20_S = "(A,(B,(C,D)))";
7683             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7684             if ( p20.length != 1 ) {
7685                 return false;
7686             }
7687             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7688                 return false;
7689             }
7690             final String p21_S = "(A,(B,(C,(D,E))))";
7691             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7692             if ( p21.length != 1 ) {
7693                 return false;
7694             }
7695             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7696                 return false;
7697             }
7698             final String p22_S = "((((A,B),C),D),E)";
7699             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7700             if ( p22.length != 1 ) {
7701                 return false;
7702             }
7703             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7704                 return false;
7705             }
7706             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7707             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7708             if ( p23.length != 1 ) {
7709                 System.out.println( "xl=" + p23.length );
7710                 System.exit( -1 );
7711                 return false;
7712             }
7713             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7714                 return false;
7715             }
7716             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7717             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7718             if ( p24.length != 1 ) {
7719                 return false;
7720             }
7721             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7722                 return false;
7723             }
7724             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7725             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7726             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7727             if ( p241.length != 2 ) {
7728                 return false;
7729             }
7730             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7731                 return false;
7732             }
7733             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7734                 return false;
7735             }
7736             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7737                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7738                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7739                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7740                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7741                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7742                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7743                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7744             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7745             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7746                 return false;
7747             }
7748             final String p26_S = "(A,B)ab";
7749             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7750             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7751                 return false;
7752             }
7753             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7754             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7755             if ( p27s.length != 1 ) {
7756                 System.out.println( "xxl=" + p27s.length );
7757                 System.exit( -1 );
7758                 return false;
7759             }
7760             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7761                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7762                 System.exit( -1 );
7763                 return false;
7764             }
7765             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7766                                                     new NHXParser() );
7767             if ( p27.length != 1 ) {
7768                 System.out.println( "yl=" + p27.length );
7769                 System.exit( -1 );
7770                 return false;
7771             }
7772             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7773                 System.out.println( p27[ 0 ].toNewHampshireX() );
7774                 System.exit( -1 );
7775                 return false;
7776             }
7777             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7778             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7779             final String p28_S3 = "(A,B)ab";
7780             final String p28_S4 = "((((A,B),C),D),;E;)";
7781             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7782                                                     new NHXParser() );
7783             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7784                 return false;
7785             }
7786             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7787                 return false;
7788             }
7789             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7790                 return false;
7791             }
7792             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7793                 return false;
7794             }
7795             if ( p28.length != 4 ) {
7796                 return false;
7797             }
7798             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";
7799             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7800             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7801                 return false;
7802             }
7803             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";
7804             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7805             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7806                 return false;
7807             }
7808             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7809             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7810             if ( ( p32.length != 0 ) ) {
7811                 return false;
7812             }
7813             final String p33_S = "A";
7814             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7815             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7816                 return false;
7817             }
7818             final String p34_S = "B;";
7819             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7820             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7821                 return false;
7822             }
7823             final String p35_S = "B:0.2";
7824             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7825             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7826                 return false;
7827             }
7828             final String p36_S = "(A)";
7829             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7830             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7831                 return false;
7832             }
7833             final String p37_S = "((A))";
7834             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7835             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7836                 return false;
7837             }
7838             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7839             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7840             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7841                 return false;
7842             }
7843             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7844             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7845             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7846                 return false;
7847             }
7848             final String p40_S = "(A,B,C)";
7849             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7850             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7851                 return false;
7852             }
7853             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7854             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7855             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7856                 return false;
7857             }
7858             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7859             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7860             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7861                 return false;
7862             }
7863             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)";
7864             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7865             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7866                 return false;
7867             }
7868             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)))";
7869             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7870             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7871                 return false;
7872             }
7873             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7874             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7875             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7876                 return false;
7877             }
7878             final String p46_S = "";
7879             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7880             if ( p46.length != 0 ) {
7881                 return false;
7882             }
7883             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7884             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7885                 return false;
7886             }
7887             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7888             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7889                 return false;
7890             }
7891             final Phylogeny p49 = factory
7892                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7893                              new NHXParser() )[ 0 ];
7894             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7895                 return false;
7896             }
7897             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7898             if ( p50.getNode( "A" ) == null ) {
7899                 return false;
7900             }
7901             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7902                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7903                 return false;
7904             }
7905             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7906                 return false;
7907             }
7908             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7909                     .equals( "((A,B)88:2.0,C);" ) ) {
7910                 return false;
7911             }
7912             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7913             if ( p51.getNode( "A(A" ) == null ) {
7914                 return false;
7915             }
7916             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7917             if ( p52.getNode( "A(A" ) == null ) {
7918                 return false;
7919             }
7920             final Phylogeny p53 = factory
7921                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7922                              new NHXParser() )[ 0 ];
7923             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7924                 return false;
7925             }
7926             // 
7927             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7928             if ( p54.getNode( "A" ) == null ) {
7929                 return false;
7930             }
7931             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7932                     .equals( "((A,B)[88],C);" ) ) {
7933                 return false;
7934             }
7935         }
7936         catch ( final Exception e ) {
7937             e.printStackTrace( System.out );
7938             return false;
7939         }
7940         return true;
7941     }
7942
7943     private static boolean testNHParsingIter() {
7944         try {
7945             final String p0_str = "(A,B);";
7946             final NHXParser p = new NHXParser();
7947             p.setSource( p0_str );
7948             if ( !p.hasNext() ) {
7949                 return false;
7950             }
7951             final Phylogeny p0 = p.next();
7952             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7953                 System.out.println( p0.toNewHampshire() );
7954                 return false;
7955             }
7956             if ( p.hasNext() ) {
7957                 return false;
7958             }
7959             if ( p.next() != null ) {
7960                 return false;
7961             }
7962             //
7963             final String p00_str = "(A,B)root;";
7964             p.setSource( p00_str );
7965             final Phylogeny p00 = p.next();
7966             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7967                 System.out.println( p00.toNewHampshire() );
7968                 return false;
7969             }
7970             //
7971             final String p000_str = "A;";
7972             p.setSource( p000_str );
7973             final Phylogeny p000 = p.next();
7974             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7975                 System.out.println( p000.toNewHampshire() );
7976                 return false;
7977             }
7978             //
7979             final String p0000_str = "A";
7980             p.setSource( p0000_str );
7981             final Phylogeny p0000 = p.next();
7982             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7983                 System.out.println( p0000.toNewHampshire() );
7984                 return false;
7985             }
7986             //
7987             p.setSource( "(A)" );
7988             final Phylogeny p00000 = p.next();
7989             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7990                 System.out.println( p00000.toNewHampshire() );
7991                 return false;
7992             }
7993             //
7994             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7995             p.setSource( p1_str );
7996             if ( !p.hasNext() ) {
7997                 return false;
7998             }
7999             final Phylogeny p1_0 = p.next();
8000             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8001                 System.out.println( p1_0.toNewHampshire() );
8002                 return false;
8003             }
8004             if ( !p.hasNext() ) {
8005                 return false;
8006             }
8007             final Phylogeny p1_1 = p.next();
8008             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8009                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8010                 return false;
8011             }
8012             if ( !p.hasNext() ) {
8013                 return false;
8014             }
8015             final Phylogeny p1_2 = p.next();
8016             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8017                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8018                 return false;
8019             }
8020             if ( !p.hasNext() ) {
8021                 return false;
8022             }
8023             final Phylogeny p1_3 = p.next();
8024             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8025                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8026                 return false;
8027             }
8028             if ( p.hasNext() ) {
8029                 return false;
8030             }
8031             if ( p.next() != null ) {
8032                 return false;
8033             }
8034             //
8035             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8036             p.setSource( p2_str );
8037             if ( !p.hasNext() ) {
8038                 return false;
8039             }
8040             Phylogeny p2_0 = p.next();
8041             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8042                 System.out.println( p2_0.toNewHampshire() );
8043                 return false;
8044             }
8045             if ( !p.hasNext() ) {
8046                 return false;
8047             }
8048             Phylogeny p2_1 = p.next();
8049             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8050                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8051                 return false;
8052             }
8053             if ( !p.hasNext() ) {
8054                 return false;
8055             }
8056             Phylogeny p2_2 = p.next();
8057             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8058                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8059                 return false;
8060             }
8061             if ( !p.hasNext() ) {
8062                 return false;
8063             }
8064             Phylogeny p2_3 = p.next();
8065             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8066                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8067                 return false;
8068             }
8069             if ( !p.hasNext() ) {
8070                 return false;
8071             }
8072             Phylogeny p2_4 = p.next();
8073             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8074                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8075                 return false;
8076             }
8077             if ( p.hasNext() ) {
8078                 return false;
8079             }
8080             if ( p.next() != null ) {
8081                 return false;
8082             }
8083             ////
8084             p.reset();
8085             if ( !p.hasNext() ) {
8086                 return false;
8087             }
8088             p2_0 = p.next();
8089             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8090                 System.out.println( p2_0.toNewHampshire() );
8091                 return false;
8092             }
8093             if ( !p.hasNext() ) {
8094                 return false;
8095             }
8096             p2_1 = p.next();
8097             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8098                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8099                 return false;
8100             }
8101             if ( !p.hasNext() ) {
8102                 return false;
8103             }
8104             p2_2 = p.next();
8105             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8106                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8107                 return false;
8108             }
8109             if ( !p.hasNext() ) {
8110                 return false;
8111             }
8112             p2_3 = p.next();
8113             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8114                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8115                 return false;
8116             }
8117             if ( !p.hasNext() ) {
8118                 return false;
8119             }
8120             p2_4 = p.next();
8121             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8122                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8123                 return false;
8124             }
8125             if ( p.hasNext() ) {
8126                 return false;
8127             }
8128             if ( p.next() != null ) {
8129                 return false;
8130             }
8131             //
8132             final String p3_str = "((A,B),C)abc";
8133             p.setSource( p3_str );
8134             if ( !p.hasNext() ) {
8135                 return false;
8136             }
8137             final Phylogeny p3_0 = p.next();
8138             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8139                 return false;
8140             }
8141             if ( p.hasNext() ) {
8142                 return false;
8143             }
8144             if ( p.next() != null ) {
8145                 return false;
8146             }
8147             //
8148             final String p4_str = "((A,B)ab,C)abc";
8149             p.setSource( p4_str );
8150             if ( !p.hasNext() ) {
8151                 return false;
8152             }
8153             final Phylogeny p4_0 = p.next();
8154             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8155                 return false;
8156             }
8157             if ( p.hasNext() ) {
8158                 return false;
8159             }
8160             if ( p.next() != null ) {
8161                 return false;
8162             }
8163             //
8164             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8165             p.setSource( p5_str );
8166             if ( !p.hasNext() ) {
8167                 return false;
8168             }
8169             final Phylogeny p5_0 = p.next();
8170             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8171                 return false;
8172             }
8173             if ( p.hasNext() ) {
8174                 return false;
8175             }
8176             if ( p.next() != null ) {
8177                 return false;
8178             }
8179             //
8180             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8181             p.setSource( p6_str );
8182             if ( !p.hasNext() ) {
8183                 return false;
8184             }
8185             Phylogeny p6_0 = p.next();
8186             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8187                 return false;
8188             }
8189             if ( p.hasNext() ) {
8190                 return false;
8191             }
8192             if ( p.next() != null ) {
8193                 return false;
8194             }
8195             p.reset();
8196             if ( !p.hasNext() ) {
8197                 return false;
8198             }
8199             p6_0 = p.next();
8200             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8201                 return false;
8202             }
8203             if ( p.hasNext() ) {
8204                 return false;
8205             }
8206             if ( p.next() != null ) {
8207                 return false;
8208             }
8209             //
8210             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8211             p.setSource( p7_str );
8212             if ( !p.hasNext() ) {
8213                 return false;
8214             }
8215             Phylogeny p7_0 = p.next();
8216             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8217                 return false;
8218             }
8219             if ( p.hasNext() ) {
8220                 return false;
8221             }
8222             if ( p.next() != null ) {
8223                 return false;
8224             }
8225             p.reset();
8226             if ( !p.hasNext() ) {
8227                 return false;
8228             }
8229             p7_0 = p.next();
8230             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8231                 return false;
8232             }
8233             if ( p.hasNext() ) {
8234                 return false;
8235             }
8236             if ( p.next() != null ) {
8237                 return false;
8238             }
8239             //
8240             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8241             p.setSource( p8_str );
8242             if ( !p.hasNext() ) {
8243                 return false;
8244             }
8245             Phylogeny p8_0 = p.next();
8246             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8247                 return false;
8248             }
8249             if ( !p.hasNext() ) {
8250                 return false;
8251             }
8252             if ( !p.hasNext() ) {
8253                 return false;
8254             }
8255             Phylogeny p8_1 = p.next();
8256             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8257                 return false;
8258             }
8259             if ( p.hasNext() ) {
8260                 return false;
8261             }
8262             if ( p.next() != null ) {
8263                 return false;
8264             }
8265             p.reset();
8266             if ( !p.hasNext() ) {
8267                 return false;
8268             }
8269             p8_0 = p.next();
8270             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8271                 return false;
8272             }
8273             if ( !p.hasNext() ) {
8274                 return false;
8275             }
8276             p8_1 = p.next();
8277             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8278                 return false;
8279             }
8280             if ( p.hasNext() ) {
8281                 return false;
8282             }
8283             if ( p.next() != null ) {
8284                 return false;
8285             }
8286             p.reset();
8287             //
8288             p.setSource( "" );
8289             if ( p.hasNext() ) {
8290                 return false;
8291             }
8292             //
8293             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8294             if ( !p.hasNext() ) {
8295                 return false;
8296             }
8297             Phylogeny p_27 = p.next();
8298             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8299                 System.out.println( p_27.toNewHampshireX() );
8300                 System.exit( -1 );
8301                 return false;
8302             }
8303             if ( p.hasNext() ) {
8304                 return false;
8305             }
8306             if ( p.next() != null ) {
8307                 return false;
8308             }
8309             p.reset();
8310             if ( !p.hasNext() ) {
8311                 return false;
8312             }
8313             p_27 = p.next();
8314             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8315                 System.out.println( p_27.toNewHampshireX() );
8316                 System.exit( -1 );
8317                 return false;
8318             }
8319             if ( p.hasNext() ) {
8320                 return false;
8321             }
8322             if ( p.next() != null ) {
8323                 return false;
8324             }
8325             //
8326             final String p30_str = "(A,B);(C,D)";
8327             final NHXParser p30 = new NHXParser();
8328             p30.setSource( p30_str );
8329             if ( !p30.hasNext() ) {
8330                 return false;
8331             }
8332             Phylogeny phy30 = p30.next();
8333             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8334                 System.out.println( phy30.toNewHampshire() );
8335                 return false;
8336             }
8337             if ( !p30.hasNext() ) {
8338                 return false;
8339             }
8340             Phylogeny phy301 = p30.next();
8341             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8342                 System.out.println( phy301.toNewHampshire() );
8343                 return false;
8344             }
8345             if ( p30.hasNext() ) {
8346                 return false;
8347             }
8348             if ( p30.hasNext() ) {
8349                 return false;
8350             }
8351             if ( p30.next() != null ) {
8352                 return false;
8353             }
8354             if ( p30.next() != null ) {
8355                 return false;
8356             }
8357             p30.reset();
8358             if ( !p30.hasNext() ) {
8359                 return false;
8360             }
8361             phy30 = p30.next();
8362             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8363                 System.out.println( phy30.toNewHampshire() );
8364                 return false;
8365             }
8366             if ( !p30.hasNext() ) {
8367                 return false;
8368             }
8369             phy301 = p30.next();
8370             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8371                 System.out.println( phy301.toNewHampshire() );
8372                 return false;
8373             }
8374             if ( p30.hasNext() ) {
8375                 return false;
8376             }
8377             if ( p30.hasNext() ) {
8378                 return false;
8379             }
8380             if ( p30.next() != null ) {
8381                 return false;
8382             }
8383             if ( p30.next() != null ) {
8384                 return false;
8385             }
8386         }
8387         catch ( final Exception e ) {
8388             e.printStackTrace( System.out );
8389             return false;
8390         }
8391         return true;
8392     }
8393
8394     private static boolean testNHXconversion() {
8395         try {
8396             final PhylogenyNode n1 = new PhylogenyNode();
8397             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8398             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8399             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8400             final PhylogenyNode n5 = PhylogenyNode
8401                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8402             final PhylogenyNode n6 = PhylogenyNode
8403                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8404             if ( !n1.toNewHampshireX().equals( "" ) ) {
8405                 return false;
8406             }
8407             if ( !n2.toNewHampshireX().equals( "" ) ) {
8408                 return false;
8409             }
8410             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8411                 return false;
8412             }
8413             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8414                 return false;
8415             }
8416             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8417                 return false;
8418             }
8419             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8420                 System.out.println( n6.toNewHampshireX() );
8421                 return false;
8422             }
8423         }
8424         catch ( final Exception e ) {
8425             e.printStackTrace( System.out );
8426             return false;
8427         }
8428         return true;
8429     }
8430
8431     private static boolean testNHXNodeParsing() {
8432         try {
8433             final PhylogenyNode n1 = new PhylogenyNode();
8434             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8435             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8436             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8437             final PhylogenyNode n5 = PhylogenyNode
8438                     .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]" );
8439             if ( !n3.getName().equals( "n3" ) ) {
8440                 return false;
8441             }
8442             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8443                 return false;
8444             }
8445             if ( n3.isDuplication() ) {
8446                 return false;
8447             }
8448             if ( n3.isHasAssignedEvent() ) {
8449                 return false;
8450             }
8451             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8452                 return false;
8453             }
8454             if ( !n4.getName().equals( "n4" ) ) {
8455                 return false;
8456             }
8457             if ( n4.getDistanceToParent() != 0.01 ) {
8458                 return false;
8459             }
8460             if ( !n5.getName().equals( "n5" ) ) {
8461                 return false;
8462             }
8463             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8464                 return false;
8465             }
8466             if ( n5.getDistanceToParent() != 0.1 ) {
8467                 return false;
8468             }
8469             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8470                 return false;
8471             }
8472             if ( !n5.isDuplication() ) {
8473                 return false;
8474             }
8475             if ( !n5.isHasAssignedEvent() ) {
8476                 return false;
8477             }
8478             final PhylogenyNode n8 = PhylogenyNode
8479                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8480                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8481             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8482                 return false;
8483             }
8484             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8485                 return false;
8486             }
8487             final PhylogenyNode n9 = PhylogenyNode
8488                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8489                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8490             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8491                 return false;
8492             }
8493             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8494                 return false;
8495             }
8496             final PhylogenyNode n10 = PhylogenyNode
8497                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8498             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8499                 return false;
8500             }
8501             final PhylogenyNode n20 = PhylogenyNode
8502                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8503             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8504                 return false;
8505             }
8506             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8507                 return false;
8508             }
8509             final PhylogenyNode n20x = PhylogenyNode
8510                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8511             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8512                 return false;
8513             }
8514             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8515                 return false;
8516             }
8517             final PhylogenyNode n20xx = PhylogenyNode
8518                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8519             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8520                 return false;
8521             }
8522             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8523                 return false;
8524             }
8525             final PhylogenyNode n20xxx = PhylogenyNode
8526                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8527             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8528                 return false;
8529             }
8530             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8531                 return false;
8532             }
8533             final PhylogenyNode n20xxxx = PhylogenyNode
8534                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8535             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8536                 return false;
8537             }
8538             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8539                 return false;
8540             }
8541             final PhylogenyNode n21 = PhylogenyNode
8542                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8543             if ( !n21.getName().equals( "N21_PIG" ) ) {
8544                 return false;
8545             }
8546             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8547                 return false;
8548             }
8549             final PhylogenyNode n21x = PhylogenyNode
8550                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8551             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8552                 return false;
8553             }
8554             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8555                 return false;
8556             }
8557             final PhylogenyNode n22 = PhylogenyNode
8558                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8559             if ( !n22.getName().equals( "n22/PIG" ) ) {
8560                 return false;
8561             }
8562             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8563                 return false;
8564             }
8565             final PhylogenyNode n23 = PhylogenyNode
8566                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8567             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8568                 return false;
8569             }
8570             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8571                 return false;
8572             }
8573             final PhylogenyNode a = PhylogenyNode
8574                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8575             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8576                 return false;
8577             }
8578             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8579                 return false;
8580             }
8581             final PhylogenyNode c1 = PhylogenyNode
8582                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8583                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8584             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8585                 return false;
8586             }
8587             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8588                 return false;
8589             }
8590             final PhylogenyNode c2 = PhylogenyNode
8591                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8592                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8593             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8594                 return false;
8595             }
8596             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8597                 return false;
8598             }
8599             final PhylogenyNode e3 = PhylogenyNode
8600                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8601             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8602                 return false;
8603             }
8604             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8605                 return false;
8606             }
8607             final PhylogenyNode n11 = PhylogenyNode
8608                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8609                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8610             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8611                 return false;
8612             }
8613             if ( n11.getDistanceToParent() != 0.4 ) {
8614                 return false;
8615             }
8616             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8617                 return false;
8618             }
8619             final PhylogenyNode n12 = PhylogenyNode
8620                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8621                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8622             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8623                 return false;
8624             }
8625             if ( n12.getDistanceToParent() != 0.4 ) {
8626                 return false;
8627             }
8628             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8629                 return false;
8630             }
8631             final PhylogenyNode o = PhylogenyNode
8632                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8633             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8634                 return false;
8635             }
8636             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8637                 return false;
8638             }
8639             if ( n1.getName().compareTo( "" ) != 0 ) {
8640                 return false;
8641             }
8642             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8643                 return false;
8644             }
8645             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8646                 return false;
8647             }
8648             if ( n2.getName().compareTo( "" ) != 0 ) {
8649                 return false;
8650             }
8651             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8652                 return false;
8653             }
8654             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8655                 return false;
8656             }
8657             final PhylogenyNode n00 = PhylogenyNode
8658                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8659             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8660                 return false;
8661             }
8662             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8663                 return false;
8664             }
8665             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8666             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8667                 return false;
8668             }
8669             final PhylogenyNode n13 = PhylogenyNode
8670                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8671             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
8672                 return false;
8673             }
8674             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8675                 return false;
8676             }
8677             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8678                 return false;
8679             }
8680             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8681                 return false;
8682             }
8683             final PhylogenyNode n14 = PhylogenyNode
8684                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8685             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8686                 return false;
8687             }
8688             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8689                 return false;
8690             }
8691             final PhylogenyNode n15 = PhylogenyNode
8692                     .createInstanceFromNhxString( "something_wicked[123]",
8693                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8694             if ( !n15.getName().equals( "something_wicked" ) ) {
8695                 return false;
8696             }
8697             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8698                 return false;
8699             }
8700             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8701                 return false;
8702             }
8703             final PhylogenyNode n16 = PhylogenyNode
8704                     .createInstanceFromNhxString( "something_wicked2[9]",
8705                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8706             if ( !n16.getName().equals( "something_wicked2" ) ) {
8707                 return false;
8708             }
8709             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8710                 return false;
8711             }
8712             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8713                 return false;
8714             }
8715             final PhylogenyNode n17 = PhylogenyNode
8716                     .createInstanceFromNhxString( "something_wicked3[a]",
8717                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8718             if ( !n17.getName().equals( "something_wicked3" ) ) {
8719                 return false;
8720             }
8721             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8722                 return false;
8723             }
8724             final PhylogenyNode n18 = PhylogenyNode
8725                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8726             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8727                 return false;
8728             }
8729             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8730                 return false;
8731             }
8732             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8733                 return false;
8734             }
8735             final PhylogenyNode n19 = PhylogenyNode
8736                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8737             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8738                 return false;
8739             }
8740             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8741                 return false;
8742             }
8743             final PhylogenyNode n30 = PhylogenyNode
8744                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
8745                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8746             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8747                 return false;
8748             }
8749             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8750                 return false;
8751             }
8752             final PhylogenyNode n31 = PhylogenyNode
8753                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
8754                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8755             if ( n31.getNodeData().isHasTaxonomy() ) {
8756                 return false;
8757             }
8758             final PhylogenyNode n32 = PhylogenyNode
8759                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8760             if ( n32.getNodeData().isHasTaxonomy() ) {
8761                 return false;
8762             }
8763             final PhylogenyNode n40 = PhylogenyNode
8764                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8765             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8766                 return false;
8767             }
8768             final PhylogenyNode n41 = PhylogenyNode
8769                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8770             if ( n41.getNodeData().isHasTaxonomy() ) {
8771                 return false;
8772             }
8773             final PhylogenyNode n42 = PhylogenyNode
8774                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8775             if ( n42.getNodeData().isHasTaxonomy() ) {
8776                 return false;
8777             }
8778             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8779                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8780             if ( n43.getNodeData().isHasTaxonomy() ) {
8781                 return false;
8782             }
8783             final PhylogenyNode n44 = PhylogenyNode
8784                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8785             if ( n44.getNodeData().isHasTaxonomy() ) {
8786                 return false;
8787             }
8788         }
8789         catch ( final Exception e ) {
8790             e.printStackTrace( System.out );
8791             return false;
8792         }
8793         return true;
8794     }
8795
8796     private static boolean testNHXParsing() {
8797         try {
8798             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8799             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8800             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8801                 return false;
8802             }
8803             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]";
8804             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8805             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8806                 return false;
8807             }
8808             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]";
8809             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8810             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8811                 return false;
8812             }
8813             final Phylogeny[] p3 = factory
8814                     .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]",
8815                              new NHXParser() );
8816             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8817                 return false;
8818             }
8819             final Phylogeny[] p4 = factory
8820                     .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(]",
8821                              new NHXParser() );
8822             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8823                 return false;
8824             }
8825             final Phylogeny[] p5 = factory
8826                     .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(((]",
8827                              new NHXParser() );
8828             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8829                 return false;
8830             }
8831             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)";
8832             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)";
8833             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8834             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8835                 return false;
8836             }
8837             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)))";
8838             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)))";
8839             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8840             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8841                 return false;
8842             }
8843             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])   ))[,,, ])))))))";
8844             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8845             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8846             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8847                 return false;
8848             }
8849             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8850             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8851                 return false;
8852             }
8853             final Phylogeny p10 = factory
8854                     .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]",
8855                              new NHXParser() )[ 0 ];
8856             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8857                 return false;
8858             }
8859         }
8860         catch ( final Exception e ) {
8861             e.printStackTrace( System.out );
8862             return false;
8863         }
8864         return true;
8865     }
8866
8867     private static boolean testNHXParsingMB() {
8868         try {
8869             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8870             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8871                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8872                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8873                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8874                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8875                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8876                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8877                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8878                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8879             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8880                 return false;
8881             }
8882             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8883                 return false;
8884             }
8885             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8886                            0.1100000000000000e+00 ) ) {
8887                 return false;
8888             }
8889             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8890                 return false;
8891             }
8892             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8893                 return false;
8894             }
8895             final Phylogeny p2 = factory
8896                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8897                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8898                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8899                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8900                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8901                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8902                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8903                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8904                                      + "7.369400000000000e-02}])",
8905                              new NHXParser() )[ 0 ];
8906             if ( p2.getNode( "1" ) == null ) {
8907                 return false;
8908             }
8909             if ( p2.getNode( "2" ) == null ) {
8910                 return false;
8911             }
8912         }
8913         catch ( final Exception e ) {
8914             e.printStackTrace( System.out );
8915             System.exit( -1 );
8916             return false;
8917         }
8918         return true;
8919     }
8920
8921     private static boolean testNHXParsingQuotes() {
8922         try {
8923             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8924             final NHXParser p = new NHXParser();
8925             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8926             if ( phylogenies_0.length != 5 ) {
8927                 return false;
8928             }
8929             final Phylogeny phy = phylogenies_0[ 4 ];
8930             if ( phy.getNumberOfExternalNodes() != 7 ) {
8931                 return false;
8932             }
8933             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8934                 return false;
8935             }
8936             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8937                 return false;
8938             }
8939             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8940                     .getScientificName().equals( "hsapiens" ) ) {
8941                 return false;
8942             }
8943             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8944                 return false;
8945             }
8946             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8947                 return false;
8948             }
8949             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8950                 return false;
8951             }
8952             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8953                 return false;
8954             }
8955             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8956                 return false;
8957             }
8958             final NHXParser p1p = new NHXParser();
8959             p1p.setIgnoreQuotes( true );
8960             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8961             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8962                 return false;
8963             }
8964             final NHXParser p2p = new NHXParser();
8965             p1p.setIgnoreQuotes( false );
8966             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8967             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8968                 return false;
8969             }
8970             final NHXParser p3p = new NHXParser();
8971             p3p.setIgnoreQuotes( false );
8972             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8973             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8974                 return false;
8975             }
8976             final NHXParser p4p = new NHXParser();
8977             p4p.setIgnoreQuotes( false );
8978             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8979             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8980                 return false;
8981             }
8982             final Phylogeny p10 = factory
8983                     .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]",
8984                              new NHXParser() )[ 0 ];
8985             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]";
8986             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8987                 return false;
8988             }
8989             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8990             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8991                 return false;
8992             }
8993             //
8994             final Phylogeny p12 = factory
8995                     .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]",
8996                              new NHXParser() )[ 0 ];
8997             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]";
8998             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8999                 return false;
9000             }
9001             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9002             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9003                 return false;
9004             }
9005             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;";
9006             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9007                 return false;
9008             }
9009             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9010             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9011                 return false;
9012             }
9013         }
9014         catch ( final Exception e ) {
9015             e.printStackTrace( System.out );
9016             return false;
9017         }
9018         return true;
9019     }
9020
9021     private static boolean testNodeRemoval() {
9022         try {
9023             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9024             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9025             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9026             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9027                 return false;
9028             }
9029             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9030             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9031             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9032                 return false;
9033             }
9034             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9035             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9036             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9037                 return false;
9038             }
9039         }
9040         catch ( final Exception e ) {
9041             e.printStackTrace( System.out );
9042             return false;
9043         }
9044         return true;
9045     }
9046
9047     private static boolean testPhylogenyBranch() {
9048         try {
9049             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9050             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9051             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9052             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9053             if ( !a1b1.equals( a1b1 ) ) {
9054                 return false;
9055             }
9056             if ( !a1b1.equals( b1a1 ) ) {
9057                 return false;
9058             }
9059             if ( !b1a1.equals( a1b1 ) ) {
9060                 return false;
9061             }
9062             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9063             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9064             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9065             if ( a1_b1.equals( b1_a1 ) ) {
9066                 return false;
9067             }
9068             if ( a1_b1.equals( a1_b1_ ) ) {
9069                 return false;
9070             }
9071             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9072             if ( !a1_b1.equals( b1_a1_ ) ) {
9073                 return false;
9074             }
9075             if ( a1_b1_.equals( b1_a1_ ) ) {
9076                 return false;
9077             }
9078             if ( !a1_b1_.equals( b1_a1 ) ) {
9079                 return false;
9080             }
9081         }
9082         catch ( final Exception e ) {
9083             e.printStackTrace( System.out );
9084             return false;
9085         }
9086         return true;
9087     }
9088
9089     private static boolean testPhyloXMLparsingOfDistributionElement() {
9090         try {
9091             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9092             PhyloXmlParser xml_parser = null;
9093             try {
9094                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9095             }
9096             catch ( final Exception e ) {
9097                 // Do nothing -- means were not running from jar.
9098             }
9099             if ( xml_parser == null ) {
9100                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9101                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9102                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9103                 }
9104                 else {
9105                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9106                 }
9107             }
9108             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9109                                                               xml_parser );
9110             if ( xml_parser.getErrorCount() > 0 ) {
9111                 System.out.println( xml_parser.getErrorMessages().toString() );
9112                 return false;
9113             }
9114             if ( phylogenies_0.length != 1 ) {
9115                 return false;
9116             }
9117             final Phylogeny t1 = phylogenies_0[ 0 ];
9118             PhylogenyNode n = null;
9119             Distribution d = null;
9120             n = t1.getNode( "root node" );
9121             if ( !n.getNodeData().isHasDistribution() ) {
9122                 return false;
9123             }
9124             if ( n.getNodeData().getDistributions().size() != 1 ) {
9125                 return false;
9126             }
9127             d = n.getNodeData().getDistribution();
9128             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9129                 return false;
9130             }
9131             if ( d.getPoints().size() != 1 ) {
9132                 return false;
9133             }
9134             if ( d.getPolygons() != null ) {
9135                 return false;
9136             }
9137             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9138                 return false;
9139             }
9140             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9141                 return false;
9142             }
9143             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9144                 return false;
9145             }
9146             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9147                 return false;
9148             }
9149             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9150                 return false;
9151             }
9152             n = t1.getNode( "node a" );
9153             if ( !n.getNodeData().isHasDistribution() ) {
9154                 return false;
9155             }
9156             if ( n.getNodeData().getDistributions().size() != 2 ) {
9157                 return false;
9158             }
9159             d = n.getNodeData().getDistribution( 1 );
9160             if ( !d.getDesc().equals( "San Diego" ) ) {
9161                 return false;
9162             }
9163             if ( d.getPoints().size() != 1 ) {
9164                 return false;
9165             }
9166             if ( d.getPolygons() != null ) {
9167                 return false;
9168             }
9169             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9170                 return false;
9171             }
9172             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9173                 return false;
9174             }
9175             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9176                 return false;
9177             }
9178             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9179                 return false;
9180             }
9181             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9182                 return false;
9183             }
9184             n = t1.getNode( "node bb" );
9185             if ( !n.getNodeData().isHasDistribution() ) {
9186                 return false;
9187             }
9188             if ( n.getNodeData().getDistributions().size() != 1 ) {
9189                 return false;
9190             }
9191             d = n.getNodeData().getDistribution( 0 );
9192             if ( d.getPoints().size() != 3 ) {
9193                 return false;
9194             }
9195             if ( d.getPolygons().size() != 2 ) {
9196                 return false;
9197             }
9198             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9199                 return false;
9200             }
9201             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9202                 return false;
9203             }
9204             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9205                 return false;
9206             }
9207             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9208                 return false;
9209             }
9210             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9211                 return false;
9212             }
9213             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9214                 return false;
9215             }
9216             Polygon p = d.getPolygons().get( 0 );
9217             if ( p.getPoints().size() != 3 ) {
9218                 return false;
9219             }
9220             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9221                 return false;
9222             }
9223             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9224                 return false;
9225             }
9226             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9227                 return false;
9228             }
9229             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9230                 return false;
9231             }
9232             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9233                 return false;
9234             }
9235             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9236                 return false;
9237             }
9238             p = d.getPolygons().get( 1 );
9239             if ( p.getPoints().size() != 3 ) {
9240                 return false;
9241             }
9242             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9243                 return false;
9244             }
9245             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9246                 return false;
9247             }
9248             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9249                 return false;
9250             }
9251             // Roundtrip:
9252             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9253             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9254             if ( rt.length != 1 ) {
9255                 return false;
9256             }
9257             final Phylogeny t1_rt = rt[ 0 ];
9258             n = t1_rt.getNode( "root node" );
9259             if ( !n.getNodeData().isHasDistribution() ) {
9260                 return false;
9261             }
9262             if ( n.getNodeData().getDistributions().size() != 1 ) {
9263                 return false;
9264             }
9265             d = n.getNodeData().getDistribution();
9266             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9267                 return false;
9268             }
9269             if ( d.getPoints().size() != 1 ) {
9270                 return false;
9271             }
9272             if ( d.getPolygons() != null ) {
9273                 return false;
9274             }
9275             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9276                 return false;
9277             }
9278             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9279                 return false;
9280             }
9281             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9282                 return false;
9283             }
9284             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9285                 return false;
9286             }
9287             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9288                 return false;
9289             }
9290             n = t1_rt.getNode( "node a" );
9291             if ( !n.getNodeData().isHasDistribution() ) {
9292                 return false;
9293             }
9294             if ( n.getNodeData().getDistributions().size() != 2 ) {
9295                 return false;
9296             }
9297             d = n.getNodeData().getDistribution( 1 );
9298             if ( !d.getDesc().equals( "San Diego" ) ) {
9299                 return false;
9300             }
9301             if ( d.getPoints().size() != 1 ) {
9302                 return false;
9303             }
9304             if ( d.getPolygons() != null ) {
9305                 return false;
9306             }
9307             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9308                 return false;
9309             }
9310             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9311                 return false;
9312             }
9313             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9314                 return false;
9315             }
9316             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9317                 return false;
9318             }
9319             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9320                 return false;
9321             }
9322             n = t1_rt.getNode( "node bb" );
9323             if ( !n.getNodeData().isHasDistribution() ) {
9324                 return false;
9325             }
9326             if ( n.getNodeData().getDistributions().size() != 1 ) {
9327                 return false;
9328             }
9329             d = n.getNodeData().getDistribution( 0 );
9330             if ( d.getPoints().size() != 3 ) {
9331                 return false;
9332             }
9333             if ( d.getPolygons().size() != 2 ) {
9334                 return false;
9335             }
9336             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9337                 return false;
9338             }
9339             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9340                 return false;
9341             }
9342             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9343                 return false;
9344             }
9345             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9346                 return false;
9347             }
9348             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9349                 return false;
9350             }
9351             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9352                 return false;
9353             }
9354             p = d.getPolygons().get( 0 );
9355             if ( p.getPoints().size() != 3 ) {
9356                 return false;
9357             }
9358             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9359                 return false;
9360             }
9361             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9362                 return false;
9363             }
9364             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9365                 return false;
9366             }
9367             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9368                 return false;
9369             }
9370             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9371                 return false;
9372             }
9373             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9374                 return false;
9375             }
9376             p = d.getPolygons().get( 1 );
9377             if ( p.getPoints().size() != 3 ) {
9378                 return false;
9379             }
9380             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9381                 return false;
9382             }
9383             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9384                 return false;
9385             }
9386             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9387                 return false;
9388             }
9389         }
9390         catch ( final Exception e ) {
9391             e.printStackTrace( System.out );
9392             return false;
9393         }
9394         return true;
9395     }
9396
9397     private static boolean testPostOrderIterator() {
9398         try {
9399             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9400             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9401             PhylogenyNodeIterator it0;
9402             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9403                 it0.next();
9404             }
9405             for( it0.reset(); it0.hasNext(); ) {
9406                 it0.next();
9407             }
9408             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9409             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9410             if ( !it.next().getName().equals( "A" ) ) {
9411                 return false;
9412             }
9413             if ( !it.next().getName().equals( "B" ) ) {
9414                 return false;
9415             }
9416             if ( !it.next().getName().equals( "ab" ) ) {
9417                 return false;
9418             }
9419             if ( !it.next().getName().equals( "C" ) ) {
9420                 return false;
9421             }
9422             if ( !it.next().getName().equals( "D" ) ) {
9423                 return false;
9424             }
9425             if ( !it.next().getName().equals( "cd" ) ) {
9426                 return false;
9427             }
9428             if ( !it.next().getName().equals( "abcd" ) ) {
9429                 return false;
9430             }
9431             if ( !it.next().getName().equals( "E" ) ) {
9432                 return false;
9433             }
9434             if ( !it.next().getName().equals( "F" ) ) {
9435                 return false;
9436             }
9437             if ( !it.next().getName().equals( "ef" ) ) {
9438                 return false;
9439             }
9440             if ( !it.next().getName().equals( "G" ) ) {
9441                 return false;
9442             }
9443             if ( !it.next().getName().equals( "H" ) ) {
9444                 return false;
9445             }
9446             if ( !it.next().getName().equals( "gh" ) ) {
9447                 return false;
9448             }
9449             if ( !it.next().getName().equals( "efgh" ) ) {
9450                 return false;
9451             }
9452             if ( !it.next().getName().equals( "r" ) ) {
9453                 return false;
9454             }
9455             if ( it.hasNext() ) {
9456                 return false;
9457             }
9458         }
9459         catch ( final Exception e ) {
9460             e.printStackTrace( System.out );
9461             return false;
9462         }
9463         return true;
9464     }
9465
9466     private static boolean testPreOrderIterator() {
9467         try {
9468             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9469             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9470             PhylogenyNodeIterator it0;
9471             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9472                 it0.next();
9473             }
9474             for( it0.reset(); it0.hasNext(); ) {
9475                 it0.next();
9476             }
9477             PhylogenyNodeIterator it = t0.iteratorPreorder();
9478             if ( !it.next().getName().equals( "r" ) ) {
9479                 return false;
9480             }
9481             if ( !it.next().getName().equals( "ab" ) ) {
9482                 return false;
9483             }
9484             if ( !it.next().getName().equals( "A" ) ) {
9485                 return false;
9486             }
9487             if ( !it.next().getName().equals( "B" ) ) {
9488                 return false;
9489             }
9490             if ( !it.next().getName().equals( "cd" ) ) {
9491                 return false;
9492             }
9493             if ( !it.next().getName().equals( "C" ) ) {
9494                 return false;
9495             }
9496             if ( !it.next().getName().equals( "D" ) ) {
9497                 return false;
9498             }
9499             if ( it.hasNext() ) {
9500                 return false;
9501             }
9502             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9503             it = t1.iteratorPreorder();
9504             if ( !it.next().getName().equals( "r" ) ) {
9505                 return false;
9506             }
9507             if ( !it.next().getName().equals( "abcd" ) ) {
9508                 return false;
9509             }
9510             if ( !it.next().getName().equals( "ab" ) ) {
9511                 return false;
9512             }
9513             if ( !it.next().getName().equals( "A" ) ) {
9514                 return false;
9515             }
9516             if ( !it.next().getName().equals( "B" ) ) {
9517                 return false;
9518             }
9519             if ( !it.next().getName().equals( "cd" ) ) {
9520                 return false;
9521             }
9522             if ( !it.next().getName().equals( "C" ) ) {
9523                 return false;
9524             }
9525             if ( !it.next().getName().equals( "D" ) ) {
9526                 return false;
9527             }
9528             if ( !it.next().getName().equals( "efgh" ) ) {
9529                 return false;
9530             }
9531             if ( !it.next().getName().equals( "ef" ) ) {
9532                 return false;
9533             }
9534             if ( !it.next().getName().equals( "E" ) ) {
9535                 return false;
9536             }
9537             if ( !it.next().getName().equals( "F" ) ) {
9538                 return false;
9539             }
9540             if ( !it.next().getName().equals( "gh" ) ) {
9541                 return false;
9542             }
9543             if ( !it.next().getName().equals( "G" ) ) {
9544                 return false;
9545             }
9546             if ( !it.next().getName().equals( "H" ) ) {
9547                 return false;
9548             }
9549             if ( it.hasNext() ) {
9550                 return false;
9551             }
9552         }
9553         catch ( final Exception e ) {
9554             e.printStackTrace( System.out );
9555             return false;
9556         }
9557         return true;
9558     }
9559
9560     private static boolean testPropertiesMap() {
9561         try {
9562             final PropertiesMap pm = new PropertiesMap();
9563             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9564             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9565             final Property p2 = new Property( "something:else",
9566                                               "?",
9567                                               "improbable:research",
9568                                               "xsd:decimal",
9569                                               AppliesTo.NODE );
9570             pm.addProperty( p0 );
9571             pm.addProperty( p1 );
9572             pm.addProperty( p2 );
9573             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9574                 return false;
9575             }
9576             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9577                 return false;
9578             }
9579             if ( pm.getProperties().size() != 3 ) {
9580                 return false;
9581             }
9582             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9583                 return false;
9584             }
9585             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9586                 return false;
9587             }
9588             if ( pm.getProperties().size() != 3 ) {
9589                 return false;
9590             }
9591             pm.removeProperty( "dimensions:diameter" );
9592             if ( pm.getProperties().size() != 2 ) {
9593                 return false;
9594             }
9595             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9596                 return false;
9597             }
9598             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9599                 return false;
9600             }
9601         }
9602         catch ( final Exception e ) {
9603             e.printStackTrace( System.out );
9604             return false;
9605         }
9606         return true;
9607     }
9608
9609     private static boolean testProteinId() {
9610         try {
9611             final ProteinId id1 = new ProteinId( "a" );
9612             final ProteinId id2 = new ProteinId( "a" );
9613             final ProteinId id3 = new ProteinId( "A" );
9614             final ProteinId id4 = new ProteinId( "b" );
9615             if ( !id1.equals( id1 ) ) {
9616                 return false;
9617             }
9618             if ( id1.getId().equals( "x" ) ) {
9619                 return false;
9620             }
9621             if ( id1.getId().equals( null ) ) {
9622                 return false;
9623             }
9624             if ( !id1.equals( id2 ) ) {
9625                 return false;
9626             }
9627             if ( id1.equals( id3 ) ) {
9628                 return false;
9629             }
9630             if ( id1.hashCode() != id1.hashCode() ) {
9631                 return false;
9632             }
9633             if ( id1.hashCode() != id2.hashCode() ) {
9634                 return false;
9635             }
9636             if ( id1.hashCode() == id3.hashCode() ) {
9637                 return false;
9638             }
9639             if ( id1.compareTo( id1 ) != 0 ) {
9640                 return false;
9641             }
9642             if ( id1.compareTo( id2 ) != 0 ) {
9643                 return false;
9644             }
9645             if ( id1.compareTo( id3 ) != 0 ) {
9646                 return false;
9647             }
9648             if ( id1.compareTo( id4 ) >= 0 ) {
9649                 return false;
9650             }
9651             if ( id4.compareTo( id1 ) <= 0 ) {
9652                 return false;
9653             }
9654             if ( !id4.getId().equals( "b" ) ) {
9655                 return false;
9656             }
9657             final ProteinId id5 = new ProteinId( " C " );
9658             if ( !id5.getId().equals( "C" ) ) {
9659                 return false;
9660             }
9661             if ( id5.equals( id1 ) ) {
9662                 return false;
9663             }
9664         }
9665         catch ( final Exception e ) {
9666             e.printStackTrace( System.out );
9667             return false;
9668         }
9669         return true;
9670     }
9671
9672     private static boolean testReIdMethods() {
9673         try {
9674             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9675             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9676             final long count = PhylogenyNode.getNodeCount();
9677             p.levelOrderReID();
9678             if ( p.getNode( "r" ).getId() != count ) {
9679                 return false;
9680             }
9681             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9682                 return false;
9683             }
9684             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9685                 return false;
9686             }
9687             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9688                 return false;
9689             }
9690             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9691                 return false;
9692             }
9693             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9694                 return false;
9695             }
9696             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9697                 return false;
9698             }
9699             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9700                 return false;
9701             }
9702             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9703                 return false;
9704             }
9705             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9706                 return false;
9707             }
9708             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9709                 return false;
9710             }
9711             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9712                 return false;
9713             }
9714             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9715                 return false;
9716             }
9717             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9718                 return false;
9719             }
9720             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9721                 return false;
9722             }
9723         }
9724         catch ( final Exception e ) {
9725             e.printStackTrace( System.out );
9726             return false;
9727         }
9728         return true;
9729     }
9730
9731     private static boolean testRerooting() {
9732         try {
9733             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9734             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",
9735                                                  new NHXParser() )[ 0 ];
9736             if ( !t1.isRooted() ) {
9737                 return false;
9738             }
9739             t1.reRoot( t1.getNode( "D" ) );
9740             t1.reRoot( t1.getNode( "CD" ) );
9741             t1.reRoot( t1.getNode( "A" ) );
9742             t1.reRoot( t1.getNode( "B" ) );
9743             t1.reRoot( t1.getNode( "AB" ) );
9744             t1.reRoot( t1.getNode( "D" ) );
9745             t1.reRoot( t1.getNode( "C" ) );
9746             t1.reRoot( t1.getNode( "CD" ) );
9747             t1.reRoot( t1.getNode( "A" ) );
9748             t1.reRoot( t1.getNode( "B" ) );
9749             t1.reRoot( t1.getNode( "AB" ) );
9750             t1.reRoot( t1.getNode( "D" ) );
9751             t1.reRoot( t1.getNode( "D" ) );
9752             t1.reRoot( t1.getNode( "C" ) );
9753             t1.reRoot( t1.getNode( "A" ) );
9754             t1.reRoot( t1.getNode( "B" ) );
9755             t1.reRoot( t1.getNode( "AB" ) );
9756             t1.reRoot( t1.getNode( "C" ) );
9757             t1.reRoot( t1.getNode( "D" ) );
9758             t1.reRoot( t1.getNode( "CD" ) );
9759             t1.reRoot( t1.getNode( "D" ) );
9760             t1.reRoot( t1.getNode( "A" ) );
9761             t1.reRoot( t1.getNode( "B" ) );
9762             t1.reRoot( t1.getNode( "AB" ) );
9763             t1.reRoot( t1.getNode( "C" ) );
9764             t1.reRoot( t1.getNode( "D" ) );
9765             t1.reRoot( t1.getNode( "CD" ) );
9766             t1.reRoot( t1.getNode( "D" ) );
9767             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9768                 return false;
9769             }
9770             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9771                 return false;
9772             }
9773             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9774                 return false;
9775             }
9776             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9777                 return false;
9778             }
9779             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9780                 return false;
9781             }
9782             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9783                 return false;
9784             }
9785             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",
9786                                                  new NHXParser() )[ 0 ];
9787             t2.reRoot( t2.getNode( "A" ) );
9788             t2.reRoot( t2.getNode( "D" ) );
9789             t2.reRoot( t2.getNode( "ABC" ) );
9790             t2.reRoot( t2.getNode( "A" ) );
9791             t2.reRoot( t2.getNode( "B" ) );
9792             t2.reRoot( t2.getNode( "D" ) );
9793             t2.reRoot( t2.getNode( "C" ) );
9794             t2.reRoot( t2.getNode( "ABC" ) );
9795             t2.reRoot( t2.getNode( "A" ) );
9796             t2.reRoot( t2.getNode( "B" ) );
9797             t2.reRoot( t2.getNode( "AB" ) );
9798             t2.reRoot( t2.getNode( "AB" ) );
9799             t2.reRoot( t2.getNode( "D" ) );
9800             t2.reRoot( t2.getNode( "C" ) );
9801             t2.reRoot( t2.getNode( "B" ) );
9802             t2.reRoot( t2.getNode( "AB" ) );
9803             t2.reRoot( t2.getNode( "D" ) );
9804             t2.reRoot( t2.getNode( "D" ) );
9805             t2.reRoot( t2.getNode( "ABC" ) );
9806             t2.reRoot( t2.getNode( "A" ) );
9807             t2.reRoot( t2.getNode( "B" ) );
9808             t2.reRoot( t2.getNode( "AB" ) );
9809             t2.reRoot( t2.getNode( "D" ) );
9810             t2.reRoot( t2.getNode( "C" ) );
9811             t2.reRoot( t2.getNode( "ABC" ) );
9812             t2.reRoot( t2.getNode( "A" ) );
9813             t2.reRoot( t2.getNode( "B" ) );
9814             t2.reRoot( t2.getNode( "AB" ) );
9815             t2.reRoot( t2.getNode( "D" ) );
9816             t2.reRoot( t2.getNode( "D" ) );
9817             t2.reRoot( t2.getNode( "C" ) );
9818             t2.reRoot( t2.getNode( "A" ) );
9819             t2.reRoot( t2.getNode( "B" ) );
9820             t2.reRoot( t2.getNode( "AB" ) );
9821             t2.reRoot( t2.getNode( "C" ) );
9822             t2.reRoot( t2.getNode( "D" ) );
9823             t2.reRoot( t2.getNode( "ABC" ) );
9824             t2.reRoot( t2.getNode( "D" ) );
9825             t2.reRoot( t2.getNode( "A" ) );
9826             t2.reRoot( t2.getNode( "B" ) );
9827             t2.reRoot( t2.getNode( "AB" ) );
9828             t2.reRoot( t2.getNode( "C" ) );
9829             t2.reRoot( t2.getNode( "D" ) );
9830             t2.reRoot( t2.getNode( "ABC" ) );
9831             t2.reRoot( t2.getNode( "D" ) );
9832             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9833                 return false;
9834             }
9835             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9836                 return false;
9837             }
9838             t2.reRoot( t2.getNode( "ABC" ) );
9839             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9840                 return false;
9841             }
9842             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9843                 return false;
9844             }
9845             t2.reRoot( t2.getNode( "AB" ) );
9846             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9847                 return false;
9848             }
9849             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9850                 return false;
9851             }
9852             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9853                 return false;
9854             }
9855             t2.reRoot( t2.getNode( "AB" ) );
9856             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9857                 return false;
9858             }
9859             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9860                 return false;
9861             }
9862             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9863                 return false;
9864             }
9865             t2.reRoot( t2.getNode( "D" ) );
9866             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9867                 return false;
9868             }
9869             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9870                 return false;
9871             }
9872             t2.reRoot( t2.getNode( "ABC" ) );
9873             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9874                 return false;
9875             }
9876             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9877                 return false;
9878             }
9879             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9880                                                  new NHXParser() )[ 0 ];
9881             t3.reRoot( t3.getNode( "B" ) );
9882             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9883                 return false;
9884             }
9885             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9886                 return false;
9887             }
9888             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9889                 return false;
9890             }
9891             t3.reRoot( t3.getNode( "B" ) );
9892             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9893                 return false;
9894             }
9895             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9896                 return false;
9897             }
9898             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9899                 return false;
9900             }
9901             t3.reRoot( t3.getRoot() );
9902             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9903                 return false;
9904             }
9905             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9906                 return false;
9907             }
9908             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9909                 return false;
9910             }
9911         }
9912         catch ( final Exception e ) {
9913             e.printStackTrace( System.out );
9914             return false;
9915         }
9916         return true;
9917     }
9918
9919     private static boolean testSDIse() {
9920         try {
9921             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9922             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9923             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9924             gene1.setRooted( true );
9925             species1.setRooted( true );
9926             final SDI sdi = new SDI( gene1, species1 );
9927             if ( !gene1.getRoot().isDuplication() ) {
9928                 return false;
9929             }
9930             final Phylogeny species2 = factory
9931                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9932                              new NHXParser() )[ 0 ];
9933             final Phylogeny gene2 = factory
9934                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9935                              new NHXParser() )[ 0 ];
9936             species2.setRooted( true );
9937             gene2.setRooted( true );
9938             final SDI sdi2 = new SDI( gene2, species2 );
9939             if ( sdi2.getDuplicationsSum() != 0 ) {
9940                 return false;
9941             }
9942             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9943                 return false;
9944             }
9945             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9946                 return false;
9947             }
9948             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9949                 return false;
9950             }
9951             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9952                 return false;
9953             }
9954             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9955                 return false;
9956             }
9957             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9958                 return false;
9959             }
9960             final Phylogeny species3 = factory
9961                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9962                              new NHXParser() )[ 0 ];
9963             final Phylogeny gene3 = factory
9964                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9965                              new NHXParser() )[ 0 ];
9966             species3.setRooted( true );
9967             gene3.setRooted( true );
9968             final SDI sdi3 = new SDI( gene3, species3 );
9969             if ( sdi3.getDuplicationsSum() != 1 ) {
9970                 return false;
9971             }
9972             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9973                 return false;
9974             }
9975             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9976                 return false;
9977             }
9978             final Phylogeny species4 = factory
9979                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9980                              new NHXParser() )[ 0 ];
9981             final Phylogeny gene4 = factory
9982                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9983                              new NHXParser() )[ 0 ];
9984             species4.setRooted( true );
9985             gene4.setRooted( true );
9986             final SDI sdi4 = new SDI( gene4, species4 );
9987             if ( sdi4.getDuplicationsSum() != 1 ) {
9988                 return false;
9989             }
9990             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9991                 return false;
9992             }
9993             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9994                 return false;
9995             }
9996             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9997                 return false;
9998             }
9999             if ( species4.getNumberOfExternalNodes() != 6 ) {
10000                 return false;
10001             }
10002             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10003                 return false;
10004             }
10005             final Phylogeny species5 = factory
10006                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10007                              new NHXParser() )[ 0 ];
10008             final Phylogeny gene5 = factory
10009                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10010                              new NHXParser() )[ 0 ];
10011             species5.setRooted( true );
10012             gene5.setRooted( true );
10013             final SDI sdi5 = new SDI( gene5, species5 );
10014             if ( sdi5.getDuplicationsSum() != 2 ) {
10015                 return false;
10016             }
10017             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10018                 return false;
10019             }
10020             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10021                 return false;
10022             }
10023             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10024                 return false;
10025             }
10026             if ( species5.getNumberOfExternalNodes() != 6 ) {
10027                 return false;
10028             }
10029             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10030                 return false;
10031             }
10032             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10033             // Conjecture for Comparing Molecular Phylogenies"
10034             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10035             final Phylogeny species6 = factory
10036                     .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,"
10037                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10038                              new NHXParser() )[ 0 ];
10039             final Phylogeny gene6 = factory
10040                     .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,"
10041                                      + "((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,"
10042                                      + "(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;",
10043                              new NHXParser() )[ 0 ];
10044             species6.setRooted( true );
10045             gene6.setRooted( true );
10046             final SDI sdi6 = new SDI( gene6, species6 );
10047             if ( sdi6.getDuplicationsSum() != 3 ) {
10048                 return false;
10049             }
10050             if ( !gene6.getNode( "r" ).isDuplication() ) {
10051                 return false;
10052             }
10053             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10054                 return false;
10055             }
10056             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10057                 return false;
10058             }
10059             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10060                 return false;
10061             }
10062             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10063                 return false;
10064             }
10065             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10066                 return false;
10067             }
10068             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10069                 return false;
10070             }
10071             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10072                 return false;
10073             }
10074             sdi6.computeMappingCostL();
10075             if ( sdi6.computeMappingCostL() != 17 ) {
10076                 return false;
10077             }
10078             if ( species6.getNumberOfExternalNodes() != 9 ) {
10079                 return false;
10080             }
10081             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10082                 return false;
10083             }
10084             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10085                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10086                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10087                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10088                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10089             species7.setRooted( true );
10090             final Phylogeny gene7_1 = Test
10091                     .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])" );
10092             gene7_1.setRooted( true );
10093             final SDI sdi7 = new SDI( gene7_1, species7 );
10094             if ( sdi7.getDuplicationsSum() != 0 ) {
10095                 return false;
10096             }
10097             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10098                 return false;
10099             }
10100             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10101                 return false;
10102             }
10103             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10104                 return false;
10105             }
10106             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10107                 return false;
10108             }
10109             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10110                 return false;
10111             }
10112             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10113                 return false;
10114             }
10115             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10116                 return false;
10117             }
10118             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10119                 return false;
10120             }
10121             final Phylogeny gene7_2 = Test
10122                     .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])" );
10123             gene7_2.setRooted( true );
10124             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10125             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10126                 return false;
10127             }
10128             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10129                 return false;
10130             }
10131             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10132                 return false;
10133             }
10134             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10135                 return false;
10136             }
10137             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10138                 return false;
10139             }
10140             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10141                 return false;
10142             }
10143             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10144                 return false;
10145             }
10146             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10147                 return false;
10148             }
10149             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10150                 return false;
10151             }
10152             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10153                 return false;
10154             }
10155         }
10156         catch ( final Exception e ) {
10157             return false;
10158         }
10159         return true;
10160     }
10161
10162     private static boolean testSDIunrooted() {
10163         try {
10164             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10165             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10166             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10167             final Iterator<PhylogenyBranch> iter = l.iterator();
10168             PhylogenyBranch br = iter.next();
10169             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10170                 return false;
10171             }
10172             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10173                 return false;
10174             }
10175             br = iter.next();
10176             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10177                 return false;
10178             }
10179             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10180                 return false;
10181             }
10182             br = iter.next();
10183             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10184                 return false;
10185             }
10186             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10187                 return false;
10188             }
10189             br = iter.next();
10190             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10191                 return false;
10192             }
10193             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10194                 return false;
10195             }
10196             br = iter.next();
10197             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10198                 return false;
10199             }
10200             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10201                 return false;
10202             }
10203             br = iter.next();
10204             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10205                 return false;
10206             }
10207             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10208                 return false;
10209             }
10210             br = iter.next();
10211             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10212                 return false;
10213             }
10214             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10215                 return false;
10216             }
10217             br = iter.next();
10218             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10219                 return false;
10220             }
10221             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10222                 return false;
10223             }
10224             br = iter.next();
10225             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10226                 return false;
10227             }
10228             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10229                 return false;
10230             }
10231             br = iter.next();
10232             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10233                 return false;
10234             }
10235             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10236                 return false;
10237             }
10238             br = iter.next();
10239             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10240                 return false;
10241             }
10242             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10243                 return false;
10244             }
10245             br = iter.next();
10246             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10247                 return false;
10248             }
10249             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10250                 return false;
10251             }
10252             br = iter.next();
10253             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10254                 return false;
10255             }
10256             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10257                 return false;
10258             }
10259             br = iter.next();
10260             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10261                 return false;
10262             }
10263             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10264                 return false;
10265             }
10266             br = iter.next();
10267             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10268                 return false;
10269             }
10270             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10271                 return false;
10272             }
10273             if ( iter.hasNext() ) {
10274                 return false;
10275             }
10276             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10277             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10278             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10279             br = iter1.next();
10280             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10281                 return false;
10282             }
10283             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10284                 return false;
10285             }
10286             br = iter1.next();
10287             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10288                 return false;
10289             }
10290             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10291                 return false;
10292             }
10293             br = iter1.next();
10294             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10295                 return false;
10296             }
10297             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10298                 return false;
10299             }
10300             if ( iter1.hasNext() ) {
10301                 return false;
10302             }
10303             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10304             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10305             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10306             br = iter2.next();
10307             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10308                 return false;
10309             }
10310             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10311                 return false;
10312             }
10313             br = iter2.next();
10314             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10315                 return false;
10316             }
10317             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10318                 return false;
10319             }
10320             br = iter2.next();
10321             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10322                 return false;
10323             }
10324             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10325                 return false;
10326             }
10327             if ( iter2.hasNext() ) {
10328                 return false;
10329             }
10330             final Phylogeny species0 = factory
10331                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10332                              new NHXParser() )[ 0 ];
10333             final Phylogeny gene1 = factory
10334                     .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])",
10335                              new NHXParser() )[ 0 ];
10336             species0.setRooted( true );
10337             gene1.setRooted( true );
10338             final SDIR sdi_unrooted = new SDIR();
10339             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10340             if ( sdi_unrooted.getCount() != 1 ) {
10341                 return false;
10342             }
10343             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10344                 return false;
10345             }
10346             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10347                 return false;
10348             }
10349             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10350                 return false;
10351             }
10352             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10353                 return false;
10354             }
10355             final Phylogeny gene2 = factory
10356                     .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])",
10357                              new NHXParser() )[ 0 ];
10358             gene2.setRooted( true );
10359             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10360             if ( sdi_unrooted.getCount() != 1 ) {
10361                 return false;
10362             }
10363             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10364                 return false;
10365             }
10366             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10367                 return false;
10368             }
10369             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10370                 return false;
10371             }
10372             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10373                 return false;
10374             }
10375             final Phylogeny species6 = factory
10376                     .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,"
10377                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10378                              new NHXParser() )[ 0 ];
10379             final Phylogeny gene6 = factory
10380                     .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],"
10381                                      + "(((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],"
10382                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10383                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10384                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10385                              new NHXParser() )[ 0 ];
10386             species6.setRooted( true );
10387             gene6.setRooted( true );
10388             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10389             if ( sdi_unrooted.getCount() != 1 ) {
10390                 return false;
10391             }
10392             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10393                 return false;
10394             }
10395             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10396                 return false;
10397             }
10398             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10399                 return false;
10400             }
10401             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10402                 return false;
10403             }
10404             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10405                 return false;
10406             }
10407             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10408                 return false;
10409             }
10410             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10411                 return false;
10412             }
10413             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10414                 return false;
10415             }
10416             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10417                 return false;
10418             }
10419             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10420                 return false;
10421             }
10422             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10423                 return false;
10424             }
10425             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10426                 return false;
10427             }
10428             p6 = null;
10429             final Phylogeny species7 = factory
10430                     .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,"
10431                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10432                              new NHXParser() )[ 0 ];
10433             final Phylogeny gene7 = factory
10434                     .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],"
10435                                      + "(((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],"
10436                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10437                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10438                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10439                              new NHXParser() )[ 0 ];
10440             species7.setRooted( true );
10441             gene7.setRooted( true );
10442             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10443             if ( sdi_unrooted.getCount() != 1 ) {
10444                 return false;
10445             }
10446             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10447                 return false;
10448             }
10449             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10450                 return false;
10451             }
10452             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10453                 return false;
10454             }
10455             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10456                 return false;
10457             }
10458             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10459                 return false;
10460             }
10461             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10462                 return false;
10463             }
10464             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10465                 return false;
10466             }
10467             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10468                 return false;
10469             }
10470             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10471                 return false;
10472             }
10473             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10474                 return false;
10475             }
10476             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10477                 return false;
10478             }
10479             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10480                 return false;
10481             }
10482             p7 = null;
10483             final Phylogeny species8 = factory
10484                     .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,"
10485                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10486                              new NHXParser() )[ 0 ];
10487             final Phylogeny gene8 = factory
10488                     .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],"
10489                                      + "(((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],"
10490                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10491                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10492                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10493                              new NHXParser() )[ 0 ];
10494             species8.setRooted( true );
10495             gene8.setRooted( true );
10496             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10497             if ( sdi_unrooted.getCount() != 1 ) {
10498                 return false;
10499             }
10500             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10501                 return false;
10502             }
10503             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10504                 return false;
10505             }
10506             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10507                 return false;
10508             }
10509             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10510                 return false;
10511             }
10512             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10513                 return false;
10514             }
10515             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10516                 return false;
10517             }
10518             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10519                 return false;
10520             }
10521             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10522                 return false;
10523             }
10524             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10525                 return false;
10526             }
10527             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10528                 return false;
10529             }
10530             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10531                 return false;
10532             }
10533             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10534                 return false;
10535             }
10536             p8 = null;
10537         }
10538         catch ( final Exception e ) {
10539             e.printStackTrace( System.out );
10540             return false;
10541         }
10542         return true;
10543     }
10544
10545     private static boolean testSequenceDbWsTools1() {
10546         try {
10547             final PhylogenyNode n = new PhylogenyNode();
10548             n.setName( "NP_001025424" );
10549             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10550             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10551                     || !acc.getValue().equals( "NP_001025424" ) ) {
10552                 return false;
10553             }
10554             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10555             acc = SequenceDbWsTools.obtainSeqAccession( n );
10556             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10557                     || !acc.getValue().equals( "NP_001025424" ) ) {
10558                 return false;
10559             }
10560             n.setName( "NP_001025424.1" );
10561             acc = SequenceDbWsTools.obtainSeqAccession( n );
10562             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10563                     || !acc.getValue().equals( "NP_001025424" ) ) {
10564                 return false;
10565             }
10566             n.setName( "NM_001030253" );
10567             acc = SequenceDbWsTools.obtainSeqAccession( n );
10568             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10569                     || !acc.getValue().equals( "NM_001030253" ) ) {
10570                 return false;
10571             }
10572             n.setName( "BCL2_HUMAN" );
10573             acc = SequenceDbWsTools.obtainSeqAccession( n );
10574             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10575                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10576                 System.out.println( acc.toString() );
10577                 return false;
10578             }
10579             n.setName( "P10415" );
10580             acc = SequenceDbWsTools.obtainSeqAccession( n );
10581             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10582                     || !acc.getValue().equals( "P10415" ) ) {
10583                 System.out.println( acc.toString() );
10584                 return false;
10585             }
10586             n.setName( " P10415 " );
10587             acc = SequenceDbWsTools.obtainSeqAccession( n );
10588             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10589                     || !acc.getValue().equals( "P10415" ) ) {
10590                 System.out.println( acc.toString() );
10591                 return false;
10592             }
10593             n.setName( "_P10415|" );
10594             acc = SequenceDbWsTools.obtainSeqAccession( n );
10595             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10596                     || !acc.getValue().equals( "P10415" ) ) {
10597                 System.out.println( acc.toString() );
10598                 return false;
10599             }
10600             n.setName( "AY695820" );
10601             acc = SequenceDbWsTools.obtainSeqAccession( n );
10602             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10603                     || !acc.getValue().equals( "AY695820" ) ) {
10604                 System.out.println( acc.toString() );
10605                 return false;
10606             }
10607             n.setName( "_AY695820_" );
10608             acc = SequenceDbWsTools.obtainSeqAccession( n );
10609             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10610                     || !acc.getValue().equals( "AY695820" ) ) {
10611                 System.out.println( acc.toString() );
10612                 return false;
10613             }
10614             n.setName( "AAA59452" );
10615             acc = SequenceDbWsTools.obtainSeqAccession( n );
10616             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10617                     || !acc.getValue().equals( "AAA59452" ) ) {
10618                 System.out.println( acc.toString() );
10619                 return false;
10620             }
10621             n.setName( "_AAA59452_" );
10622             acc = SequenceDbWsTools.obtainSeqAccession( n );
10623             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10624                     || !acc.getValue().equals( "AAA59452" ) ) {
10625                 System.out.println( acc.toString() );
10626                 return false;
10627             }
10628             n.setName( "AAA59452.1" );
10629             acc = SequenceDbWsTools.obtainSeqAccession( n );
10630             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10631                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10632                 System.out.println( acc.toString() );
10633                 return false;
10634             }
10635             n.setName( "_AAA59452.1_" );
10636             acc = SequenceDbWsTools.obtainSeqAccession( n );
10637             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10638                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10639                 System.out.println( acc.toString() );
10640                 return false;
10641             }
10642             n.setName( "GI:94894583" );
10643             acc = SequenceDbWsTools.obtainSeqAccession( n );
10644             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10645                     || !acc.getValue().equals( "94894583" ) ) {
10646                 System.out.println( acc.toString() );
10647                 return false;
10648             }
10649             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10650             acc = SequenceDbWsTools.obtainSeqAccession( n );
10651             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10652                     || !acc.getValue().equals( "71845847" ) ) {
10653                 System.out.println( acc.toString() );
10654                 return false;
10655             }
10656             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10657             acc = SequenceDbWsTools.obtainSeqAccession( n );
10658             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10659                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10660                 System.out.println( acc.toString() );
10661                 return false;
10662             }
10663         }
10664         catch ( final Exception e ) {
10665             return false;
10666         }
10667         return true;
10668     }
10669
10670     private static boolean testSequenceDbWsTools2() {
10671         try {
10672             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10673             SequenceDbWsTools.obtainSeqInformation( n1 );
10674             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10675                 return false;
10676             }
10677             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10678                 return false;
10679             }
10680             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10681                 return false;
10682             }
10683             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10684                 return false;
10685             }
10686             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10687             SequenceDbWsTools.obtainSeqInformation( n2 );
10688             if ( !n2.getNodeData().getSequence().getName()
10689                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10690                 return false;
10691             }
10692             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10693                 return false;
10694             }
10695             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10696                 return false;
10697             }
10698             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10699                 return false;
10700             }
10701             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10702             SequenceDbWsTools.obtainSeqInformation( n3 );
10703             if ( !n3.getNodeData().getSequence().getName()
10704                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10705                 return false;
10706             }
10707             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10708                 return false;
10709             }
10710             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10711                 return false;
10712             }
10713             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10714                 return false;
10715             }
10716         }
10717         catch ( final IOException e ) {
10718             System.out.println();
10719             System.out.println( "the following might be due to absence internet connection:" );
10720             e.printStackTrace( System.out );
10721             return true;
10722         }
10723         catch ( final Exception e ) {
10724             e.printStackTrace();
10725             return false;
10726         }
10727         return true;
10728     }
10729
10730     private static boolean testSequenceIdParsing() {
10731         try {
10732             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10733             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10734                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10735                 if ( id != null ) {
10736                     System.out.println( "value   =" + id.getValue() );
10737                     System.out.println( "provider=" + id.getSource() );
10738                 }
10739                 return false;
10740             }
10741             //
10742             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10743             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10744                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10745                 if ( id != null ) {
10746                     System.out.println( "value   =" + id.getValue() );
10747                     System.out.println( "provider=" + id.getSource() );
10748                 }
10749                 return false;
10750             }
10751             //
10752             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10753             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10754                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10755                 if ( id != null ) {
10756                     System.out.println( "value   =" + id.getValue() );
10757                     System.out.println( "provider=" + id.getSource() );
10758                 }
10759                 return false;
10760             }
10761             // 
10762             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10763             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10764                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10765                 if ( id != null ) {
10766                     System.out.println( "value   =" + id.getValue() );
10767                     System.out.println( "provider=" + id.getSource() );
10768                 }
10769                 return false;
10770             }
10771             // 
10772             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10773             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10774                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10775                 if ( id != null ) {
10776                     System.out.println( "value   =" + id.getValue() );
10777                     System.out.println( "provider=" + id.getSource() );
10778                 }
10779                 return false;
10780             }
10781             // 
10782             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10783             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10784                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10785                 if ( id != null ) {
10786                     System.out.println( "value   =" + id.getValue() );
10787                     System.out.println( "provider=" + id.getSource() );
10788                 }
10789                 return false;
10790             }
10791             // 
10792             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10793             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10794                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10795                 if ( id != null ) {
10796                     System.out.println( "value   =" + id.getValue() );
10797                     System.out.println( "provider=" + id.getSource() );
10798                 }
10799                 return false;
10800             }
10801             // 
10802             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10803             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10804                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10805                 if ( id != null ) {
10806                     System.out.println( "value   =" + id.getValue() );
10807                     System.out.println( "provider=" + id.getSource() );
10808                 }
10809                 return false;
10810             }
10811             // 
10812             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10813             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10814                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10815                 if ( id != null ) {
10816                     System.out.println( "value   =" + id.getValue() );
10817                     System.out.println( "provider=" + id.getSource() );
10818                 }
10819                 return false;
10820             }
10821             // 
10822             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10823             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10824                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10825                 if ( id != null ) {
10826                     System.out.println( "value   =" + id.getValue() );
10827                     System.out.println( "provider=" + id.getSource() );
10828                 }
10829                 return false;
10830             }
10831             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10832             if ( id != null ) {
10833                 System.out.println( "value   =" + id.getValue() );
10834                 System.out.println( "provider=" + id.getSource() );
10835                 return false;
10836             }
10837         }
10838         catch ( final Exception e ) {
10839             e.printStackTrace( System.out );
10840             return false;
10841         }
10842         return true;
10843     }
10844
10845     private static boolean testSequenceWriter() {
10846         try {
10847             final String n = ForesterUtil.LINE_SEPARATOR;
10848             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10849                 return false;
10850             }
10851             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10852                 return false;
10853             }
10854             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10855                 return false;
10856             }
10857             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10858                 return false;
10859             }
10860             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10861                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10862                 return false;
10863             }
10864             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10865                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10866                 return false;
10867             }
10868         }
10869         catch ( final Exception e ) {
10870             e.printStackTrace();
10871             return false;
10872         }
10873         return true;
10874     }
10875
10876     private static boolean testSpecies() {
10877         try {
10878             final Species s1 = new BasicSpecies( "a" );
10879             final Species s2 = new BasicSpecies( "a" );
10880             final Species s3 = new BasicSpecies( "A" );
10881             final Species s4 = new BasicSpecies( "b" );
10882             if ( !s1.equals( s1 ) ) {
10883                 return false;
10884             }
10885             if ( s1.getSpeciesId().equals( "x" ) ) {
10886                 return false;
10887             }
10888             if ( s1.getSpeciesId().equals( null ) ) {
10889                 return false;
10890             }
10891             if ( !s1.equals( s2 ) ) {
10892                 return false;
10893             }
10894             if ( s1.equals( s3 ) ) {
10895                 return false;
10896             }
10897             if ( s1.hashCode() != s1.hashCode() ) {
10898                 return false;
10899             }
10900             if ( s1.hashCode() != s2.hashCode() ) {
10901                 return false;
10902             }
10903             if ( s1.hashCode() == s3.hashCode() ) {
10904                 return false;
10905             }
10906             if ( s1.compareTo( s1 ) != 0 ) {
10907                 return false;
10908             }
10909             if ( s1.compareTo( s2 ) != 0 ) {
10910                 return false;
10911             }
10912             if ( s1.compareTo( s3 ) != 0 ) {
10913                 return false;
10914             }
10915             if ( s1.compareTo( s4 ) >= 0 ) {
10916                 return false;
10917             }
10918             if ( s4.compareTo( s1 ) <= 0 ) {
10919                 return false;
10920             }
10921             if ( !s4.getSpeciesId().equals( "b" ) ) {
10922                 return false;
10923             }
10924             final Species s5 = new BasicSpecies( " C " );
10925             if ( !s5.getSpeciesId().equals( "C" ) ) {
10926                 return false;
10927             }
10928             if ( s5.equals( s1 ) ) {
10929                 return false;
10930             }
10931         }
10932         catch ( final Exception e ) {
10933             e.printStackTrace( System.out );
10934             return false;
10935         }
10936         return true;
10937     }
10938
10939     private static boolean testSplit() {
10940         try {
10941             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10942             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10943             //Archaeopteryx.createApplication( p0 );
10944             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10945             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10946             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10947             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10948             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10949             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10950             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10951             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10952             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10953             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10954             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10955             // System.out.println( s0.toString() );
10956             //
10957             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10960             if ( s0.match( query_nodes ) ) {
10961                 return false;
10962             }
10963             query_nodes = new HashSet<PhylogenyNode>();
10964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10971             if ( !s0.match( query_nodes ) ) {
10972                 return false;
10973             }
10974             //
10975             query_nodes = new HashSet<PhylogenyNode>();
10976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10979             if ( !s0.match( query_nodes ) ) {
10980                 return false;
10981             }
10982             //
10983             query_nodes = new HashSet<PhylogenyNode>();
10984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10988             if ( !s0.match( query_nodes ) ) {
10989                 return false;
10990             }
10991             //
10992             query_nodes = new HashSet<PhylogenyNode>();
10993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10997             if ( !s0.match( query_nodes ) ) {
10998                 return false;
10999             }
11000             //
11001             query_nodes = new HashSet<PhylogenyNode>();
11002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11005             if ( !s0.match( query_nodes ) ) {
11006                 return false;
11007             }
11008             //
11009             query_nodes = new HashSet<PhylogenyNode>();
11010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11012             if ( !s0.match( query_nodes ) ) {
11013                 return false;
11014             }
11015             //
11016             query_nodes = new HashSet<PhylogenyNode>();
11017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11022             if ( !s0.match( query_nodes ) ) {
11023                 return false;
11024             }
11025             //
11026             query_nodes = new HashSet<PhylogenyNode>();
11027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11030             if ( !s0.match( query_nodes ) ) {
11031                 return false;
11032             }
11033             //
11034             query_nodes = new HashSet<PhylogenyNode>();
11035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11039             if ( !s0.match( query_nodes ) ) {
11040                 return false;
11041             }
11042             //
11043             query_nodes = new HashSet<PhylogenyNode>();
11044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11046             if ( s0.match( query_nodes ) ) {
11047                 return false;
11048             }
11049             //
11050             query_nodes = new HashSet<PhylogenyNode>();
11051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11055             if ( s0.match( query_nodes ) ) {
11056                 return false;
11057             }
11058             //
11059             query_nodes = new HashSet<PhylogenyNode>();
11060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11065             if ( s0.match( query_nodes ) ) {
11066                 return false;
11067             }
11068             //
11069             query_nodes = new HashSet<PhylogenyNode>();
11070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11073             if ( s0.match( query_nodes ) ) {
11074                 return false;
11075             }
11076             //
11077             query_nodes = new HashSet<PhylogenyNode>();
11078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11080             if ( s0.match( query_nodes ) ) {
11081                 return false;
11082             }
11083             //
11084             query_nodes = new HashSet<PhylogenyNode>();
11085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11087             if ( s0.match( query_nodes ) ) {
11088                 return false;
11089             }
11090             //
11091             query_nodes = new HashSet<PhylogenyNode>();
11092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11093             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11094             if ( s0.match( query_nodes ) ) {
11095                 return false;
11096             }
11097             //
11098             query_nodes = new HashSet<PhylogenyNode>();
11099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11101             if ( s0.match( query_nodes ) ) {
11102                 return false;
11103             }
11104             //
11105             query_nodes = new HashSet<PhylogenyNode>();
11106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11108             if ( s0.match( query_nodes ) ) {
11109                 return false;
11110             }
11111             //
11112             query_nodes = new HashSet<PhylogenyNode>();
11113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11115             if ( s0.match( query_nodes ) ) {
11116                 return false;
11117             }
11118             //
11119             query_nodes = new HashSet<PhylogenyNode>();
11120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11123             if ( s0.match( query_nodes ) ) {
11124                 return false;
11125             }
11126             //
11127             query_nodes = new HashSet<PhylogenyNode>();
11128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11129             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11131             if ( s0.match( query_nodes ) ) {
11132                 return false;
11133             }
11134             //
11135             query_nodes = new HashSet<PhylogenyNode>();
11136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11137             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11139             if ( s0.match( query_nodes ) ) {
11140                 return false;
11141             }
11142             //
11143             query_nodes = new HashSet<PhylogenyNode>();
11144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11145             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11146             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11148             if ( s0.match( query_nodes ) ) {
11149                 return false;
11150             }
11151             /////////
11152             //            query_nodes = new HashSet<PhylogenyNode>();
11153             //            query_nodes.add( new PhylogenyNode( "X" ) );
11154             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11155             //            query_nodes.add( new PhylogenyNode( "A" ) );
11156             //            query_nodes.add( new PhylogenyNode( "B" ) );
11157             //            query_nodes.add( new PhylogenyNode( "C" ) );
11158             //            query_nodes.add( new PhylogenyNode( "D" ) );
11159             //            query_nodes.add( new PhylogenyNode( "E" ) );
11160             //            query_nodes.add( new PhylogenyNode( "F" ) );
11161             //            query_nodes.add( new PhylogenyNode( "G" ) );
11162             //            if ( !s0.match( query_nodes ) ) {
11163             //                return false;
11164             //            }
11165             //            query_nodes = new HashSet<PhylogenyNode>();
11166             //            query_nodes.add( new PhylogenyNode( "X" ) );
11167             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11168             //            query_nodes.add( new PhylogenyNode( "A" ) );
11169             //            query_nodes.add( new PhylogenyNode( "B" ) );
11170             //            query_nodes.add( new PhylogenyNode( "C" ) );
11171             //            if ( !s0.match( query_nodes ) ) {
11172             //                return false;
11173             //            }
11174             //            //
11175             //            query_nodes = new HashSet<PhylogenyNode>();
11176             //            query_nodes.add( new PhylogenyNode( "X" ) );
11177             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11178             //            query_nodes.add( new PhylogenyNode( "D" ) );
11179             //            query_nodes.add( new PhylogenyNode( "E" ) );
11180             //            query_nodes.add( new PhylogenyNode( "F" ) );
11181             //            query_nodes.add( new PhylogenyNode( "G" ) );
11182             //            if ( !s0.match( query_nodes ) ) {
11183             //                return false;
11184             //            }
11185             //            //
11186             //            query_nodes = new HashSet<PhylogenyNode>();
11187             //            query_nodes.add( new PhylogenyNode( "X" ) );
11188             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11189             //            query_nodes.add( new PhylogenyNode( "A" ) );
11190             //            query_nodes.add( new PhylogenyNode( "B" ) );
11191             //            query_nodes.add( new PhylogenyNode( "C" ) );
11192             //            query_nodes.add( new PhylogenyNode( "D" ) );
11193             //            if ( !s0.match( query_nodes ) ) {
11194             //                return false;
11195             //            }
11196             //            //
11197             //            query_nodes = new HashSet<PhylogenyNode>();
11198             //            query_nodes.add( new PhylogenyNode( "X" ) );
11199             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11200             //            query_nodes.add( new PhylogenyNode( "E" ) );
11201             //            query_nodes.add( new PhylogenyNode( "F" ) );
11202             //            query_nodes.add( new PhylogenyNode( "G" ) );
11203             //            if ( !s0.match( query_nodes ) ) {
11204             //                return false;
11205             //            }
11206             //            //
11207             //            query_nodes = new HashSet<PhylogenyNode>();
11208             //            query_nodes.add( new PhylogenyNode( "X" ) );
11209             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11210             //            query_nodes.add( new PhylogenyNode( "F" ) );
11211             //            query_nodes.add( new PhylogenyNode( "G" ) );
11212             //            if ( !s0.match( query_nodes ) ) {
11213             //                return false;
11214             //            }
11215             //
11216             query_nodes = new HashSet<PhylogenyNode>();
11217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11221             if ( s0.match( query_nodes ) ) {
11222                 return false;
11223             }
11224             //
11225             query_nodes = new HashSet<PhylogenyNode>();
11226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11230             if ( s0.match( query_nodes ) ) {
11231                 return false;
11232             }
11233             ///////////////////////////
11234             //
11235             query_nodes = new HashSet<PhylogenyNode>();
11236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11240             if ( s0.match( query_nodes ) ) {
11241                 return false;
11242             }
11243             //
11244             query_nodes = new HashSet<PhylogenyNode>();
11245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11249             if ( s0.match( query_nodes ) ) {
11250                 return false;
11251             }
11252             //
11253             query_nodes = new HashSet<PhylogenyNode>();
11254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11257             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11258             if ( s0.match( query_nodes ) ) {
11259                 return false;
11260             }
11261             //
11262             query_nodes = new HashSet<PhylogenyNode>();
11263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11267             if ( s0.match( query_nodes ) ) {
11268                 return false;
11269             }
11270             //
11271             query_nodes = new HashSet<PhylogenyNode>();
11272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11276             if ( s0.match( query_nodes ) ) {
11277                 return false;
11278             }
11279             //
11280             query_nodes = new HashSet<PhylogenyNode>();
11281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11284             if ( s0.match( query_nodes ) ) {
11285                 return false;
11286             }
11287             //
11288             query_nodes = new HashSet<PhylogenyNode>();
11289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11294             if ( s0.match( query_nodes ) ) {
11295                 return false;
11296             }
11297             //
11298             query_nodes = new HashSet<PhylogenyNode>();
11299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11304             if ( s0.match( query_nodes ) ) {
11305                 return false;
11306             }
11307             //
11308             query_nodes = new HashSet<PhylogenyNode>();
11309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11314             if ( s0.match( query_nodes ) ) {
11315                 return false;
11316             }
11317             //
11318             query_nodes = new HashSet<PhylogenyNode>();
11319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11325             if ( s0.match( query_nodes ) ) {
11326                 return false;
11327             }
11328         }
11329         catch ( final Exception e ) {
11330             e.printStackTrace();
11331             return false;
11332         }
11333         return true;
11334     }
11335
11336     private static boolean testSplitStrict() {
11337         try {
11338             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11339             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11340             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11341             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11342             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11343             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11344             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11345             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11346             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11347             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11348             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11349             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11352             if ( s0.match( query_nodes ) ) {
11353                 return false;
11354             }
11355             query_nodes = new HashSet<PhylogenyNode>();
11356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11363             if ( !s0.match( query_nodes ) ) {
11364                 return false;
11365             }
11366             //
11367             query_nodes = new HashSet<PhylogenyNode>();
11368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11371             if ( !s0.match( query_nodes ) ) {
11372                 return false;
11373             }
11374             //
11375             query_nodes = new HashSet<PhylogenyNode>();
11376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11380             if ( !s0.match( query_nodes ) ) {
11381                 return false;
11382             }
11383             //
11384             query_nodes = new HashSet<PhylogenyNode>();
11385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11389             if ( !s0.match( query_nodes ) ) {
11390                 return false;
11391             }
11392             //
11393             query_nodes = new HashSet<PhylogenyNode>();
11394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11397             if ( !s0.match( query_nodes ) ) {
11398                 return false;
11399             }
11400             //
11401             query_nodes = new HashSet<PhylogenyNode>();
11402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11404             if ( !s0.match( query_nodes ) ) {
11405                 return false;
11406             }
11407             //
11408             query_nodes = new HashSet<PhylogenyNode>();
11409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11414             if ( !s0.match( query_nodes ) ) {
11415                 return false;
11416             }
11417             //
11418             query_nodes = new HashSet<PhylogenyNode>();
11419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11422             if ( !s0.match( query_nodes ) ) {
11423                 return false;
11424             }
11425             //
11426             query_nodes = new HashSet<PhylogenyNode>();
11427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11431             if ( !s0.match( query_nodes ) ) {
11432                 return false;
11433             }
11434             //
11435             query_nodes = new HashSet<PhylogenyNode>();
11436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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( "E" ) );
11445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11447             if ( s0.match( query_nodes ) ) {
11448                 return false;
11449             }
11450             //
11451             query_nodes = new HashSet<PhylogenyNode>();
11452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11457             if ( s0.match( query_nodes ) ) {
11458                 return false;
11459             }
11460             //
11461             query_nodes = new HashSet<PhylogenyNode>();
11462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11465             if ( s0.match( query_nodes ) ) {
11466                 return false;
11467             }
11468             //
11469             query_nodes = new HashSet<PhylogenyNode>();
11470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11472             if ( s0.match( query_nodes ) ) {
11473                 return false;
11474             }
11475             //
11476             query_nodes = new HashSet<PhylogenyNode>();
11477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11479             if ( s0.match( query_nodes ) ) {
11480                 return false;
11481             }
11482             //
11483             query_nodes = new HashSet<PhylogenyNode>();
11484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11486             if ( s0.match( query_nodes ) ) {
11487                 return false;
11488             }
11489             //
11490             query_nodes = new HashSet<PhylogenyNode>();
11491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11493             if ( s0.match( query_nodes ) ) {
11494                 return false;
11495             }
11496             //
11497             query_nodes = new HashSet<PhylogenyNode>();
11498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11500             if ( s0.match( query_nodes ) ) {
11501                 return false;
11502             }
11503             //
11504             query_nodes = new HashSet<PhylogenyNode>();
11505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11507             if ( s0.match( query_nodes ) ) {
11508                 return false;
11509             }
11510             //
11511             query_nodes = new HashSet<PhylogenyNode>();
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11515             if ( s0.match( query_nodes ) ) {
11516                 return false;
11517             }
11518             //
11519             query_nodes = new HashSet<PhylogenyNode>();
11520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11523             if ( s0.match( query_nodes ) ) {
11524                 return false;
11525             }
11526             //
11527             query_nodes = new HashSet<PhylogenyNode>();
11528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11531             if ( s0.match( query_nodes ) ) {
11532                 return false;
11533             }
11534             //
11535             query_nodes = new HashSet<PhylogenyNode>();
11536             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11540             if ( s0.match( query_nodes ) ) {
11541                 return false;
11542             }
11543         }
11544         catch ( final Exception e ) {
11545             e.printStackTrace();
11546             return false;
11547         }
11548         return true;
11549     }
11550
11551     private static boolean testSubtreeDeletion() {
11552         try {
11553             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11554             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11555             t1.deleteSubtree( t1.getNode( "A" ), false );
11556             if ( t1.getNumberOfExternalNodes() != 5 ) {
11557                 return false;
11558             }
11559             t1.toNewHampshireX();
11560             t1.deleteSubtree( t1.getNode( "E" ), false );
11561             if ( t1.getNumberOfExternalNodes() != 4 ) {
11562                 return false;
11563             }
11564             t1.toNewHampshireX();
11565             t1.deleteSubtree( t1.getNode( "F" ), false );
11566             if ( t1.getNumberOfExternalNodes() != 3 ) {
11567                 return false;
11568             }
11569             t1.toNewHampshireX();
11570             t1.deleteSubtree( t1.getNode( "D" ), false );
11571             t1.toNewHampshireX();
11572             if ( t1.getNumberOfExternalNodes() != 3 ) {
11573                 return false;
11574             }
11575             t1.deleteSubtree( t1.getNode( "def" ), false );
11576             t1.toNewHampshireX();
11577             if ( t1.getNumberOfExternalNodes() != 2 ) {
11578                 return false;
11579             }
11580             t1.deleteSubtree( t1.getNode( "B" ), false );
11581             t1.toNewHampshireX();
11582             if ( t1.getNumberOfExternalNodes() != 1 ) {
11583                 return false;
11584             }
11585             t1.deleteSubtree( t1.getNode( "C" ), false );
11586             t1.toNewHampshireX();
11587             if ( t1.getNumberOfExternalNodes() != 1 ) {
11588                 return false;
11589             }
11590             t1.deleteSubtree( t1.getNode( "abc" ), false );
11591             t1.toNewHampshireX();
11592             if ( t1.getNumberOfExternalNodes() != 1 ) {
11593                 return false;
11594             }
11595             t1.deleteSubtree( t1.getNode( "r" ), false );
11596             if ( t1.getNumberOfExternalNodes() != 0 ) {
11597                 return false;
11598             }
11599             if ( !t1.isEmpty() ) {
11600                 return false;
11601             }
11602             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11603             t2.deleteSubtree( t2.getNode( "A" ), false );
11604             t2.toNewHampshireX();
11605             if ( t2.getNumberOfExternalNodes() != 5 ) {
11606                 return false;
11607             }
11608             t2.deleteSubtree( t2.getNode( "abc" ), false );
11609             t2.toNewHampshireX();
11610             if ( t2.getNumberOfExternalNodes() != 3 ) {
11611                 return false;
11612             }
11613             t2.deleteSubtree( t2.getNode( "def" ), false );
11614             t2.toNewHampshireX();
11615             if ( t2.getNumberOfExternalNodes() != 1 ) {
11616                 return false;
11617             }
11618         }
11619         catch ( final Exception e ) {
11620             e.printStackTrace( System.out );
11621             return false;
11622         }
11623         return true;
11624     }
11625
11626     private static boolean testSupportCount() {
11627         try {
11628             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11629             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11630             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11631                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11632                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11633                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11634                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11635                                                               new NHXParser() );
11636             SupportCount.count( t0_1, phylogenies_1, true, false );
11637             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11638             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11639                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11640                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11641                                                                       + "(((((A,B),C),D),E),(F,G))"
11642                                                                       + "(((((A,B),C),D),E),(F,G))"
11643                                                                       + "(((((A,B),C),D),E),(F,G))"
11644                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11645                                                                       + "(((((A,B),C),D),E),(F,G))"
11646                                                                       + "((((((A,B),C),D),E),F),G)"
11647                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11648                                                               new NHXParser() );
11649             SupportCount.count( t0_2, phylogenies_2, true, false );
11650             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11651             while ( it.hasNext() ) {
11652                 final PhylogenyNode n = it.next();
11653                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11654                     return false;
11655                 }
11656             }
11657             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11658             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11659                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11660             SupportCount.count( t0_3, phylogenies_3, true, false );
11661             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11662             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11663                 return false;
11664             }
11665             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11666                 return false;
11667             }
11668             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11669                 return false;
11670             }
11671             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11672                 return false;
11673             }
11674             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11675                 return false;
11676             }
11677             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11678                 return false;
11679             }
11680             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11681                 return false;
11682             }
11683             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11684                 return false;
11685             }
11686             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11687                 return false;
11688             }
11689             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11690                 return false;
11691             }
11692             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11693             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11694                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11695             SupportCount.count( t0_4, phylogenies_4, true, false );
11696             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11697             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11698                 return false;
11699             }
11700             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11701                 return false;
11702             }
11703             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11704                 return false;
11705             }
11706             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11707                 return false;
11708             }
11709             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11710                 return false;
11711             }
11712             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11713                 return false;
11714             }
11715             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11716                 return false;
11717             }
11718             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11719                 return false;
11720             }
11721             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11722                 return false;
11723             }
11724             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11725                 return false;
11726             }
11727             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11728             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11729             double d = SupportCount.compare( b1, a, true, true, true );
11730             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11731                 return false;
11732             }
11733             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11734             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11735             d = SupportCount.compare( b2, a, true, true, true );
11736             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11737                 return false;
11738             }
11739             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11740             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11741             d = SupportCount.compare( b3, a, true, true, true );
11742             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11743                 return false;
11744             }
11745             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11746             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11747             d = SupportCount.compare( b4, a, true, true, false );
11748             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11749                 return false;
11750             }
11751         }
11752         catch ( final Exception e ) {
11753             e.printStackTrace( System.out );
11754             return false;
11755         }
11756         return true;
11757     }
11758
11759     private static boolean testSupportTransfer() {
11760         try {
11761             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11762             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)",
11763                                                  new NHXParser() )[ 0 ];
11764             final Phylogeny p2 = factory
11765                     .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 ];
11766             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11767                 return false;
11768             }
11769             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11770                 return false;
11771             }
11772             support_transfer.moveBranchLengthsToBootstrap( p1 );
11773             support_transfer.transferSupportValues( p1, p2 );
11774             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11775                 return false;
11776             }
11777             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11778                 return false;
11779             }
11780             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11781                 return false;
11782             }
11783             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11784                 return false;
11785             }
11786             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11787                 return false;
11788             }
11789             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11790                 return false;
11791             }
11792             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11793                 return false;
11794             }
11795             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11796                 return false;
11797             }
11798         }
11799         catch ( final Exception e ) {
11800             e.printStackTrace( System.out );
11801             return false;
11802         }
11803         return true;
11804     }
11805
11806     private static boolean testTaxonomyExtraction() {
11807         try {
11808             final PhylogenyNode n0 = PhylogenyNode
11809                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11810             if ( n0.getNodeData().isHasTaxonomy() ) {
11811                 return false;
11812             }
11813             final PhylogenyNode n1 = PhylogenyNode
11814                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11815             if ( n1.getNodeData().isHasTaxonomy() ) {
11816                 System.out.println( n1.toString() );
11817                 return false;
11818             }
11819             final PhylogenyNode n2x = PhylogenyNode
11820                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11821             if ( n2x.getNodeData().isHasTaxonomy() ) {
11822                 return false;
11823             }
11824             final PhylogenyNode n3 = PhylogenyNode
11825                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11826             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11827                 System.out.println( n3.toString() );
11828                 return false;
11829             }
11830             final PhylogenyNode n4 = PhylogenyNode
11831                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11832             if ( n4.getNodeData().isHasTaxonomy() ) {
11833                 System.out.println( n4.toString() );
11834                 return false;
11835             }
11836             final PhylogenyNode n5 = PhylogenyNode
11837                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11838             if ( n5.getNodeData().isHasTaxonomy() ) {
11839                 System.out.println( n5.toString() );
11840                 return false;
11841             }
11842             final PhylogenyNode n6 = PhylogenyNode
11843                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11844             if ( n6.getNodeData().isHasTaxonomy() ) {
11845                 System.out.println( n6.toString() );
11846                 return false;
11847             }
11848             final PhylogenyNode n7 = PhylogenyNode
11849                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11850             if ( n7.getNodeData().isHasTaxonomy() ) {
11851                 System.out.println( n7.toString() );
11852                 return false;
11853             }
11854             final PhylogenyNode n8 = PhylogenyNode
11855                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11856             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11857                 System.out.println( n8.toString() );
11858                 return false;
11859             }
11860             final PhylogenyNode n9 = PhylogenyNode
11861                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11862             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11863                 System.out.println( n9.toString() );
11864                 return false;
11865             }
11866             final PhylogenyNode n10x = PhylogenyNode
11867                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11868             if ( n10x.getNodeData().isHasTaxonomy() ) {
11869                 System.out.println( n10x.toString() );
11870                 return false;
11871             }
11872             final PhylogenyNode n10xx = PhylogenyNode
11873                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11874             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11875                 System.out.println( n10xx.toString() );
11876                 return false;
11877             }
11878             final PhylogenyNode n10 = PhylogenyNode
11879                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11880             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11881                 System.out.println( n10.toString() );
11882                 return false;
11883             }
11884             final PhylogenyNode n11 = PhylogenyNode
11885                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11886             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11887                 System.out.println( n11.toString() );
11888                 return false;
11889             }
11890             final PhylogenyNode n12 = PhylogenyNode
11891                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11892                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11893             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11894                 System.out.println( n12.toString() );
11895                 return false;
11896             }
11897             final PhylogenyNode n13 = PhylogenyNode
11898                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11899             if ( n13.getNodeData().isHasTaxonomy() ) {
11900                 System.out.println( n13.toString() );
11901                 return false;
11902             }
11903             final PhylogenyNode n14 = PhylogenyNode
11904                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11905             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11906                 System.out.println( n14.toString() );
11907                 return false;
11908             }
11909             final PhylogenyNode n15 = PhylogenyNode
11910                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11911             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11912                 System.out.println( n15.toString() );
11913                 return false;
11914             }
11915             final PhylogenyNode n16 = PhylogenyNode
11916                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11917             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11918                 System.out.println( n16.toString() );
11919                 return false;
11920             }
11921             final PhylogenyNode n17 = PhylogenyNode
11922                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11923             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11924                 System.out.println( n17.toString() );
11925                 return false;
11926             }
11927             //
11928             final PhylogenyNode n18 = PhylogenyNode
11929                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11930             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11931                 System.out.println( n18.toString() );
11932                 return false;
11933             }
11934             final PhylogenyNode n19 = PhylogenyNode
11935                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
11936                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11937             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11938                 System.out.println( n19.toString() );
11939                 return false;
11940             }
11941             final PhylogenyNode n20 = PhylogenyNode
11942                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11943             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11944                 System.out.println( n20.toString() );
11945                 return false;
11946             }
11947             final PhylogenyNode n21 = PhylogenyNode
11948                     .createInstanceFromNhxString( "Mus musculus musculus K392",
11949                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11950             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11951                 System.out.println( n21.toString() );
11952                 return false;
11953             }
11954         }
11955         catch ( final Exception e ) {
11956             e.printStackTrace( System.out );
11957             return false;
11958         }
11959         return true;
11960     }
11961
11962     private static boolean testTreeCopy() {
11963         try {
11964             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
11965             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
11966             final Phylogeny t1 = t0.copy();
11967             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
11968                 return false;
11969             }
11970             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11971                 return false;
11972             }
11973             t0.deleteSubtree( t0.getNode( "c" ), true );
11974             t0.deleteSubtree( t0.getNode( "a" ), true );
11975             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
11976             t0.getNode( "b" ).setName( "Bee" );
11977             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
11978                 return false;
11979             }
11980             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11981                 return false;
11982             }
11983             t0.deleteSubtree( t0.getNode( "e" ), true );
11984             t0.deleteSubtree( t0.getNode( "Bee" ), true );
11985             t0.deleteSubtree( t0.getNode( "d" ), true );
11986             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11987                 return false;
11988             }
11989         }
11990         catch ( final Exception e ) {
11991             e.printStackTrace();
11992             return false;
11993         }
11994         return true;
11995     }
11996
11997     private static boolean testTreeMethods() {
11998         try {
11999             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12000             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12001             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12002             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12003                 System.out.println( t0.toNewHampshireX() );
12004                 return false;
12005             }
12006             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12007             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12008             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12009                 return false;
12010             }
12011             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12012                 return false;
12013             }
12014             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12015                 return false;
12016             }
12017         }
12018         catch ( final Exception e ) {
12019             e.printStackTrace( System.out );
12020             return false;
12021         }
12022         return true;
12023     }
12024
12025     private static boolean testUniprotEntryRetrieval() {
12026         try {
12027             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12028             if ( !entry.getAccession().equals( "P12345" ) ) {
12029                 return false;
12030             }
12031             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12032                 return false;
12033             }
12034             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12035                 return false;
12036             }
12037             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12038                 return false;
12039             }
12040             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12041                 return false;
12042             }
12043             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12044                 return false;
12045             }
12046         }
12047         catch ( final IOException e ) {
12048             System.out.println();
12049             System.out.println( "the following might be due to absence internet connection:" );
12050             e.printStackTrace( System.out );
12051             return true;
12052         }
12053         catch ( final Exception e ) {
12054             return false;
12055         }
12056         return true;
12057     }
12058
12059     private static boolean testUniprotTaxonomySearch() {
12060         try {
12061             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12062                                                                                                  10 );
12063             if ( results.size() != 1 ) {
12064                 return false;
12065             }
12066             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12067                 return false;
12068             }
12069             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12070                 return false;
12071             }
12072             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12073                 return false;
12074             }
12075             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12076                 return false;
12077             }
12078             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12079                 return false;
12080             }
12081             results = null;
12082             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12083             if ( results.size() != 1 ) {
12084                 return false;
12085             }
12086             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12087                 return false;
12088             }
12089             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12090                 return false;
12091             }
12092             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12093                 return false;
12094             }
12095             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12096                 return false;
12097             }
12098             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12099                 return false;
12100             }
12101             results = null;
12102             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12103             if ( results.size() != 1 ) {
12104                 return false;
12105             }
12106             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12107                 return false;
12108             }
12109             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12110                 return false;
12111             }
12112             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12113                 return false;
12114             }
12115             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12116                 return false;
12117             }
12118             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12119                 return false;
12120             }
12121             results = null;
12122             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12123             if ( results.size() != 1 ) {
12124                 return false;
12125             }
12126             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12127                 return false;
12128             }
12129             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12130                 return false;
12131             }
12132             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12133                 return false;
12134             }
12135             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12136                 return false;
12137             }
12138             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12139                 return false;
12140             }
12141             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12142                 return false;
12143             }
12144             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12145                 return false;
12146             }
12147             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12148                     .equals( "Nematostella vectensis" ) ) {
12149                 System.out.println( results.get( 0 ).getLineage() );
12150                 return false;
12151             }
12152             //
12153             results = null;
12154             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12155             if ( results.size() != 1 ) {
12156                 return false;
12157             }
12158             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12159                 return false;
12160             }
12161             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12162                 return false;
12163             }
12164             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12165                 return false;
12166             }
12167             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12168                 return false;
12169             }
12170             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12171                 return false;
12172             }
12173             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12174                     .equals( "Xenopus tropicalis" ) ) {
12175                 System.out.println( results.get( 0 ).getLineage() );
12176                 return false;
12177             }
12178             //
12179             results = null;
12180             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12181             if ( results.size() != 1 ) {
12182                 return false;
12183             }
12184             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12185                 return false;
12186             }
12187             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12188                 return false;
12189             }
12190             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12191                 return false;
12192             }
12193             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12194                 return false;
12195             }
12196             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12197                 return false;
12198             }
12199             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12200                     .equals( "Xenopus tropicalis" ) ) {
12201                 System.out.println( results.get( 0 ).getLineage() );
12202                 return false;
12203             }
12204             //
12205             results = null;
12206             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12207             if ( results.size() != 1 ) {
12208                 return false;
12209             }
12210             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12211                 return false;
12212             }
12213             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12214                 return false;
12215             }
12216             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12217                 return false;
12218             }
12219             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12220                 return false;
12221             }
12222             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12223                 return false;
12224             }
12225             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12226                     .equals( "Xenopus tropicalis" ) ) {
12227                 System.out.println( results.get( 0 ).getLineage() );
12228                 return false;
12229             }
12230         }
12231         catch ( final IOException e ) {
12232             System.out.println();
12233             System.out.println( "the following might be due to absence internet connection:" );
12234             e.printStackTrace( System.out );
12235             return true;
12236         }
12237         catch ( final Exception e ) {
12238             return false;
12239         }
12240         return true;
12241     }
12242
12243     private static boolean testWabiTxSearch() {
12244         try {
12245             String result = "";
12246             result = TxSearch.searchSimple( "nematostella" );
12247             result = TxSearch.getTxId( "nematostella" );
12248             if ( !result.equals( "45350" ) ) {
12249                 return false;
12250             }
12251             result = TxSearch.getTxName( "45350" );
12252             if ( !result.equals( "Nematostella" ) ) {
12253                 return false;
12254             }
12255             result = TxSearch.getTxId( "nematostella vectensis" );
12256             if ( !result.equals( "45351" ) ) {
12257                 return false;
12258             }
12259             result = TxSearch.getTxName( "45351" );
12260             if ( !result.equals( "Nematostella vectensis" ) ) {
12261                 return false;
12262             }
12263             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12264             if ( !result.equals( "536089" ) ) {
12265                 return false;
12266             }
12267             result = TxSearch.getTxName( "536089" );
12268             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12269                 return false;
12270             }
12271             final List<String> queries = new ArrayList<String>();
12272             queries.add( "Campylobacter coli" );
12273             queries.add( "Escherichia coli" );
12274             queries.add( "Arabidopsis" );
12275             queries.add( "Trichoplax" );
12276             queries.add( "Samanea saman" );
12277             queries.add( "Kluyveromyces marxianus" );
12278             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12279             queries.add( "Bornavirus parrot/PDD/2008" );
12280             final List<RANKS> ranks = new ArrayList<RANKS>();
12281             ranks.add( RANKS.SUPERKINGDOM );
12282             ranks.add( RANKS.KINGDOM );
12283             ranks.add( RANKS.FAMILY );
12284             ranks.add( RANKS.GENUS );
12285             ranks.add( RANKS.TRIBE );
12286             result = TxSearch.searchLineage( queries, ranks );
12287             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12288             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12289         }
12290         catch ( final Exception e ) {
12291             System.out.println();
12292             System.out.println( "the following might be due to absence internet connection:" );
12293             e.printStackTrace( System.out );
12294             return false;
12295         }
12296         return true;
12297     }
12298 }