5864f613fb7646998751832cab65a30ca980f8b2
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesMap;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.Sequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128 import org.forester.ws.wabi.TxSearch;
129 import org.forester.ws.wabi.TxSearch.RANKS;
130 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
131 import org.forester.ws.wabi.TxSearch.TAX_RANK;
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137                                                                    + ForesterUtil.getFileSeparator() + "resources"
138                                                                    + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140                                                                    + ForesterUtil.getFileSeparator() + "test_data"
141                                                                    + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = false;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
146                                                                    + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
149                                                                    + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     public static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                 + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         System.out.print( "MSA entropy: " );
185         if ( Test.testMsaEntropy() ) {
186             System.out.println( "OK." );
187             succeeded++;
188         }
189         else {
190             System.out.println( "failed." );
191             failed++;
192         }
193         System.out.print( "Basic node methods: " );
194         if ( Test.testBasicNodeMethods() ) {
195             System.out.println( "OK." );
196             succeeded++;
197         }
198         else {
199             System.out.println( "failed." );
200             failed++;
201         }
202         System.out.print( "Protein id: " );
203         if ( !testProteinId() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Species: " );
212         if ( !testSpecies() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Basic domain: " );
221         if ( !testBasicDomain() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Basic protein: " );
230         if ( !testBasicProtein() ) {
231             System.out.println( "failed." );
232             failed++;
233         }
234         else {
235             succeeded++;
236         }
237         System.out.println( "OK." );
238         System.out.print( "Sequence writer: " );
239         if ( testSequenceWriter() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "Sequence id parsing: " );
248         if ( testSequenceIdParsing() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "UniProtKB id extraction: " );
257         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Sequence DB tools 1: " );
266         if ( testSequenceDbWsTools1() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Hmmscan output parser: " );
275         if ( testHmmscanOutputParser() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "Overlap removal: " );
284         if ( !org.forester.test.Test.testOverlapRemoval() ) {
285             System.out.println( "failed." );
286             failed++;
287         }
288         else {
289             succeeded++;
290         }
291         System.out.println( "OK." );
292         System.out.print( "Engulfing overlap removal: " );
293         if ( !Test.testEngulfingOverlapRemoval() ) {
294             System.out.println( "failed." );
295             failed++;
296         }
297         else {
298             succeeded++;
299         }
300         System.out.println( "OK." );
301         System.out.print( "Taxonomy code extraction: " );
302         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "SN extraction: " );
311         if ( Test.testExtractSNFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy extraction (general): " );
320         if ( Test.testTaxonomyExtraction() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Uri for Aptx web sequence accession: " );
329         if ( Test.testCreateUriForSeqWeb() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Basic node construction and parsing of NHX (node level): " );
338         if ( Test.testNHXNodeParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing iterating: " );
347         if ( Test.testNHParsingIter() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NH parsing: " );
356         if ( Test.testNHParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Conversion to NHX (node level): " );
365         if ( Test.testNHXconversion() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NHX parsing: " );
374         if ( Test.testNHXParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing with quotes: " );
383         if ( Test.testNHXParsingQuotes() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing (MrBayes): " );
392         if ( Test.testNHXParsingMB() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus characters parsing: " );
401         if ( Test.testNexusCharactersParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus tree parsing iterating: " );
410         if ( Test.testNexusTreeParsingIterating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus tree parsing: " );
419         if ( Test.testNexusTreeParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing (translating): " );
428         if ( Test.testNexusTreeParsingTranslating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus matrix parsing: " );
437         if ( Test.testNexusMatrixParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Basic phyloXML parsing: " );
446         if ( Test.testBasicPhyloXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic phyloXML parsing (validating against schema): " );
455         if ( testBasicPhyloXMLparsingValidating() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
464         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "phyloXML Distribution Element: " );
473         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Tol XML parsing: " );
482         if ( Test.testBasicTolXMLparsing() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Copying of node data: " );
491         if ( Test.testCopyOfNodeData() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tree copy: " );
500         if ( Test.testTreeCopy() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Basic tree methods: " );
509         if ( Test.testBasicTreeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree methods: " );
518         if ( Test.testTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Postorder Iterator: " );
527         if ( Test.testPostOrderIterator() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Preorder Iterator: " );
536         if ( Test.testPreOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Levelorder Iterator: " );
545         if ( Test.testLevelOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Re-id methods: " );
554         if ( Test.testReIdMethods() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Methods on last external nodes: " );
563         if ( Test.testLastExternalNodeMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on external nodes: " );
572         if ( Test.testExternalNodeRelatedMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Deletion of external nodes: " );
581         if ( Test.testDeletionOfExternalNodes() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Subtree deletion: " );
590         if ( Test.testSubtreeDeletion() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Phylogeny branch: " );
599         if ( Test.testPhylogenyBranch() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Rerooting: " );
608         if ( Test.testRerooting() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Mipoint rooting: " );
617         if ( Test.testMidpointrooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Node removal: " );
626         if ( Test.testNodeRemoval() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Support count: " );
635         if ( Test.testSupportCount() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support transfer: " );
644         if ( Test.testSupportTransfer() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Finding of LCA: " );
653         if ( Test.testGetLCA() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Finding of LCA 2: " );
662         if ( Test.testGetLCA2() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Calculation of distance between nodes: " );
671         if ( Test.testGetDistance() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Descriptive statistics: " );
680         if ( Test.testDescriptiveStatistics() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Data objects and methods: " );
689         if ( Test.testDataObjects() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Properties map: " );
698         if ( Test.testPropertiesMap() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "SDIse: " );
707         if ( Test.testSDIse() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIunrooted: " );
716         if ( Test.testSDIunrooted() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "GSDI: " );
725         if ( TestGSDI.test() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "RIO: " );
734         if ( TestRIO.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Phylogeny reconstruction:" );
743         System.out.println();
744         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "Analysis of domain architectures: " );
753         System.out.println();
754         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "GO: " );
763         System.out.println();
764         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Modeling tools: " );
773         if ( TestPccx.test() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Split Matrix strict: " );
782         if ( Test.testSplitStrict() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix: " );
791         if ( Test.testSplit() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Confidence Assessor: " );
800         if ( Test.testConfidenceAssessor() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Basic table: " );
809         if ( Test.testBasicTable() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "General table: " );
818         if ( Test.testGeneralTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Amino acid sequence: " );
827         if ( Test.testAminoAcidSequence() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General MSA parser: " );
836         if ( Test.testGeneralMsaParser() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Fasta parser for msa: " );
845         if ( Test.testFastaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Creation of balanced phylogeny: " );
854         if ( Test.testCreateBalancedPhylogeny() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Genbank accessor parsing: " );
863         if ( Test.testGenbankAccessorParsing() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         String path = "";
872         final String os = ForesterUtil.OS_NAME.toLowerCase();
873         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
874             path = "/usr/local/bin/mafft";
875         }
876         else if ( os.indexOf( "win" ) >= 0 ) {
877             path = "C:\\Program Files\\mafft-win\\mafft.bat";
878         }
879         else {
880             path = "mafft";
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/bin/mafft";
883             }
884             if ( !MsaInferrer.isInstalled( path ) ) {
885                 path = "/usr/local/bin/mafft";
886             }
887         }
888         if ( MsaInferrer.isInstalled( path ) ) {
889             System.out.print( "MAFFT (external program): " );
890             if ( Test.testMafft( path ) ) {
891                 System.out.println( "OK." );
892                 succeeded++;
893             }
894             else {
895                 System.out.println( "failed [will not count towards failed tests]" );
896             }
897         }
898         System.out.print( "Next nodes with collapsed: " );
899         if ( Test.testNextNodeWithCollapsing() ) {
900             System.out.println( "OK." );
901             succeeded++;
902         }
903         else {
904             System.out.println( "failed." );
905             failed++;
906         }
907         System.out.print( "Simple MSA quality: " );
908         if ( Test.testMsaQualityMethod() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Deleteable MSA: " );
917         if ( Test.testDeleteableMsa() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         if ( PERFORM_DB_TESTS ) {
926             System.out.print( "Uniprot Entry Retrieval: " );
927             if ( Test.testUniprotEntryRetrieval() ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed." );
933                 failed++;
934             }
935             System.out.print( "Ebi Entry Retrieval: " );
936             if ( Test.testEbiEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Sequence DB tools 2: " );
945             if ( testSequenceDbWsTools2() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952                 System.exit( -1 );
953             }
954             System.out.print( "Uniprot Taxonomy Search: " );
955             if ( Test.testUniprotTaxonomySearch() ) {
956                 System.out.println( "OK." );
957                 succeeded++;
958             }
959             else {
960                 System.out.println( "failed." );
961                 failed++;
962             }
963         }
964         if ( PERFORM_WEB_TREE_ACCESS ) {
965             System.out.print( "NHX parsing from URL: " );
966             if ( Test.testNHXparsingFromURL() ) {
967                 System.out.println( "OK." );
968                 succeeded++;
969             }
970             else {
971                 System.out.println( "failed." );
972                 failed++;
973             }
974             System.out.print( "NHX parsing from URL 2: " );
975             if ( Test.testNHXparsingFromURL2() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "phyloXML parsing from URL: " );
984             if ( Test.testPhyloXMLparsingFromURL() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             System.out.print( "TreeBase acccess: " );
993             if ( Test.testTreeBaseReading() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             //
1002             System.out.print( "ToL access: " );
1003             if ( Test.testToLReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             //
1012             System.out.print( "TreeFam access: " );
1013             if ( Test.testTreeFamReading() ) {
1014                 System.out.println( "OK." );
1015                 succeeded++;
1016             }
1017             else {
1018                 System.out.println( "failed." );
1019                 failed++;
1020             }
1021             //
1022             //
1023             System.out.print( "Pfam tree access: " );
1024             if ( Test.testPfamTreeReading() ) {
1025                 System.out.println( "OK." );
1026                 succeeded++;
1027             }
1028             else {
1029                 System.out.println( "failed." );
1030                 failed++;
1031             }
1032         }
1033         System.out.println();
1034         final Runtime rt = java.lang.Runtime.getRuntime();
1035         final long free_memory = rt.freeMemory() / 1000000;
1036         final long total_memory = rt.totalMemory() / 1000000;
1037         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1038                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1039         System.out.println();
1040         System.out.println( "Successful tests: " + succeeded );
1041         System.out.println( "Failed     tests: " + failed );
1042         System.out.println();
1043         if ( failed < 1 ) {
1044             System.out.println( "OK." );
1045         }
1046         else {
1047             System.out.println( "Not OK." );
1048         }
1049     }
1050
1051     public static boolean testEngulfingOverlapRemoval() {
1052         try {
1053             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1054             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1055             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1056             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1057             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1058             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1059             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1060             final List<Boolean> covered = new ArrayList<Boolean>();
1061             covered.add( true ); // 0
1062             covered.add( false ); // 1
1063             covered.add( true ); // 2
1064             covered.add( false ); // 3
1065             covered.add( true ); // 4
1066             covered.add( true ); // 5
1067             covered.add( false ); // 6
1068             covered.add( true ); // 7
1069             covered.add( true ); // 8
1070             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1071                 return false;
1072             }
1073             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1074                 return false;
1075             }
1076             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1077                 return false;
1078             }
1079             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1086                 return false;
1087             }
1088             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1089                 return false;
1090             }
1091             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1092             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1093             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1094             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1095             abc.addProteinDomain( a );
1096             abc.addProteinDomain( b );
1097             abc.addProteinDomain( c );
1098             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1099             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1100             if ( abc.getNumberOfProteinDomains() != 3 ) {
1101                 return false;
1102             }
1103             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1104                 return false;
1105             }
1106             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1107                 return false;
1108             }
1109             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1110                 return false;
1111             }
1112             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1113                 return false;
1114             }
1115             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1116             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1117             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1118             final Protein def = new BasicProtein( "def", "nemve", 0 );
1119             def.addProteinDomain( d );
1120             def.addProteinDomain( e );
1121             def.addProteinDomain( f );
1122             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1123             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1124             if ( def.getNumberOfProteinDomains() != 3 ) {
1125                 return false;
1126             }
1127             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1128                 return false;
1129             }
1130             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1131                 return false;
1132             }
1133             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1134                 return false;
1135             }
1136             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1137                 return false;
1138             }
1139             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1140                 return false;
1141             }
1142         }
1143         catch ( final Exception e ) {
1144             e.printStackTrace( System.out );
1145             return false;
1146         }
1147         return true;
1148     }
1149
1150     public static final boolean testNHXparsingFromURL2() {
1151         try {
1152             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1153             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1154                                                                       false,
1155                                                                       false,
1156                                                                       false,
1157                                                                       TAXONOMY_EXTRACTION.NO,
1158                                                                       false );
1159             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1160                 return false;
1161             }
1162             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1163                 System.out.println( phys[ 0 ].toNewHampshire() );
1164                 return false;
1165             }
1166             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1167                 System.out.println( phys[ 1 ].toNewHampshire() );
1168                 return false;
1169             }
1170             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1171                                                                        false,
1172                                                                        false,
1173                                                                        false,
1174                                                                        TAXONOMY_EXTRACTION.NO,
1175                                                                        false );
1176             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1177                 return false;
1178             }
1179             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1180                 System.out.println( phys2[ 0 ].toNewHampshire() );
1181                 return false;
1182             }
1183             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1184                 System.out.println( phys2[ 1 ].toNewHampshire() );
1185                 return false;
1186             }
1187             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1188                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1189             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1190                 return false;
1191             }
1192             if ( !phys3[ 0 ]
1193                     .toNewHampshire()
1194                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1195                 System.out.println( phys3[ 0 ].toNewHampshire() );
1196                 return false;
1197             }
1198             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1199                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1200             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1201                 return false;
1202             }
1203             if ( !phys4[ 0 ]
1204                     .toNewHampshire()
1205                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1206                 System.out.println( phys4[ 0 ].toNewHampshire() );
1207                 return false;
1208             }
1209         }
1210         catch ( final Exception e ) {
1211             e.printStackTrace();
1212         }
1213         return true;
1214     }
1215
1216     public static final boolean testNHXparsingFromURL() {
1217         try {
1218             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1219             final URL u = new URL( s );
1220             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1221             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1222             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1223                 return false;
1224             }
1225             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1226                 System.out.println( phys[ 0 ].toNewHampshire() );
1227                 return false;
1228             }
1229             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1230                 System.out.println( phys[ 1 ].toNewHampshire() );
1231                 return false;
1232             }
1233             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1234             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1235                 return false;
1236             }
1237             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1238                 System.out.println( phys2[ 0 ].toNewHampshire() );
1239                 return false;
1240             }
1241             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1242             final NHXParser p = new NHXParser();
1243             final URL u2 = new URL( s );
1244             p.setSource( u2 );
1245             if ( !p.hasNext() ) {
1246                 return false;
1247             }
1248             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1249                 return false;
1250             }
1251             if ( !p.hasNext() ) {
1252                 return false;
1253             }
1254             p.reset();
1255             if ( !p.hasNext() ) {
1256                 return false;
1257             }
1258             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1259                 return false;
1260             }
1261             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1262                 return false;
1263             }
1264             p.reset();
1265             if ( !p.hasNext() ) {
1266                 return false;
1267             }
1268             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1269                 return false;
1270             }
1271             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1272                 return false;
1273             }
1274         }
1275         catch ( final Exception e ) {
1276             e.printStackTrace();
1277         }
1278         return true;
1279     }
1280
1281     public static boolean testOverlapRemoval() {
1282         try {
1283             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1284             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1285             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1286             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1287             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1288             final List<Boolean> covered = new ArrayList<Boolean>();
1289             covered.add( true ); // 0
1290             covered.add( false ); // 1
1291             covered.add( true ); // 2
1292             covered.add( false ); // 3
1293             covered.add( true ); // 4
1294             covered.add( true ); // 5
1295             covered.add( false ); // 6
1296             covered.add( true ); // 7
1297             covered.add( true ); // 8
1298             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1299                 return false;
1300             }
1301             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1302                 return false;
1303             }
1304             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1305                 return false;
1306             }
1307             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1308                 return false;
1309             }
1310             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1311                 return false;
1312             }
1313             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1314             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1315             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1316             ab.addProteinDomain( a );
1317             ab.addProteinDomain( b );
1318             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1319             if ( ab.getNumberOfProteinDomains() != 2 ) {
1320                 return false;
1321             }
1322             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1323                 return false;
1324             }
1325             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1326                 return false;
1327             }
1328             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1329             if ( ab.getNumberOfProteinDomains() != 2 ) {
1330                 return false;
1331             }
1332             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1333                 return false;
1334             }
1335             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1336             final Domain d = new BasicDomain( "d",
1337                                               ( short ) 10000,
1338                                               ( short ) 10500,
1339                                               ( short ) 1,
1340                                               ( short ) 1,
1341                                               0.0000001,
1342                                               1 );
1343             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1344             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1345             cde.addProteinDomain( c );
1346             cde.addProteinDomain( d );
1347             cde.addProteinDomain( e );
1348             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1349             if ( cde.getNumberOfProteinDomains() != 3 ) {
1350                 return false;
1351             }
1352             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1353                 return false;
1354             }
1355             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1356             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1357             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1358             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1359             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1360             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1361             fghi.addProteinDomain( f );
1362             fghi.addProteinDomain( g );
1363             fghi.addProteinDomain( h );
1364             fghi.addProteinDomain( i );
1365             fghi.addProteinDomain( i );
1366             fghi.addProteinDomain( i );
1367             fghi.addProteinDomain( i2 );
1368             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1369             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1370                 return false;
1371             }
1372             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1373                 return false;
1374             }
1375             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1376                 return false;
1377             }
1378             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1379             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1380                 return false;
1381             }
1382             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1383                 return false;
1384             }
1385             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1386             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1387             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1388             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1389             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1390             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1391             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1392             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1393             jklm.addProteinDomain( j );
1394             jklm.addProteinDomain( k );
1395             jklm.addProteinDomain( l );
1396             jklm.addProteinDomain( m );
1397             jklm.addProteinDomain( m0 );
1398             jklm.addProteinDomain( m1 );
1399             jklm.addProteinDomain( m2 );
1400             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1401             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1402                 return false;
1403             }
1404             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1405                 return false;
1406             }
1407             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1408                 return false;
1409             }
1410             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1411             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1412                 return false;
1413             }
1414             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1415                 return false;
1416             }
1417             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1418             final Protein od = new BasicProtein( "od", "varanus", 0 );
1419             od.addProteinDomain( only );
1420             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1421             if ( od.getNumberOfProteinDomains() != 1 ) {
1422                 return false;
1423             }
1424             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1425                 return false;
1426             }
1427         }
1428         catch ( final Exception e ) {
1429             e.printStackTrace( System.out );
1430             return false;
1431         }
1432         return true;
1433     }
1434
1435     public static final boolean testPfamTreeReading() {
1436         try {
1437             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1438             final NHXParser parser = new NHXParser();
1439             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1440             parser.setReplaceUnderscores( false );
1441             parser.setGuessRootedness( true );
1442             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1443             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1444             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1445                 return false;
1446             }
1447             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1448                 return false;
1449             }
1450         }
1451         catch ( final Exception e ) {
1452             e.printStackTrace();
1453         }
1454         return true;
1455     }
1456
1457     public static final boolean testPhyloXMLparsingFromURL() {
1458         try {
1459             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1460             final URL u = new URL( s );
1461             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1462             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1463             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1464                 return false;
1465             }
1466         }
1467         catch ( final Exception e ) {
1468             e.printStackTrace();
1469         }
1470         return true;
1471     }
1472
1473     public static final boolean testToLReading() {
1474         try {
1475             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1476             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1477             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1478             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1479                 return false;
1480             }
1481             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1482                 return false;
1483             }
1484             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1485                 return false;
1486             }
1487             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1488                 return false;
1489             }
1490         }
1491         catch ( final Exception e ) {
1492             e.printStackTrace();
1493         }
1494         return true;
1495     }
1496
1497     public static final boolean testTreeBaseReading() {
1498         try {
1499             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1500             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1501             parser.setReplaceUnderscores( true );
1502             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1503             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1504             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1505                 return false;
1506             }
1507             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1508             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1509             parser2.setReplaceUnderscores( true );
1510             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1511             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1512             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1513                 return false;
1514             }
1515         }
1516         catch ( final Exception e ) {
1517             e.printStackTrace();
1518         }
1519         return true;
1520     }
1521
1522     public static final boolean testTreeFamReading() {
1523         try {
1524             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1525             final NHXParser parser = new NHXParser();
1526             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1527             parser.setReplaceUnderscores( false );
1528             parser.setGuessRootedness( true );
1529             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1530             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1531             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1532                 return false;
1533             }
1534             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1535                 return false;
1536             }
1537         }
1538         catch ( final Exception e ) {
1539             e.printStackTrace();
1540         }
1541         return true;
1542     }
1543
1544     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1545         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1546         return p;
1547     }
1548
1549     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1550         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1551     }
1552
1553     private static boolean testAminoAcidSequence() {
1554         try {
1555             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1556             if ( aa1.getLength() != 13 ) {
1557                 return false;
1558             }
1559             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1560                 return false;
1561             }
1562             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1563                 return false;
1564             }
1565             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1566                 return false;
1567             }
1568             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1569             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1570                 return false;
1571             }
1572             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1573             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1574                 return false;
1575             }
1576             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1577             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1578                 return false;
1579             }
1580         }
1581         catch ( final Exception e ) {
1582             e.printStackTrace();
1583             return false;
1584         }
1585         return true;
1586     }
1587
1588     private static boolean testBasicDomain() {
1589         try {
1590             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1591             if ( !pd.getDomainId().equals( "id" ) ) {
1592                 return false;
1593             }
1594             if ( pd.getNumber() != 1 ) {
1595                 return false;
1596             }
1597             if ( pd.getTotalCount() != 4 ) {
1598                 return false;
1599             }
1600             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1601                 return false;
1602             }
1603             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1604             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1605             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1606             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1607             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1608             if ( !a1.equals( a1 ) ) {
1609                 return false;
1610             }
1611             if ( !a1.equals( a1_copy ) ) {
1612                 return false;
1613             }
1614             if ( !a1.equals( a1_equal ) ) {
1615                 return false;
1616             }
1617             if ( !a1.equals( a2 ) ) {
1618                 return false;
1619             }
1620             if ( a1.equals( a3 ) ) {
1621                 return false;
1622             }
1623             if ( a1.compareTo( a1 ) != 0 ) {
1624                 return false;
1625             }
1626             if ( a1.compareTo( a1_copy ) != 0 ) {
1627                 return false;
1628             }
1629             if ( a1.compareTo( a1_equal ) != 0 ) {
1630                 return false;
1631             }
1632             if ( a1.compareTo( a2 ) != 0 ) {
1633                 return false;
1634             }
1635             if ( a1.compareTo( a3 ) == 0 ) {
1636                 return false;
1637             }
1638         }
1639         catch ( final Exception e ) {
1640             e.printStackTrace( System.out );
1641             return false;
1642         }
1643         return true;
1644     }
1645
1646     private static boolean testBasicNodeMethods() {
1647         try {
1648             if ( PhylogenyNode.getNodeCount() != 0 ) {
1649                 return false;
1650             }
1651             final PhylogenyNode n1 = new PhylogenyNode();
1652             final PhylogenyNode n2 = PhylogenyNode
1653                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1654             final PhylogenyNode n3 = PhylogenyNode
1655                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1656             final PhylogenyNode n4 = PhylogenyNode
1657                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1658             if ( n1.isHasAssignedEvent() ) {
1659                 return false;
1660             }
1661             if ( PhylogenyNode.getNodeCount() != 4 ) {
1662                 return false;
1663             }
1664             if ( n3.getIndicator() != 0 ) {
1665                 return false;
1666             }
1667             if ( n3.getNumberOfExternalNodes() != 1 ) {
1668                 return false;
1669             }
1670             if ( !n3.isExternal() ) {
1671                 return false;
1672             }
1673             if ( !n3.isRoot() ) {
1674                 return false;
1675             }
1676             if ( !n4.getName().equals( "n4" ) ) {
1677                 return false;
1678             }
1679         }
1680         catch ( final Exception e ) {
1681             e.printStackTrace( System.out );
1682             return false;
1683         }
1684         return true;
1685     }
1686
1687     private static boolean testBasicPhyloXMLparsing() {
1688         try {
1689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1690             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1691             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1692                                                               xml_parser );
1693             if ( xml_parser.getErrorCount() > 0 ) {
1694                 System.out.println( xml_parser.getErrorMessages().toString() );
1695                 return false;
1696             }
1697             if ( phylogenies_0.length != 4 ) {
1698                 return false;
1699             }
1700             final Phylogeny t1 = phylogenies_0[ 0 ];
1701             final Phylogeny t2 = phylogenies_0[ 1 ];
1702             final Phylogeny t3 = phylogenies_0[ 2 ];
1703             final Phylogeny t4 = phylogenies_0[ 3 ];
1704             if ( t1.getNumberOfExternalNodes() != 1 ) {
1705                 return false;
1706             }
1707             if ( !t1.isRooted() ) {
1708                 return false;
1709             }
1710             if ( t1.isRerootable() ) {
1711                 return false;
1712             }
1713             if ( !t1.getType().equals( "gene_tree" ) ) {
1714                 return false;
1715             }
1716             if ( t2.getNumberOfExternalNodes() != 2 ) {
1717                 return false;
1718             }
1719             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1720                 return false;
1721             }
1722             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1723                 return false;
1724             }
1725             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1726                 return false;
1727             }
1728             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1729                 return false;
1730             }
1731             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1732                 return false;
1733             }
1734             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1735                 return false;
1736             }
1737             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1738                     .startsWith( "actgtgggggt" ) ) {
1739                 return false;
1740             }
1741             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1742                     .startsWith( "ctgtgatgcat" ) ) {
1743                 return false;
1744             }
1745             if ( t3.getNumberOfExternalNodes() != 4 ) {
1746                 return false;
1747             }
1748             if ( !t1.getName().equals( "t1" ) ) {
1749                 return false;
1750             }
1751             if ( !t2.getName().equals( "t2" ) ) {
1752                 return false;
1753             }
1754             if ( !t3.getName().equals( "t3" ) ) {
1755                 return false;
1756             }
1757             if ( !t4.getName().equals( "t4" ) ) {
1758                 return false;
1759             }
1760             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1761                 return false;
1762             }
1763             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1764                 return false;
1765             }
1766             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1767                 return false;
1768             }
1769             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1770                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1771                 return false;
1772             }
1773             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1774                 return false;
1775             }
1776             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1777                 return false;
1778             }
1779             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1780                 return false;
1781             }
1782             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1783                     .equals( "apoptosis" ) ) {
1784                 return false;
1785             }
1786             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1787                     .equals( "GO:0006915" ) ) {
1788                 return false;
1789             }
1790             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1791                     .equals( "UniProtKB" ) ) {
1792                 return false;
1793             }
1794             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1795                     .equals( "experimental" ) ) {
1796                 return false;
1797             }
1798             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1799                     .equals( "function" ) ) {
1800                 return false;
1801             }
1802             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1803                     .getValue() != 1 ) {
1804                 return false;
1805             }
1806             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1807                     .getType().equals( "ml" ) ) {
1808                 return false;
1809             }
1810             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1811                     .equals( "apoptosis" ) ) {
1812                 return false;
1813             }
1814             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1815                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1816                 return false;
1817             }
1818             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1819                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1820                 return false;
1821             }
1822             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1823                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1824                 return false;
1825             }
1826             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1827                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1828                 return false;
1829             }
1830             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1831                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1832                 return false;
1833             }
1834             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1835                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1836                 return false;
1837             }
1838             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1839                     .equals( "GO:0005829" ) ) {
1840                 return false;
1841             }
1842             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1843                     .equals( "intracellular organelle" ) ) {
1844                 return false;
1845             }
1846             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1847                 return false;
1848             }
1849             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1850                     .equals( "UniProt link" ) ) ) {
1851                 return false;
1852             }
1853             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1854                 return false;
1855             }
1856             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1857             if ( x.size() != 4 ) {
1858                 return false;
1859             }
1860             int c = 0;
1861             for( final Accession acc : x ) {
1862                 if ( c == 0 ) {
1863                     if ( !acc.getSource().equals( "KEGG" ) ) {
1864                         return false;
1865                     }
1866                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1867                         return false;
1868                     }
1869                 }
1870                 c++;
1871             }
1872         }
1873         catch ( final Exception e ) {
1874             e.printStackTrace( System.out );
1875             return false;
1876         }
1877         return true;
1878     }
1879
1880     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1881         try {
1882             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1883             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1884             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1885                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1886             }
1887             else {
1888                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1889             }
1890             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1891                                                               xml_parser );
1892             if ( xml_parser.getErrorCount() > 0 ) {
1893                 System.out.println( xml_parser.getErrorMessages().toString() );
1894                 return false;
1895             }
1896             if ( phylogenies_0.length != 4 ) {
1897                 return false;
1898             }
1899             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1900             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1901             if ( phylogenies_t1.length != 1 ) {
1902                 return false;
1903             }
1904             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1905             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1906                 return false;
1907             }
1908             if ( !t1_rt.isRooted() ) {
1909                 return false;
1910             }
1911             if ( t1_rt.isRerootable() ) {
1912                 return false;
1913             }
1914             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1915                 return false;
1916             }
1917             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1918             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1919             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1920             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1921                 return false;
1922             }
1923             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1924                 return false;
1925             }
1926             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1927                 return false;
1928             }
1929             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1930                 return false;
1931             }
1932             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1933                     .startsWith( "actgtgggggt" ) ) {
1934                 return false;
1935             }
1936             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1937                     .startsWith( "ctgtgatgcat" ) ) {
1938                 return false;
1939             }
1940             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1941             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1942             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1943             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1944             if ( phylogenies_1.length != 1 ) {
1945                 return false;
1946             }
1947             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1948             if ( !t3_rt.getName().equals( "t3" ) ) {
1949                 return false;
1950             }
1951             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1952                 return false;
1953             }
1954             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1955                 return false;
1956             }
1957             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1958                 return false;
1959             }
1960             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1961                 return false;
1962             }
1963             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1964                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1974                     .equals( "UniProtKB" ) ) {
1975                 return false;
1976             }
1977             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1978                     .equals( "apoptosis" ) ) {
1979                 return false;
1980             }
1981             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1982                     .equals( "GO:0006915" ) ) {
1983                 return false;
1984             }
1985             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1986                     .equals( "UniProtKB" ) ) {
1987                 return false;
1988             }
1989             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1990                     .equals( "experimental" ) ) {
1991                 return false;
1992             }
1993             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1994                     .equals( "function" ) ) {
1995                 return false;
1996             }
1997             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1998                     .getValue() != 1 ) {
1999                 return false;
2000             }
2001             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2002                     .getType().equals( "ml" ) ) {
2003                 return false;
2004             }
2005             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2006                     .equals( "apoptosis" ) ) {
2007                 return false;
2008             }
2009             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2010                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2011                 return false;
2012             }
2013             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2014                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2015                 return false;
2016             }
2017             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2018                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2019                 return false;
2020             }
2021             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2022                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2023                 return false;
2024             }
2025             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2026                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2027                 return false;
2028             }
2029             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2030                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2031                 return false;
2032             }
2033             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2034                     .equals( "GO:0005829" ) ) {
2035                 return false;
2036             }
2037             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2038                     .equals( "intracellular organelle" ) ) {
2039                 return false;
2040             }
2041             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2042                 return false;
2043             }
2044             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2045                     .equals( "UniProt link" ) ) ) {
2046                 return false;
2047             }
2048             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2049                 return false;
2050             }
2051             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2052                 return false;
2053             }
2054             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2055                     .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." ) ) ) {
2056                 return false;
2057             }
2058             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2059                 return false;
2060             }
2061             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2062                 return false;
2063             }
2064             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2065                 return false;
2066             }
2067             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2068                 return false;
2069             }
2070             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2071                     .equals( "ncbi" ) ) {
2072                 return false;
2073             }
2074             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2075                 return false;
2076             }
2077             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2078                     .getName().equals( "B" ) ) {
2079                 return false;
2080             }
2081             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2082                     .getFrom() != 21 ) {
2083                 return false;
2084             }
2085             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2086                 return false;
2087             }
2088             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2089                     .getLength() != 24 ) {
2090                 return false;
2091             }
2092             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2093                     .getConfidence() != 2144 ) {
2094                 return false;
2095             }
2096             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2097                     .equals( "pfam" ) ) {
2098                 return false;
2099             }
2100             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2101                 return false;
2102             }
2103             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2104                 return false;
2105             }
2106             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2107                 return false;
2108             }
2109             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2110                 return false;
2111             }
2112             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2113             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2114                 return false;
2115             }
2116             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2117                 return false;
2118             }
2119             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2120                 return false;
2121             }
2122             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2123                 return false;
2124             }
2125             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2126                 return false;
2127             }
2128             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2129                 return false;
2130             }
2131             if ( taxbb.getSynonyms().size() != 2 ) {
2132                 return false;
2133             }
2134             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2135                 return false;
2136             }
2137             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2138                 return false;
2139             }
2140             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2141                 return false;
2142             }
2143             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2144                 return false;
2145             }
2146             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2147                 return false;
2148             }
2149             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2150                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2151                 return false;
2152             }
2153             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2154                 return false;
2155             }
2156             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2157                 return false;
2158             }
2159             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2160                 return false;
2161             }
2162             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2163                 return false;
2164             }
2165             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2166                 return false;
2167             }
2168             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2169                 return false;
2170             }
2171             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2172                 return false;
2173             }
2174             //
2175             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2176                 return false;
2177             }
2178             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2179                     .equalsIgnoreCase( "435" ) ) {
2180                 return false;
2181             }
2182             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2183                 return false;
2184             }
2185             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2186                     .equalsIgnoreCase( "443.7" ) ) {
2187                 return false;
2188             }
2189             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2190                 return false;
2191             }
2192             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2193                 return false;
2194             }
2195             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2196                     .equalsIgnoreCase( "433" ) ) {
2197                 return false;
2198             }
2199             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2200                     .getCrossReferences();
2201             if ( x.size() != 4 ) {
2202                 return false;
2203             }
2204             int c = 0;
2205             for( final Accession acc : x ) {
2206                 if ( c == 0 ) {
2207                     if ( !acc.getSource().equals( "KEGG" ) ) {
2208                         return false;
2209                     }
2210                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2211                         return false;
2212                     }
2213                 }
2214                 c++;
2215             }
2216         }
2217         catch ( final Exception e ) {
2218             e.printStackTrace( System.out );
2219             return false;
2220         }
2221         return true;
2222     }
2223
2224     private static boolean testBasicPhyloXMLparsingValidating() {
2225         try {
2226             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2227             PhyloXmlParser xml_parser = null;
2228             try {
2229                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2230             }
2231             catch ( final Exception e ) {
2232                 // Do nothing -- means were not running from jar.
2233             }
2234             if ( xml_parser == null ) {
2235                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2236                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2237                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2238                 }
2239                 else {
2240                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2241                 }
2242             }
2243             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2244                                                               xml_parser );
2245             if ( xml_parser.getErrorCount() > 0 ) {
2246                 System.out.println( xml_parser.getErrorMessages().toString() );
2247                 return false;
2248             }
2249             if ( phylogenies_0.length != 4 ) {
2250                 return false;
2251             }
2252             final Phylogeny t1 = phylogenies_0[ 0 ];
2253             final Phylogeny t2 = phylogenies_0[ 1 ];
2254             final Phylogeny t3 = phylogenies_0[ 2 ];
2255             final Phylogeny t4 = phylogenies_0[ 3 ];
2256             if ( !t1.getName().equals( "t1" ) ) {
2257                 return false;
2258             }
2259             if ( !t2.getName().equals( "t2" ) ) {
2260                 return false;
2261             }
2262             if ( !t3.getName().equals( "t3" ) ) {
2263                 return false;
2264             }
2265             if ( !t4.getName().equals( "t4" ) ) {
2266                 return false;
2267             }
2268             if ( t1.getNumberOfExternalNodes() != 1 ) {
2269                 return false;
2270             }
2271             if ( t2.getNumberOfExternalNodes() != 2 ) {
2272                 return false;
2273             }
2274             if ( t3.getNumberOfExternalNodes() != 4 ) {
2275                 return false;
2276             }
2277             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2278             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2279             if ( xml_parser.getErrorCount() > 0 ) {
2280                 System.out.println( "errors:" );
2281                 System.out.println( xml_parser.getErrorMessages().toString() );
2282                 return false;
2283             }
2284             if ( phylogenies_1.length != 4 ) {
2285                 return false;
2286             }
2287             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2288                                                               xml_parser );
2289             if ( xml_parser.getErrorCount() > 0 ) {
2290                 System.out.println( "errors:" );
2291                 System.out.println( xml_parser.getErrorMessages().toString() );
2292                 return false;
2293             }
2294             if ( phylogenies_2.length != 1 ) {
2295                 return false;
2296             }
2297             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2298                 return false;
2299             }
2300             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2301                                                               xml_parser );
2302             if ( xml_parser.getErrorCount() > 0 ) {
2303                 System.out.println( xml_parser.getErrorMessages().toString() );
2304                 return false;
2305             }
2306             if ( phylogenies_3.length != 2 ) {
2307                 return false;
2308             }
2309             final Phylogeny a = phylogenies_3[ 0 ];
2310             if ( !a.getName().equals( "tree 4" ) ) {
2311                 return false;
2312             }
2313             if ( a.getNumberOfExternalNodes() != 3 ) {
2314                 return false;
2315             }
2316             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2317                 return false;
2318             }
2319             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2320                 return false;
2321             }
2322             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2323                                                               xml_parser );
2324             if ( xml_parser.getErrorCount() > 0 ) {
2325                 System.out.println( xml_parser.getErrorMessages().toString() );
2326                 return false;
2327             }
2328             if ( phylogenies_4.length != 1 ) {
2329                 return false;
2330             }
2331             final Phylogeny s = phylogenies_4[ 0 ];
2332             if ( s.getNumberOfExternalNodes() != 6 ) {
2333                 return false;
2334             }
2335             s.getNode( "first" );
2336             s.getNode( "<>" );
2337             s.getNode( "\"<a'b&c'd\">\"" );
2338             s.getNode( "'''\"" );
2339             s.getNode( "\"\"\"" );
2340             s.getNode( "dick & doof" );
2341         }
2342         catch ( final Exception e ) {
2343             e.printStackTrace( System.out );
2344             return false;
2345         }
2346         return true;
2347     }
2348
2349     private static boolean testBasicProtein() {
2350         try {
2351             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2352             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             p0.addProteinDomain( y );
2360             p0.addProteinDomain( e );
2361             p0.addProteinDomain( b );
2362             p0.addProteinDomain( c );
2363             p0.addProteinDomain( d );
2364             p0.addProteinDomain( a );
2365             p0.addProteinDomain( x );
2366             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2367                 return false;
2368             }
2369             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2370                 return false;
2371             }
2372             //
2373             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2374             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             aa0.addProteinDomain( a1 );
2376             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2377                 return false;
2378             }
2379             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2380                 return false;
2381             }
2382             //
2383             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2384             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2385             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2386             aa1.addProteinDomain( a11 );
2387             aa1.addProteinDomain( a12 );
2388             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2389                 return false;
2390             }
2391             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2392                 return false;
2393             }
2394             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2395             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2396                 return false;
2397             }
2398             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2399                 return false;
2400             }
2401             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2402                 return false;
2403             }
2404             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2405             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2406                 return false;
2407             }
2408             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2409                 return false;
2410             }
2411             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2412                 return false;
2413             }
2414             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2415                 return false;
2416             }
2417             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2418             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2419                 return false;
2420             }
2421             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2422                 return false;
2423             }
2424             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2425                 return false;
2426             }
2427             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2428                 return false;
2429             }
2430             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2431             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2432                 return false;
2433             }
2434             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2435                 return false;
2436             }
2437             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2438                 return false;
2439             }
2440             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2441                 return false;
2442             }
2443             //
2444             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2445             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2446             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2447             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2448             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2449             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2450             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2451             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2452             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2453             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2454             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2455             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2456             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2457             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2458             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2459             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2460             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2461             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2462             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2463             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2464             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2465             p00.addProteinDomain( y0 );
2466             p00.addProteinDomain( e0 );
2467             p00.addProteinDomain( b0 );
2468             p00.addProteinDomain( c0 );
2469             p00.addProteinDomain( d0 );
2470             p00.addProteinDomain( a0 );
2471             p00.addProteinDomain( x0 );
2472             p00.addProteinDomain( y1 );
2473             p00.addProteinDomain( y2 );
2474             p00.addProteinDomain( y3 );
2475             p00.addProteinDomain( e1 );
2476             p00.addProteinDomain( e2 );
2477             p00.addProteinDomain( e3 );
2478             p00.addProteinDomain( e4 );
2479             p00.addProteinDomain( e5 );
2480             p00.addProteinDomain( z0 );
2481             p00.addProteinDomain( z1 );
2482             p00.addProteinDomain( z2 );
2483             p00.addProteinDomain( zz0 );
2484             p00.addProteinDomain( zz1 );
2485             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2486                 return false;
2487             }
2488             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2489                 return false;
2490             }
2491             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2492                 return false;
2493             }
2494             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2495                 return false;
2496             }
2497             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" ) ) {
2498                 return false;
2499             }
2500             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2501             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2502             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2503             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2504             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2505             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2506             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2507             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2508             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2509             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2510             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2511             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2512             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2513             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2514             p.addProteinDomain( B15 );
2515             p.addProteinDomain( C50 );
2516             p.addProteinDomain( A60 );
2517             p.addProteinDomain( A30 );
2518             p.addProteinDomain( C70 );
2519             p.addProteinDomain( B35 );
2520             p.addProteinDomain( B40 );
2521             p.addProteinDomain( A0 );
2522             p.addProteinDomain( A10 );
2523             p.addProteinDomain( A20 );
2524             p.addProteinDomain( B25 );
2525             p.addProteinDomain( D80 );
2526             List<String> domains_ids = new ArrayList<String>();
2527             domains_ids.add( "A" );
2528             domains_ids.add( "B" );
2529             domains_ids.add( "C" );
2530             if ( !p.contains( domains_ids, false ) ) {
2531                 return false;
2532             }
2533             if ( !p.contains( domains_ids, true ) ) {
2534                 return false;
2535             }
2536             domains_ids.add( "X" );
2537             if ( p.contains( domains_ids, false ) ) {
2538                 return false;
2539             }
2540             if ( p.contains( domains_ids, true ) ) {
2541                 return false;
2542             }
2543             domains_ids = new ArrayList<String>();
2544             domains_ids.add( "A" );
2545             domains_ids.add( "C" );
2546             domains_ids.add( "D" );
2547             if ( !p.contains( domains_ids, false ) ) {
2548                 return false;
2549             }
2550             if ( !p.contains( domains_ids, true ) ) {
2551                 return false;
2552             }
2553             domains_ids = new ArrayList<String>();
2554             domains_ids.add( "A" );
2555             domains_ids.add( "D" );
2556             domains_ids.add( "C" );
2557             if ( !p.contains( domains_ids, false ) ) {
2558                 return false;
2559             }
2560             if ( p.contains( domains_ids, true ) ) {
2561                 return false;
2562             }
2563             domains_ids = new ArrayList<String>();
2564             domains_ids.add( "A" );
2565             domains_ids.add( "A" );
2566             domains_ids.add( "B" );
2567             if ( !p.contains( domains_ids, false ) ) {
2568                 return false;
2569             }
2570             if ( !p.contains( domains_ids, true ) ) {
2571                 return false;
2572             }
2573             domains_ids = new ArrayList<String>();
2574             domains_ids.add( "A" );
2575             domains_ids.add( "A" );
2576             domains_ids.add( "A" );
2577             domains_ids.add( "B" );
2578             domains_ids.add( "B" );
2579             if ( !p.contains( domains_ids, false ) ) {
2580                 return false;
2581             }
2582             if ( !p.contains( domains_ids, true ) ) {
2583                 return false;
2584             }
2585             domains_ids = new ArrayList<String>();
2586             domains_ids.add( "A" );
2587             domains_ids.add( "A" );
2588             domains_ids.add( "B" );
2589             domains_ids.add( "A" );
2590             domains_ids.add( "B" );
2591             domains_ids.add( "B" );
2592             domains_ids.add( "A" );
2593             domains_ids.add( "B" );
2594             domains_ids.add( "C" );
2595             domains_ids.add( "A" );
2596             domains_ids.add( "C" );
2597             domains_ids.add( "D" );
2598             if ( !p.contains( domains_ids, false ) ) {
2599                 return false;
2600             }
2601             if ( p.contains( domains_ids, true ) ) {
2602                 return false;
2603             }
2604         }
2605         catch ( final Exception e ) {
2606             e.printStackTrace( System.out );
2607             return false;
2608         }
2609         return true;
2610     }
2611
2612     private static boolean testBasicTable() {
2613         try {
2614             final BasicTable<String> t0 = new BasicTable<String>();
2615             if ( t0.getNumberOfColumns() != 0 ) {
2616                 return false;
2617             }
2618             if ( t0.getNumberOfRows() != 0 ) {
2619                 return false;
2620             }
2621             t0.setValue( 3, 2, "23" );
2622             t0.setValue( 10, 1, "error" );
2623             t0.setValue( 10, 1, "110" );
2624             t0.setValue( 9, 1, "19" );
2625             t0.setValue( 1, 10, "101" );
2626             t0.setValue( 10, 10, "1010" );
2627             t0.setValue( 100, 10, "10100" );
2628             t0.setValue( 0, 0, "00" );
2629             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2630                 return false;
2631             }
2632             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2633                 return false;
2634             }
2635             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2636                 return false;
2637             }
2638             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2639                 return false;
2640             }
2641             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2642                 return false;
2643             }
2644             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2645                 return false;
2646             }
2647             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2648                 return false;
2649             }
2650             if ( t0.getNumberOfColumns() != 101 ) {
2651                 return false;
2652             }
2653             if ( t0.getNumberOfRows() != 11 ) {
2654                 return false;
2655             }
2656             if ( t0.getValueAsString( 49, 4 ) != null ) {
2657                 return false;
2658             }
2659             final String l = ForesterUtil.getLineSeparator();
2660             final StringBuffer source = new StringBuffer();
2661             source.append( "" + l );
2662             source.append( "# 1 1 1 1 1 1 1 1" + l );
2663             source.append( " 00 01 02 03" + l );
2664             source.append( "   10 11 12 13  " + l );
2665             source.append( "20 21 22 23 " + l );
2666             source.append( "    30  31    32 33" + l );
2667             source.append( "40 41 42 43" + l );
2668             source.append( "  # 1 1 1 1 1 " + l );
2669             source.append( "50 51 52 53 54" + l );
2670             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2671             if ( t1.getNumberOfColumns() != 5 ) {
2672                 return false;
2673             }
2674             if ( t1.getNumberOfRows() != 6 ) {
2675                 return false;
2676             }
2677             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2678                 return false;
2679             }
2680             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2681                 return false;
2682             }
2683             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2684                 return false;
2685             }
2686             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2687                 return false;
2688             }
2689             final StringBuffer source1 = new StringBuffer();
2690             source1.append( "" + l );
2691             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2692             source1.append( " 00; 01 ;02;03" + l );
2693             source1.append( "   10; 11; 12; 13  " + l );
2694             source1.append( "20; 21; 22; 23 " + l );
2695             source1.append( "    30;  31;    32; 33" + l );
2696             source1.append( "40;41;42;43" + l );
2697             source1.append( "  # 1 1 1 1 1 " + l );
2698             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2699             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2700             if ( t2.getNumberOfColumns() != 5 ) {
2701                 return false;
2702             }
2703             if ( t2.getNumberOfRows() != 6 ) {
2704                 return false;
2705             }
2706             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2707                 return false;
2708             }
2709             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2710                 return false;
2711             }
2712             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2713                 return false;
2714             }
2715             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2716                 return false;
2717             }
2718             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2719                 return false;
2720             }
2721             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2722                 return false;
2723             }
2724             final StringBuffer source2 = new StringBuffer();
2725             source2.append( "" + l );
2726             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2727             source2.append( " 00; 01 ;02;03" + l );
2728             source2.append( "   10; 11; 12; 13  " + l );
2729             source2.append( "20; 21; 22; 23 " + l );
2730             source2.append( "                     " + l );
2731             source2.append( "    30;  31;    32; 33" + l );
2732             source2.append( "40;41;42;43" + l );
2733             source2.append( "  comment: 1 1 1 1 1 " + l );
2734             source2.append( ";;;50  ;   52; 53;;54   " + l );
2735             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2736                                                                         ';',
2737                                                                         false,
2738                                                                         false,
2739                                                                         "comment:",
2740                                                                         false );
2741             if ( tl.size() != 2 ) {
2742                 return false;
2743             }
2744             final BasicTable<String> t3 = tl.get( 0 );
2745             final BasicTable<String> t4 = tl.get( 1 );
2746             if ( t3.getNumberOfColumns() != 4 ) {
2747                 return false;
2748             }
2749             if ( t3.getNumberOfRows() != 3 ) {
2750                 return false;
2751             }
2752             if ( t4.getNumberOfColumns() != 4 ) {
2753                 return false;
2754             }
2755             if ( t4.getNumberOfRows() != 3 ) {
2756                 return false;
2757             }
2758             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2759                 return false;
2760             }
2761             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2762                 return false;
2763             }
2764         }
2765         catch ( final Exception e ) {
2766             e.printStackTrace( System.out );
2767             return false;
2768         }
2769         return true;
2770     }
2771
2772     private static boolean testBasicTolXMLparsing() {
2773         try {
2774             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2775             final TolParser parser = new TolParser();
2776             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2777             if ( parser.getErrorCount() > 0 ) {
2778                 System.out.println( parser.getErrorMessages().toString() );
2779                 return false;
2780             }
2781             if ( phylogenies_0.length != 1 ) {
2782                 return false;
2783             }
2784             final Phylogeny t1 = phylogenies_0[ 0 ];
2785             if ( t1.getNumberOfExternalNodes() != 5 ) {
2786                 return false;
2787             }
2788             if ( !t1.isRooted() ) {
2789                 return false;
2790             }
2791             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2792                 return false;
2793             }
2794             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2795                 return false;
2796             }
2797             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2798                 return false;
2799             }
2800             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2801                 return false;
2802             }
2803             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2804             if ( parser.getErrorCount() > 0 ) {
2805                 System.out.println( parser.getErrorMessages().toString() );
2806                 return false;
2807             }
2808             if ( phylogenies_1.length != 1 ) {
2809                 return false;
2810             }
2811             final Phylogeny t2 = phylogenies_1[ 0 ];
2812             if ( t2.getNumberOfExternalNodes() != 664 ) {
2813                 return false;
2814             }
2815             if ( !t2.isRooted() ) {
2816                 return false;
2817             }
2818             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2819                 return false;
2820             }
2821             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2822                 return false;
2823             }
2824             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2825                 return false;
2826             }
2827             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2828                 return false;
2829             }
2830             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2831                 return false;
2832             }
2833             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2834                     .equals( "Aquifex" ) ) {
2835                 return false;
2836             }
2837             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2838             if ( parser.getErrorCount() > 0 ) {
2839                 System.out.println( parser.getErrorMessages().toString() );
2840                 return false;
2841             }
2842             if ( phylogenies_2.length != 1 ) {
2843                 return false;
2844             }
2845             final Phylogeny t3 = phylogenies_2[ 0 ];
2846             if ( t3.getNumberOfExternalNodes() != 184 ) {
2847                 return false;
2848             }
2849             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2850                 return false;
2851             }
2852             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2853                 return false;
2854             }
2855             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2856                 return false;
2857             }
2858             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2859             if ( parser.getErrorCount() > 0 ) {
2860                 System.out.println( parser.getErrorMessages().toString() );
2861                 return false;
2862             }
2863             if ( phylogenies_3.length != 1 ) {
2864                 return false;
2865             }
2866             final Phylogeny t4 = phylogenies_3[ 0 ];
2867             if ( t4.getNumberOfExternalNodes() != 1 ) {
2868                 return false;
2869             }
2870             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2871                 return false;
2872             }
2873             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2874                 return false;
2875             }
2876             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2877                 return false;
2878             }
2879             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2880             if ( parser.getErrorCount() > 0 ) {
2881                 System.out.println( parser.getErrorMessages().toString() );
2882                 return false;
2883             }
2884             if ( phylogenies_4.length != 1 ) {
2885                 return false;
2886             }
2887             final Phylogeny t5 = phylogenies_4[ 0 ];
2888             if ( t5.getNumberOfExternalNodes() != 13 ) {
2889                 return false;
2890             }
2891             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2892                 return false;
2893             }
2894             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2895                 return false;
2896             }
2897             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2898                 return false;
2899             }
2900         }
2901         catch ( final Exception e ) {
2902             e.printStackTrace( System.out );
2903             return false;
2904         }
2905         return true;
2906     }
2907
2908     private static boolean testBasicTreeMethods() {
2909         try {
2910             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2911             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2912             if ( t2.getNumberOfExternalNodes() != 4 ) {
2913                 return false;
2914             }
2915             if ( t2.getHeight() != 8.5 ) {
2916                 return false;
2917             }
2918             if ( !t2.isCompletelyBinary() ) {
2919                 return false;
2920             }
2921             if ( t2.isEmpty() ) {
2922                 return false;
2923             }
2924             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2925             if ( t3.getNumberOfExternalNodes() != 5 ) {
2926                 return false;
2927             }
2928             if ( t3.getHeight() != 11 ) {
2929                 return false;
2930             }
2931             if ( t3.isCompletelyBinary() ) {
2932                 return false;
2933             }
2934             final PhylogenyNode n = t3.getNode( "ABC" );
2935             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 ];
2936             if ( t4.getNumberOfExternalNodes() != 9 ) {
2937                 return false;
2938             }
2939             if ( t4.getHeight() != 11 ) {
2940                 return false;
2941             }
2942             if ( t4.isCompletelyBinary() ) {
2943                 return false;
2944             }
2945             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)" );
2946             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2947             if ( t5.getNumberOfExternalNodes() != 8 ) {
2948                 return false;
2949             }
2950             if ( t5.getHeight() != 15 ) {
2951                 return false;
2952             }
2953             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)" );
2954             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2955             if ( t6.getHeight() != 15 ) {
2956                 return false;
2957             }
2958             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)" );
2959             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2960             if ( t7.getHeight() != 15 ) {
2961                 return false;
2962             }
2963             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)" );
2964             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2965             if ( t8.getNumberOfExternalNodes() != 10 ) {
2966                 return false;
2967             }
2968             if ( t8.getHeight() != 15 ) {
2969                 return false;
2970             }
2971             final char[] a9 = new char[] { 'a' };
2972             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2973             if ( t9.getHeight() != 0 ) {
2974                 return false;
2975             }
2976             final char[] a10 = new char[] { 'a', ':', '6' };
2977             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2978             if ( t10.getHeight() != 6 ) {
2979                 return false;
2980             }
2981         }
2982         catch ( final Exception e ) {
2983             e.printStackTrace( System.out );
2984             return false;
2985         }
2986         return true;
2987     }
2988
2989     private static boolean testConfidenceAssessor() {
2990         try {
2991             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2992             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2993             final Phylogeny[] ev0 = factory
2994                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2995                              new NHXParser() );
2996             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2997             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2998                 return false;
2999             }
3000             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3001                 return false;
3002             }
3003             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3004             final Phylogeny[] ev1 = factory
3005                     .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)));",
3006                              new NHXParser() );
3007             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3008             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3009                 return false;
3010             }
3011             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3012                 return false;
3013             }
3014             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3015             final Phylogeny[] ev_b = factory
3016                     .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",
3017                              new NHXParser() );
3018             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3019             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3020                 return false;
3021             }
3022             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3023                 return false;
3024             }
3025             //
3026             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3027             final Phylogeny[] ev1x = factory
3028                     .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)));",
3029                              new NHXParser() );
3030             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3031             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3032                 return false;
3033             }
3034             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3035                 return false;
3036             }
3037             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3038             final Phylogeny[] ev_bx = factory
3039                     .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",
3040                              new NHXParser() );
3041             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3042             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3043                 return false;
3044             }
3045             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3046                 return false;
3047             }
3048             //
3049             final Phylogeny[] t2 = factory
3050                     .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);",
3051                              new NHXParser() );
3052             final Phylogeny[] ev2 = factory
3053                     .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);",
3054                              new NHXParser() );
3055             for( final Phylogeny target : t2 ) {
3056                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3057             }
3058             //
3059             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3060                                                  new NHXParser() )[ 0 ];
3061             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3062             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3063             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3064                 return false;
3065             }
3066             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3067                 return false;
3068             }
3069             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3070                 return false;
3071             }
3072         }
3073         catch ( final Exception e ) {
3074             e.printStackTrace();
3075             return false;
3076         }
3077         return true;
3078     }
3079
3080     private static boolean testCopyOfNodeData() {
3081         try {
3082             final PhylogenyNode n1 = PhylogenyNode
3083                     .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]" );
3084             final PhylogenyNode n2 = n1.copyNodeData();
3085             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3086                 return false;
3087             }
3088         }
3089         catch ( final Exception e ) {
3090             e.printStackTrace();
3091             return false;
3092         }
3093         return true;
3094     }
3095
3096     private static boolean testCreateBalancedPhylogeny() {
3097         try {
3098             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3099             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3100                 return false;
3101             }
3102             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3103                 return false;
3104             }
3105             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3106             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3107                 return false;
3108             }
3109             if ( p1.getNumberOfExternalNodes() != 100 ) {
3110                 return false;
3111             }
3112         }
3113         catch ( final Exception e ) {
3114             e.printStackTrace();
3115             return false;
3116         }
3117         return true;
3118     }
3119
3120     private static boolean testCreateUriForSeqWeb() {
3121         try {
3122             final PhylogenyNode n = new PhylogenyNode();
3123             n.setName( "tr|B3RJ64" );
3124             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3125                 return false;
3126             }
3127             n.setName( "B0LM41_HUMAN" );
3128             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3129                 return false;
3130             }
3131             n.setName( "NP_001025424" );
3132             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3133                 return false;
3134             }
3135             n.setName( "_NM_001030253-" );
3136             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3137                 return false;
3138             }
3139             n.setName( "XM_002122186" );
3140             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3141                 return false;
3142             }
3143             n.setName( "dgh_AAA34956_gdg" );
3144             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3145                 return false;
3146             }
3147             n.setName( "AAA34956" );
3148             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3149                 return false;
3150             }
3151             n.setName( "GI:394892" );
3152             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3153                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3154                 return false;
3155             }
3156             n.setName( "gi_394892" );
3157             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3158                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3159                 return false;
3160             }
3161             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3162             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3163                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3164                 return false;
3165             }
3166             n.setName( "P12345" );
3167             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3168                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3169                 return false;
3170             }
3171             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3172             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3173                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3174                 return false;
3175             }
3176         }
3177         catch ( final Exception e ) {
3178             e.printStackTrace( System.out );
3179             return false;
3180         }
3181         return true;
3182     }
3183
3184     private static boolean testDataObjects() {
3185         try {
3186             final Confidence s0 = new Confidence();
3187             final Confidence s1 = new Confidence();
3188             if ( !s0.isEqual( s1 ) ) {
3189                 return false;
3190             }
3191             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3192             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3193             if ( s2.isEqual( s1 ) ) {
3194                 return false;
3195             }
3196             if ( !s2.isEqual( s3 ) ) {
3197                 return false;
3198             }
3199             final Confidence s4 = ( Confidence ) s3.copy();
3200             if ( !s4.isEqual( s3 ) ) {
3201                 return false;
3202             }
3203             s3.asSimpleText();
3204             s3.asText();
3205             // Taxonomy
3206             // ----------
3207             final Taxonomy t1 = new Taxonomy();
3208             final Taxonomy t2 = new Taxonomy();
3209             final Taxonomy t3 = new Taxonomy();
3210             final Taxonomy t4 = new Taxonomy();
3211             final Taxonomy t5 = new Taxonomy();
3212             t1.setIdentifier( new Identifier( "ecoli" ) );
3213             t1.setTaxonomyCode( "ECOLI" );
3214             t1.setScientificName( "E. coli" );
3215             t1.setCommonName( "coli" );
3216             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3217             if ( !t1.isEqual( t0 ) ) {
3218                 return false;
3219             }
3220             t2.setIdentifier( new Identifier( "ecoli" ) );
3221             t2.setTaxonomyCode( "OTHER" );
3222             t2.setScientificName( "what" );
3223             t2.setCommonName( "something" );
3224             if ( !t1.isEqual( t2 ) ) {
3225                 return false;
3226             }
3227             t2.setIdentifier( new Identifier( "nemve" ) );
3228             if ( t1.isEqual( t2 ) ) {
3229                 return false;
3230             }
3231             t1.setIdentifier( null );
3232             t3.setTaxonomyCode( "ECOLI" );
3233             t3.setScientificName( "what" );
3234             t3.setCommonName( "something" );
3235             if ( !t1.isEqual( t3 ) ) {
3236                 return false;
3237             }
3238             t1.setIdentifier( null );
3239             t1.setTaxonomyCode( "" );
3240             t4.setScientificName( "E. ColI" );
3241             t4.setCommonName( "something" );
3242             if ( !t1.isEqual( t4 ) ) {
3243                 return false;
3244             }
3245             t4.setScientificName( "B. subtilis" );
3246             t4.setCommonName( "something" );
3247             if ( t1.isEqual( t4 ) ) {
3248                 return false;
3249             }
3250             t1.setIdentifier( null );
3251             t1.setTaxonomyCode( "" );
3252             t1.setScientificName( "" );
3253             t5.setCommonName( "COLI" );
3254             if ( !t1.isEqual( t5 ) ) {
3255                 return false;
3256             }
3257             t5.setCommonName( "vibrio" );
3258             if ( t1.isEqual( t5 ) ) {
3259                 return false;
3260             }
3261             // Identifier
3262             // ----------
3263             final Identifier id0 = new Identifier( "123", "pfam" );
3264             final Identifier id1 = ( Identifier ) id0.copy();
3265             if ( !id1.isEqual( id1 ) ) {
3266                 return false;
3267             }
3268             if ( !id1.isEqual( id0 ) ) {
3269                 return false;
3270             }
3271             if ( !id0.isEqual( id1 ) ) {
3272                 return false;
3273             }
3274             id1.asSimpleText();
3275             id1.asText();
3276             // ProteinDomain
3277             // ---------------
3278             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3279             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3280             if ( !pd1.isEqual( pd1 ) ) {
3281                 return false;
3282             }
3283             if ( !pd1.isEqual( pd0 ) ) {
3284                 return false;
3285             }
3286             pd1.asSimpleText();
3287             pd1.asText();
3288             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3289             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3290             if ( !pd3.isEqual( pd3 ) ) {
3291                 return false;
3292             }
3293             if ( !pd2.isEqual( pd3 ) ) {
3294                 return false;
3295             }
3296             if ( !pd0.isEqual( pd3 ) ) {
3297                 return false;
3298             }
3299             pd3.asSimpleText();
3300             pd3.asText();
3301             // DomainArchitecture
3302             // ------------------
3303             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3304             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3305             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3306             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3307             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3308             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3309             domains0.add( d2 );
3310             domains0.add( d0 );
3311             domains0.add( d3 );
3312             domains0.add( d1 );
3313             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3314             if ( ds0.getNumberOfDomains() != 4 ) {
3315                 return false;
3316             }
3317             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3318             if ( !ds0.isEqual( ds0 ) ) {
3319                 return false;
3320             }
3321             if ( !ds0.isEqual( ds1 ) ) {
3322                 return false;
3323             }
3324             if ( ds1.getNumberOfDomains() != 4 ) {
3325                 return false;
3326             }
3327             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3328             domains1.add( d1 );
3329             domains1.add( d2 );
3330             domains1.add( d4 );
3331             domains1.add( d0 );
3332             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3333             if ( ds0.isEqual( ds2 ) ) {
3334                 return false;
3335             }
3336             ds1.asSimpleText();
3337             ds1.asText();
3338             ds1.toNHX();
3339             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3340             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3341                 System.out.println( ds3.toNHX() );
3342                 return false;
3343             }
3344             if ( ds3.getNumberOfDomains() != 3 ) {
3345                 return false;
3346             }
3347             // Event
3348             // -----
3349             final Event e1 = new Event( Event.EventType.fusion );
3350             if ( e1.isDuplication() ) {
3351                 return false;
3352             }
3353             if ( !e1.isFusion() ) {
3354                 return false;
3355             }
3356             if ( !e1.asText().toString().equals( "fusion" ) ) {
3357                 return false;
3358             }
3359             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3360                 return false;
3361             }
3362             final Event e11 = new Event( Event.EventType.fusion );
3363             if ( !e11.isEqual( e1 ) ) {
3364                 return false;
3365             }
3366             if ( !e11.toNHX().toString().equals( "" ) ) {
3367                 return false;
3368             }
3369             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3370             if ( e2.isDuplication() ) {
3371                 return false;
3372             }
3373             if ( !e2.isSpeciationOrDuplication() ) {
3374                 return false;
3375             }
3376             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3377                 return false;
3378             }
3379             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3380                 return false;
3381             }
3382             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3383                 return false;
3384             }
3385             if ( e11.isEqual( e2 ) ) {
3386                 return false;
3387             }
3388             final Event e2c = ( Event ) e2.copy();
3389             if ( !e2c.isEqual( e2 ) ) {
3390                 return false;
3391             }
3392             Event e3 = new Event( 1, 2, 3 );
3393             if ( e3.isDuplication() ) {
3394                 return false;
3395             }
3396             if ( e3.isSpeciation() ) {
3397                 return false;
3398             }
3399             if ( e3.isGeneLoss() ) {
3400                 return false;
3401             }
3402             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3403                 return false;
3404             }
3405             final Event e3c = ( Event ) e3.copy();
3406             final Event e3cc = ( Event ) e3c.copy();
3407             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3408                 return false;
3409             }
3410             e3 = null;
3411             if ( !e3c.isEqual( e3cc ) ) {
3412                 return false;
3413             }
3414             Event e4 = new Event( 1, 2, 3 );
3415             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3416                 return false;
3417             }
3418             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3419                 return false;
3420             }
3421             final Event e4c = ( Event ) e4.copy();
3422             e4 = null;
3423             final Event e4cc = ( Event ) e4c.copy();
3424             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3425                 return false;
3426             }
3427             if ( !e4c.isEqual( e4cc ) ) {
3428                 return false;
3429             }
3430             final Event e5 = new Event();
3431             if ( !e5.isUnassigned() ) {
3432                 return false;
3433             }
3434             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3435                 return false;
3436             }
3437             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3438                 return false;
3439             }
3440             final Event e6 = new Event( 1, 0, 0 );
3441             if ( !e6.asText().toString().equals( "duplication" ) ) {
3442                 return false;
3443             }
3444             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3445                 return false;
3446             }
3447             final Event e7 = new Event( 0, 1, 0 );
3448             if ( !e7.asText().toString().equals( "speciation" ) ) {
3449                 return false;
3450             }
3451             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3452                 return false;
3453             }
3454             final Event e8 = new Event( 0, 0, 1 );
3455             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3456                 return false;
3457             }
3458             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3459                 return false;
3460             }
3461         }
3462         catch ( final Exception e ) {
3463             e.printStackTrace( System.out );
3464             return false;
3465         }
3466         return true;
3467     }
3468
3469     private static boolean testDeletionOfExternalNodes() {
3470         try {
3471             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3472             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3473             final PhylogenyWriter w = new PhylogenyWriter();
3474             if ( t0.isEmpty() ) {
3475                 return false;
3476             }
3477             if ( t0.getNumberOfExternalNodes() != 1 ) {
3478                 return false;
3479             }
3480             t0.deleteSubtree( t0.getNode( "A" ), false );
3481             if ( t0.getNumberOfExternalNodes() != 0 ) {
3482                 return false;
3483             }
3484             if ( !t0.isEmpty() ) {
3485                 return false;
3486             }
3487             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3488             if ( t1.getNumberOfExternalNodes() != 2 ) {
3489                 return false;
3490             }
3491             t1.deleteSubtree( t1.getNode( "A" ), false );
3492             if ( t1.getNumberOfExternalNodes() != 1 ) {
3493                 return false;
3494             }
3495             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3496                 return false;
3497             }
3498             t1.deleteSubtree( t1.getNode( "B" ), false );
3499             if ( t1.getNumberOfExternalNodes() != 1 ) {
3500                 return false;
3501             }
3502             t1.deleteSubtree( t1.getNode( "r" ), false );
3503             if ( !t1.isEmpty() ) {
3504                 return false;
3505             }
3506             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3507             if ( t2.getNumberOfExternalNodes() != 3 ) {
3508                 return false;
3509             }
3510             t2.deleteSubtree( t2.getNode( "B" ), false );
3511             if ( t2.getNumberOfExternalNodes() != 2 ) {
3512                 return false;
3513             }
3514             t2.toNewHampshireX();
3515             PhylogenyNode n = t2.getNode( "A" );
3516             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3517                 return false;
3518             }
3519             t2.deleteSubtree( t2.getNode( "A" ), false );
3520             if ( t2.getNumberOfExternalNodes() != 2 ) {
3521                 return false;
3522             }
3523             t2.deleteSubtree( t2.getNode( "C" ), true );
3524             if ( t2.getNumberOfExternalNodes() != 1 ) {
3525                 return false;
3526             }
3527             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3528             if ( t3.getNumberOfExternalNodes() != 4 ) {
3529                 return false;
3530             }
3531             t3.deleteSubtree( t3.getNode( "B" ), true );
3532             if ( t3.getNumberOfExternalNodes() != 3 ) {
3533                 return false;
3534             }
3535             n = t3.getNode( "A" );
3536             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3537                 return false;
3538             }
3539             n = n.getNextExternalNode();
3540             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3541                 return false;
3542             }
3543             t3.deleteSubtree( t3.getNode( "A" ), true );
3544             if ( t3.getNumberOfExternalNodes() != 2 ) {
3545                 return false;
3546             }
3547             n = t3.getNode( "C" );
3548             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3549                 return false;
3550             }
3551             t3.deleteSubtree( t3.getNode( "C" ), true );
3552             if ( t3.getNumberOfExternalNodes() != 1 ) {
3553                 return false;
3554             }
3555             t3.deleteSubtree( t3.getNode( "D" ), true );
3556             if ( t3.getNumberOfExternalNodes() != 0 ) {
3557                 return false;
3558             }
3559             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3560             if ( t4.getNumberOfExternalNodes() != 6 ) {
3561                 return false;
3562             }
3563             t4.deleteSubtree( t4.getNode( "B2" ), true );
3564             if ( t4.getNumberOfExternalNodes() != 5 ) {
3565                 return false;
3566             }
3567             String s = w.toNewHampshire( t4, true ).toString();
3568             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3569                 return false;
3570             }
3571             t4.deleteSubtree( t4.getNode( "B11" ), true );
3572             if ( t4.getNumberOfExternalNodes() != 4 ) {
3573                 return false;
3574             }
3575             t4.deleteSubtree( t4.getNode( "C" ), true );
3576             if ( t4.getNumberOfExternalNodes() != 3 ) {
3577                 return false;
3578             }
3579             n = t4.getNode( "A" );
3580             n = n.getNextExternalNode();
3581             if ( !n.getName().equals( "B12" ) ) {
3582                 return false;
3583             }
3584             n = n.getNextExternalNode();
3585             if ( !n.getName().equals( "D" ) ) {
3586                 return false;
3587             }
3588             s = w.toNewHampshire( t4, true ).toString();
3589             if ( !s.equals( "((A,B12),D);" ) ) {
3590                 return false;
3591             }
3592             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3593             t5.deleteSubtree( t5.getNode( "A" ), true );
3594             if ( t5.getNumberOfExternalNodes() != 5 ) {
3595                 return false;
3596             }
3597             s = w.toNewHampshire( t5, true ).toString();
3598             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3599                 return false;
3600             }
3601             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3602             t6.deleteSubtree( t6.getNode( "B11" ), true );
3603             if ( t6.getNumberOfExternalNodes() != 5 ) {
3604                 return false;
3605             }
3606             s = w.toNewHampshire( t6, false ).toString();
3607             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3608                 return false;
3609             }
3610             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3611             t7.deleteSubtree( t7.getNode( "B12" ), true );
3612             if ( t7.getNumberOfExternalNodes() != 5 ) {
3613                 return false;
3614             }
3615             s = w.toNewHampshire( t7, true ).toString();
3616             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3617                 return false;
3618             }
3619             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3620             t8.deleteSubtree( t8.getNode( "B2" ), true );
3621             if ( t8.getNumberOfExternalNodes() != 5 ) {
3622                 return false;
3623             }
3624             s = w.toNewHampshire( t8, false ).toString();
3625             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3626                 return false;
3627             }
3628             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3629             t9.deleteSubtree( t9.getNode( "C" ), true );
3630             if ( t9.getNumberOfExternalNodes() != 5 ) {
3631                 return false;
3632             }
3633             s = w.toNewHampshire( t9, true ).toString();
3634             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3635                 return false;
3636             }
3637             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3638             t10.deleteSubtree( t10.getNode( "D" ), true );
3639             if ( t10.getNumberOfExternalNodes() != 5 ) {
3640                 return false;
3641             }
3642             s = w.toNewHampshire( t10, true ).toString();
3643             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3644                 return false;
3645             }
3646             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3647             t11.deleteSubtree( t11.getNode( "A" ), true );
3648             if ( t11.getNumberOfExternalNodes() != 2 ) {
3649                 return false;
3650             }
3651             s = w.toNewHampshire( t11, true ).toString();
3652             if ( !s.equals( "(B,C);" ) ) {
3653                 return false;
3654             }
3655             t11.deleteSubtree( t11.getNode( "C" ), true );
3656             if ( t11.getNumberOfExternalNodes() != 1 ) {
3657                 return false;
3658             }
3659             s = w.toNewHampshire( t11, false ).toString();
3660             if ( !s.equals( "B;" ) ) {
3661                 return false;
3662             }
3663             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3664             t12.deleteSubtree( t12.getNode( "B2" ), true );
3665             if ( t12.getNumberOfExternalNodes() != 8 ) {
3666                 return false;
3667             }
3668             s = w.toNewHampshire( t12, true ).toString();
3669             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3670                 return false;
3671             }
3672             t12.deleteSubtree( t12.getNode( "B3" ), true );
3673             if ( t12.getNumberOfExternalNodes() != 7 ) {
3674                 return false;
3675             }
3676             s = w.toNewHampshire( t12, true ).toString();
3677             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3678                 return false;
3679             }
3680             t12.deleteSubtree( t12.getNode( "C3" ), true );
3681             if ( t12.getNumberOfExternalNodes() != 6 ) {
3682                 return false;
3683             }
3684             s = w.toNewHampshire( t12, true ).toString();
3685             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3686                 return false;
3687             }
3688             t12.deleteSubtree( t12.getNode( "A1" ), true );
3689             if ( t12.getNumberOfExternalNodes() != 5 ) {
3690                 return false;
3691             }
3692             s = w.toNewHampshire( t12, true ).toString();
3693             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3694                 return false;
3695             }
3696             t12.deleteSubtree( t12.getNode( "B1" ), true );
3697             if ( t12.getNumberOfExternalNodes() != 4 ) {
3698                 return false;
3699             }
3700             s = w.toNewHampshire( t12, true ).toString();
3701             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3702                 return false;
3703             }
3704             t12.deleteSubtree( t12.getNode( "A3" ), true );
3705             if ( t12.getNumberOfExternalNodes() != 3 ) {
3706                 return false;
3707             }
3708             s = w.toNewHampshire( t12, true ).toString();
3709             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3710                 return false;
3711             }
3712             t12.deleteSubtree( t12.getNode( "A2" ), true );
3713             if ( t12.getNumberOfExternalNodes() != 2 ) {
3714                 return false;
3715             }
3716             s = w.toNewHampshire( t12, true ).toString();
3717             if ( !s.equals( "(C1,C2);" ) ) {
3718                 return false;
3719             }
3720             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3721             t13.deleteSubtree( t13.getNode( "D" ), true );
3722             if ( t13.getNumberOfExternalNodes() != 4 ) {
3723                 return false;
3724             }
3725             s = w.toNewHampshire( t13, true ).toString();
3726             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3727                 return false;
3728             }
3729             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3730             t14.deleteSubtree( t14.getNode( "E" ), true );
3731             if ( t14.getNumberOfExternalNodes() != 5 ) {
3732                 return false;
3733             }
3734             s = w.toNewHampshire( t14, true ).toString();
3735             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3736                 return false;
3737             }
3738             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3739             t15.deleteSubtree( t15.getNode( "B2" ), true );
3740             if ( t15.getNumberOfExternalNodes() != 11 ) {
3741                 return false;
3742             }
3743             t15.deleteSubtree( t15.getNode( "B1" ), true );
3744             if ( t15.getNumberOfExternalNodes() != 10 ) {
3745                 return false;
3746             }
3747             t15.deleteSubtree( t15.getNode( "B3" ), true );
3748             if ( t15.getNumberOfExternalNodes() != 9 ) {
3749                 return false;
3750             }
3751             t15.deleteSubtree( t15.getNode( "B4" ), true );
3752             if ( t15.getNumberOfExternalNodes() != 8 ) {
3753                 return false;
3754             }
3755             t15.deleteSubtree( t15.getNode( "A1" ), true );
3756             if ( t15.getNumberOfExternalNodes() != 7 ) {
3757                 return false;
3758             }
3759             t15.deleteSubtree( t15.getNode( "C4" ), true );
3760             if ( t15.getNumberOfExternalNodes() != 6 ) {
3761                 return false;
3762             }
3763         }
3764         catch ( final Exception e ) {
3765             e.printStackTrace( System.out );
3766             return false;
3767         }
3768         return true;
3769     }
3770
3771     private static boolean testDescriptiveStatistics() {
3772         try {
3773             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3774             dss1.addValue( 82 );
3775             dss1.addValue( 78 );
3776             dss1.addValue( 70 );
3777             dss1.addValue( 58 );
3778             dss1.addValue( 42 );
3779             if ( dss1.getN() != 5 ) {
3780                 return false;
3781             }
3782             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3783                 return false;
3784             }
3785             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3786                 return false;
3787             }
3788             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3789                 return false;
3790             }
3791             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3792                 return false;
3793             }
3794             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3795                 return false;
3796             }
3797             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3798                 return false;
3799             }
3800             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3801                 return false;
3802             }
3803             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3804                 return false;
3805             }
3806             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3807                 return false;
3808             }
3809             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3810                 return false;
3811             }
3812             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3813                 return false;
3814             }
3815             dss1.addValue( 123 );
3816             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3817                 return false;
3818             }
3819             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3820                 return false;
3821             }
3822             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3823                 return false;
3824             }
3825             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3826             dss2.addValue( -1.85 );
3827             dss2.addValue( 57.5 );
3828             dss2.addValue( 92.78 );
3829             dss2.addValue( 57.78 );
3830             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3831                 return false;
3832             }
3833             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3834                 return false;
3835             }
3836             final double[] a = dss2.getDataAsDoubleArray();
3837             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3838                 return false;
3839             }
3840             dss2.addValue( -100 );
3841             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3842                 return false;
3843             }
3844             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3845                 return false;
3846             }
3847             final double[] ds = new double[ 14 ];
3848             ds[ 0 ] = 34;
3849             ds[ 1 ] = 23;
3850             ds[ 2 ] = 1;
3851             ds[ 3 ] = 32;
3852             ds[ 4 ] = 11;
3853             ds[ 5 ] = 2;
3854             ds[ 6 ] = 12;
3855             ds[ 7 ] = 33;
3856             ds[ 8 ] = 13;
3857             ds[ 9 ] = 22;
3858             ds[ 10 ] = 21;
3859             ds[ 11 ] = 35;
3860             ds[ 12 ] = 24;
3861             ds[ 13 ] = 31;
3862             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3863             if ( bins.length != 4 ) {
3864                 return false;
3865             }
3866             if ( bins[ 0 ] != 2 ) {
3867                 return false;
3868             }
3869             if ( bins[ 1 ] != 3 ) {
3870                 return false;
3871             }
3872             if ( bins[ 2 ] != 4 ) {
3873                 return false;
3874             }
3875             if ( bins[ 3 ] != 5 ) {
3876                 return false;
3877             }
3878             final double[] ds1 = new double[ 9 ];
3879             ds1[ 0 ] = 10.0;
3880             ds1[ 1 ] = 19.0;
3881             ds1[ 2 ] = 9.999;
3882             ds1[ 3 ] = 0.0;
3883             ds1[ 4 ] = 39.9;
3884             ds1[ 5 ] = 39.999;
3885             ds1[ 6 ] = 30.0;
3886             ds1[ 7 ] = 19.999;
3887             ds1[ 8 ] = 30.1;
3888             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3889             if ( bins1.length != 4 ) {
3890                 return false;
3891             }
3892             if ( bins1[ 0 ] != 2 ) {
3893                 return false;
3894             }
3895             if ( bins1[ 1 ] != 3 ) {
3896                 return false;
3897             }
3898             if ( bins1[ 2 ] != 0 ) {
3899                 return false;
3900             }
3901             if ( bins1[ 3 ] != 4 ) {
3902                 return false;
3903             }
3904             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3905             if ( bins1_1.length != 3 ) {
3906                 return false;
3907             }
3908             if ( bins1_1[ 0 ] != 3 ) {
3909                 return false;
3910             }
3911             if ( bins1_1[ 1 ] != 2 ) {
3912                 return false;
3913             }
3914             if ( bins1_1[ 2 ] != 4 ) {
3915                 return false;
3916             }
3917             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3918             if ( bins1_2.length != 3 ) {
3919                 return false;
3920             }
3921             if ( bins1_2[ 0 ] != 2 ) {
3922                 return false;
3923             }
3924             if ( bins1_2[ 1 ] != 2 ) {
3925                 return false;
3926             }
3927             if ( bins1_2[ 2 ] != 2 ) {
3928                 return false;
3929             }
3930             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3931             dss3.addValue( 1 );
3932             dss3.addValue( 1 );
3933             dss3.addValue( 1 );
3934             dss3.addValue( 2 );
3935             dss3.addValue( 3 );
3936             dss3.addValue( 4 );
3937             dss3.addValue( 5 );
3938             dss3.addValue( 5 );
3939             dss3.addValue( 5 );
3940             dss3.addValue( 6 );
3941             dss3.addValue( 7 );
3942             dss3.addValue( 8 );
3943             dss3.addValue( 9 );
3944             dss3.addValue( 10 );
3945             dss3.addValue( 10 );
3946             dss3.addValue( 10 );
3947             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3948             histo.toStringBuffer( 10, '=', 40, 5 );
3949             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3950         }
3951         catch ( final Exception e ) {
3952             e.printStackTrace( System.out );
3953             return false;
3954         }
3955         return true;
3956     }
3957
3958     private static boolean testDir( final String file ) {
3959         try {
3960             final File f = new File( file );
3961             if ( !f.exists() ) {
3962                 return false;
3963             }
3964             if ( !f.isDirectory() ) {
3965                 return false;
3966             }
3967             if ( !f.canRead() ) {
3968                 return false;
3969             }
3970         }
3971         catch ( final Exception e ) {
3972             return false;
3973         }
3974         return true;
3975     }
3976
3977     private static boolean testEbiEntryRetrieval() {
3978         try {
3979             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3980             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3981                 System.out.println( entry.getAccession() );
3982                 return false;
3983             }
3984             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3985                 System.out.println( entry.getTaxonomyScientificName() );
3986                 return false;
3987             }
3988             if ( !entry.getSequenceName()
3989                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3990                 System.out.println( entry.getSequenceName() );
3991                 return false;
3992             }
3993             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3994             //     System.out.println( entry.getSequenceSymbol() );
3995             //     return false;
3996             // }
3997             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3998                 System.out.println( entry.getGeneName() );
3999                 return false;
4000             }
4001             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4002                 System.out.println( entry.getTaxonomyIdentifier() );
4003                 return false;
4004             }
4005             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4006                 System.out.println( entry.getAnnotations().first().getRefValue() );
4007                 return false;
4008             }
4009             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4010                 System.out.println( entry.getAnnotations().first().getRefSource() );
4011                 return false;
4012             }
4013             if ( entry.getCrossReferences().size() != 5 ) {
4014                 return false;
4015             }
4016             //
4017             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4018             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4019                 return false;
4020             }
4021             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4022                 System.out.println( entry1.getTaxonomyScientificName() );
4023                 return false;
4024             }
4025             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4026                 System.out.println( entry1.getSequenceName() );
4027                 return false;
4028             }
4029             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4030                 System.out.println( entry1.getTaxonomyIdentifier() );
4031                 return false;
4032             }
4033             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4034                 System.out.println( entry1.getGeneName() );
4035                 return false;
4036             }
4037             if ( entry1.getCrossReferences().size() != 6 ) {
4038                 return false;
4039             }
4040             //
4041             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4042             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4043                 return false;
4044             }
4045             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4046                 System.out.println( entry2.getTaxonomyScientificName() );
4047                 return false;
4048             }
4049             if ( !entry2.getSequenceName()
4050                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4051                 System.out.println( entry2.getSequenceName() );
4052                 return false;
4053             }
4054             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4055                 System.out.println( entry2.getTaxonomyIdentifier() );
4056                 return false;
4057             }
4058             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4059                 System.out.println( entry2.getGeneName() );
4060                 return false;
4061             }
4062             if ( entry2.getCrossReferences().size() != 3 ) {
4063                 return false;
4064             }
4065             //
4066             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4067             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4068                 return false;
4069             }
4070             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4071                 System.out.println( entry3.getTaxonomyScientificName() );
4072                 return false;
4073             }
4074             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4075                 System.out.println( entry3.getSequenceName() );
4076                 return false;
4077             }
4078             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4079                 System.out.println( entry3.getTaxonomyIdentifier() );
4080                 return false;
4081             }
4082             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4083                 System.out.println( entry3.getSequenceSymbol() );
4084                 return false;
4085             }
4086             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4087                 return false;
4088             }
4089             if ( entry3.getCrossReferences().size() != 8 ) {
4090                 return false;
4091             }
4092             //
4093             //
4094             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4095             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4096                 return false;
4097             }
4098             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4099                 System.out.println( entry4.getTaxonomyScientificName() );
4100                 return false;
4101             }
4102             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4103                 System.out.println( entry4.getSequenceName() );
4104                 return false;
4105             }
4106             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4107                 System.out.println( entry4.getTaxonomyIdentifier() );
4108                 return false;
4109             }
4110             if ( !entry4.getGeneName().equals( "ras" ) ) {
4111                 System.out.println( entry4.getGeneName() );
4112                 return false;
4113             }
4114             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4115             //     System.out.println( entry4.getChromosome() );
4116             //     return false;
4117             // }
4118             // if ( !entry4.getMap().equals( "ras" ) ) {
4119             //     System.out.println( entry4.getMap() );
4120             //     return false;
4121             // }
4122             //TODO FIXME gi...
4123             //
4124             //TODO fails:
4125             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4126             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4127             //                return false;
4128             //            }
4129             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4130             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4131                 return false;
4132             }
4133             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4134                 System.out.println( entry5.getTaxonomyScientificName() );
4135                 return false;
4136             }
4137             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4138                 System.out.println( entry5.getSequenceName() );
4139                 return false;
4140             }
4141             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4142                 System.out.println( entry5.getTaxonomyIdentifier() );
4143                 return false;
4144             }
4145         }
4146         catch ( final IOException e ) {
4147             System.out.println();
4148             System.out.println( "the following might be due to absence internet connection:" );
4149             e.printStackTrace( System.out );
4150             return true;
4151         }
4152         catch ( final Exception e ) {
4153             e.printStackTrace();
4154             return false;
4155         }
4156         return true;
4157     }
4158
4159     private static boolean testExternalNodeRelatedMethods() {
4160         try {
4161             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4162             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4163             PhylogenyNode n = t1.getNode( "A" );
4164             n = n.getNextExternalNode();
4165             if ( !n.getName().equals( "B" ) ) {
4166                 return false;
4167             }
4168             n = n.getNextExternalNode();
4169             if ( !n.getName().equals( "C" ) ) {
4170                 return false;
4171             }
4172             n = n.getNextExternalNode();
4173             if ( !n.getName().equals( "D" ) ) {
4174                 return false;
4175             }
4176             n = t1.getNode( "B" );
4177             while ( !n.isLastExternalNode() ) {
4178                 n = n.getNextExternalNode();
4179             }
4180             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4181             n = t2.getNode( "A" );
4182             n = n.getNextExternalNode();
4183             if ( !n.getName().equals( "B" ) ) {
4184                 return false;
4185             }
4186             n = n.getNextExternalNode();
4187             if ( !n.getName().equals( "C" ) ) {
4188                 return false;
4189             }
4190             n = n.getNextExternalNode();
4191             if ( !n.getName().equals( "D" ) ) {
4192                 return false;
4193             }
4194             n = t2.getNode( "B" );
4195             while ( !n.isLastExternalNode() ) {
4196                 n = n.getNextExternalNode();
4197             }
4198             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4199             n = t3.getNode( "A" );
4200             n = n.getNextExternalNode();
4201             if ( !n.getName().equals( "B" ) ) {
4202                 return false;
4203             }
4204             n = n.getNextExternalNode();
4205             if ( !n.getName().equals( "C" ) ) {
4206                 return false;
4207             }
4208             n = n.getNextExternalNode();
4209             if ( !n.getName().equals( "D" ) ) {
4210                 return false;
4211             }
4212             n = n.getNextExternalNode();
4213             if ( !n.getName().equals( "E" ) ) {
4214                 return false;
4215             }
4216             n = n.getNextExternalNode();
4217             if ( !n.getName().equals( "F" ) ) {
4218                 return false;
4219             }
4220             n = n.getNextExternalNode();
4221             if ( !n.getName().equals( "G" ) ) {
4222                 return false;
4223             }
4224             n = n.getNextExternalNode();
4225             if ( !n.getName().equals( "H" ) ) {
4226                 return false;
4227             }
4228             n = t3.getNode( "B" );
4229             while ( !n.isLastExternalNode() ) {
4230                 n = n.getNextExternalNode();
4231             }
4232             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4233             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4234                 final PhylogenyNode node = iter.next();
4235             }
4236             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4237             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4238                 final PhylogenyNode node = iter.next();
4239             }
4240             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4241             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4242             if ( !iter.next().getName().equals( "A" ) ) {
4243                 return false;
4244             }
4245             if ( !iter.next().getName().equals( "B" ) ) {
4246                 return false;
4247             }
4248             if ( !iter.next().getName().equals( "C" ) ) {
4249                 return false;
4250             }
4251             if ( !iter.next().getName().equals( "D" ) ) {
4252                 return false;
4253             }
4254             if ( !iter.next().getName().equals( "E" ) ) {
4255                 return false;
4256             }
4257             if ( !iter.next().getName().equals( "F" ) ) {
4258                 return false;
4259             }
4260             if ( iter.hasNext() ) {
4261                 return false;
4262             }
4263         }
4264         catch ( final Exception e ) {
4265             e.printStackTrace( System.out );
4266             return false;
4267         }
4268         return true;
4269     }
4270
4271     private static boolean testExtractSNFromNodeName() {
4272         try {
4273             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4274                 return false;
4275             }
4276             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4277                 return false;
4278             }
4279             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4280                 return false;
4281             }
4282             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4283                     .equals( "Mus musculus musculus" ) ) {
4284                 return false;
4285             }
4286             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4287                     .equals( "Mus musculus musculus" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4291                     .equals( "Mus musculus musculus" ) ) {
4292                 return false;
4293             }
4294             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4295                     .equals( "Mus musculus musculus" ) ) {
4296                 return false;
4297             }
4298             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4299                 return false;
4300             }
4301             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4302                     .equals( "Mus musculus musculus" ) ) {
4303                 return false;
4304             }
4305             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4306                     .equals( "Mus musculus musculus" ) ) {
4307                 return false;
4308             }
4309             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4310                 return false;
4311             }
4312             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4313                 return false;
4314             }
4315             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4316                 return false;
4317             }
4318             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4319                 return false;
4320             }
4321             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4322                     .equals( "Mus musculus musculus" ) ) {
4323                 return false;
4324             }
4325             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4326                 return false;
4327             }
4328             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4332                 return false;
4333             }
4334             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4335                 return false;
4336             }
4337             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4338                 return false;
4339             }
4340             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4341                 return false;
4342             }
4343             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4344                 return false;
4345             }
4346             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4347                 return false;
4348             }
4349             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4350                     .equals( "Mus musculus" ) ) {
4351                 return false;
4352             }
4353             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4354                     .equals( "Mus musculus" ) ) {
4355                 return false;
4356             }
4357             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4361                     .equals( "Mus musculus musculus" ) ) {
4362                 return false;
4363             }
4364             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4365                     .equals( "Mus musculus musculus" ) ) {
4366                 return false;
4367             }
4368             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4369                     .equals( "Mus musculus musculus" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4376                     .equals( "Pilostyles mexicana" ) ) {
4377                 return false;
4378             }
4379             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4380                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4381                 return false;
4382             }
4383             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4384                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4385                 return false;
4386             }
4387             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4388                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4392                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4396                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4397                 return false;
4398             }
4399             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4400                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4401                 return false;
4402             }
4403             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4404                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4405                 return false;
4406             }
4407             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4408                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4409                 return false;
4410             }
4411             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4412                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4413                 return false;
4414             }
4415             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4416                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4417                 return false;
4418             }
4419             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4420                     .equals( "Escherichia coli (strain K12)" ) ) {
4421                 return false;
4422             }
4423             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4424                     .equals( "Escherichia coli (strain K12)" ) ) {
4425                 return false;
4426             }
4427             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4428                     .equals( "Escherichia coli (str. K12)" ) ) {
4429                 return false;
4430             }
4431             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4432                     .equals( "Escherichia coli (str. K12)" ) ) {
4433                 return false;
4434             }
4435             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4436                     .equals( "Escherichia coli (str. K12)" ) ) {
4437                 return false;
4438             }
4439             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4440                     .equals( "Escherichia coli (var. K12)" ) ) {
4441                 return false;
4442             }
4443             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4444                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4445                 return false;
4446             }
4447             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4448                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4449                 return false;
4450             }
4451             if ( !ParserUtils
4452                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4453                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4454                 return false;
4455             }
4456             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4457                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4458                 return false;
4459             }
4460             if ( !ParserUtils
4461                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4462                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4463                 return false;
4464             }
4465             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4466                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4467                 return false;
4468             }
4469             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4470                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4471                 return false;
4472             }
4473             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4477                 return false;
4478             }
4479             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4480                 return false;
4481             }
4482             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4483                     .equals( "Macrocera sp." ) ) {
4484                 return false;
4485             }
4486             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4490                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4494                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4495                 return false;
4496             }
4497             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4498                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4499                 return false;
4500             }
4501             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4502                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4503                 return false;
4504             }
4505         }
4506         catch ( final Exception e ) {
4507             e.printStackTrace( System.out );
4508             return false;
4509         }
4510         return true;
4511     }
4512
4513     private static boolean testExtractTaxonomyCodeFromNodeName() {
4514         try {
4515             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4516                 return false;
4517             }
4518             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4519                     .equals( "SOYBN" ) ) {
4520                 return false;
4521             }
4522             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4523                     .equals( "ARATH" ) ) {
4524                 return false;
4525             }
4526             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4527                     .equals( "ARATH" ) ) {
4528                 return false;
4529             }
4530             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4531                 return false;
4532             }
4533             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4534                 return false;
4535             }
4536             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4537                 return false;
4538             }
4539             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4540                     .equals( "SOYBN" ) ) {
4541                 return false;
4542             }
4543             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4544                     .equals( "SOYBN" ) ) {
4545                 return false;
4546             }
4547             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4548                     .equals( "SOYBN" ) ) {
4549                 return false;
4550             }
4551             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4552                     .equals( "SOYBN" ) ) {
4553                 return false;
4554             }
4555             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4556                     .equals( "SOYBN" ) ) {
4557                 return false;
4558             }
4559             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4560                     .equals( "SOYBN" ) ) {
4561                 return false;
4562             }
4563             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4564                     .equals( "SOYBN" ) ) {
4565                 return false;
4566             }
4567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4568                     .equals( "SOYBN" ) ) {
4569                 return false;
4570             }
4571             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4572                 return false;
4573             }
4574             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4575                     .equals( "SOYBN" ) ) {
4576                 return false;
4577             }
4578             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4579                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4580                 return false;
4581             }
4582             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4583                     .equals( "9YX45" ) ) {
4584                 return false;
4585             }
4586             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4587                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4588                     .equals( "MOUSE" ) ) {
4589                 return false;
4590             }
4591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4592                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4593                     .equals( "MOUSE" ) ) {
4594                 return false;
4595             }
4596             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4597                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4598                     .equals( "MOUSE" ) ) {
4599                 return false;
4600             }
4601             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4602                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4603                 return false;
4604             }
4605             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4606                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4607                 return false;
4608             }
4609             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4610                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4611                 return false;
4612             }
4613             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4614                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4615                 return false;
4616             }
4617             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4618                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4619                 return false;
4620             }
4621             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4622                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4623                 return false;
4624             }
4625             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4626                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4627                 return false;
4628             }
4629             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4630                     .equals( "RAT" ) ) {
4631                 return false;
4632             }
4633             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4634                     .equals( "PIG" ) ) {
4635                 return false;
4636             }
4637             if ( !ParserUtils
4638                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4639                     .equals( "MOUSE" ) ) {
4640                 return false;
4641             }
4642             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4643                     .equals( "MOUSE" ) ) {
4644                 return false;
4645             }
4646             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4647                 return false;
4648             }
4649         }
4650         catch ( final Exception e ) {
4651             e.printStackTrace( System.out );
4652             return false;
4653         }
4654         return true;
4655     }
4656
4657     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4658         try {
4659             PhylogenyNode n = new PhylogenyNode();
4660             n.setName( "tr|B3RJ64" );
4661             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4662                 return false;
4663             }
4664             n.setName( "tr.B3RJ64" );
4665             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4666                 return false;
4667             }
4668             n.setName( "tr=B3RJ64" );
4669             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4670                 return false;
4671             }
4672             n.setName( "tr-B3RJ64" );
4673             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4674                 return false;
4675             }
4676             n.setName( "tr/B3RJ64" );
4677             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4678                 return false;
4679             }
4680             n.setName( "tr\\B3RJ64" );
4681             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4682                 return false;
4683             }
4684             n.setName( "tr_B3RJ64" );
4685             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4686                 return false;
4687             }
4688             n.setName( " tr|B3RJ64 " );
4689             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4690                 return false;
4691             }
4692             n.setName( "-tr|B3RJ64-" );
4693             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4694                 return false;
4695             }
4696             n.setName( "-tr=B3RJ64-" );
4697             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4698                 return false;
4699             }
4700             n.setName( "_tr=B3RJ64_" );
4701             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4702                 return false;
4703             }
4704             n.setName( " tr_tr|B3RJ64_sp|123 " );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4706                 return false;
4707             }
4708             n.setName( "B3RJ64" );
4709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4710                 return false;
4711             }
4712             n.setName( "sp|B3RJ64" );
4713             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4714                 return false;
4715             }
4716             n.setName( "sp|B3RJ64C" );
4717             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4718                 return false;
4719             }
4720             n.setName( "sp B3RJ64" );
4721             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4722                 return false;
4723             }
4724             n.setName( "sp|B3RJ6X" );
4725             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4726                 return false;
4727             }
4728             n.setName( "sp|B3RJ6" );
4729             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4730                 return false;
4731             }
4732             n.setName( "K1PYK7_CRAGI" );
4733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4734                 return false;
4735             }
4736             n.setName( "K1PYK7_PEA" );
4737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4738                 return false;
4739             }
4740             n.setName( "K1PYK7_RAT" );
4741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4742                 return false;
4743             }
4744             n.setName( "K1PYK7_PIG" );
4745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4746                 return false;
4747             }
4748             n.setName( "~K1PYK7_PIG~" );
4749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4750                 return false;
4751             }
4752             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4753             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4754                 return false;
4755             }
4756             n.setName( "K1PYKX_CRAGI" );
4757             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4758                 return false;
4759             }
4760             n.setName( "XXXXX_CRAGI" );
4761             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4762                 return false;
4763             }
4764             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4765             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4766                 return false;
4767             }
4768             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4769             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4770                 return false;
4771             }
4772             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4774                 return false;
4775             }
4776             n = new PhylogenyNode();
4777             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4778             seq.setSymbol( "K1PYK7_CRAGI" );
4779             n.getNodeData().addSequence( seq );
4780             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4781                 return false;
4782             }
4783             seq.setSymbol( "tr|B3RJ64" );
4784             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4785                 return false;
4786             }
4787             n = new PhylogenyNode();
4788             seq = new org.forester.phylogeny.data.Sequence();
4789             seq.setName( "K1PYK7_CRAGI" );
4790             n.getNodeData().addSequence( seq );
4791             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4792                 return false;
4793             }
4794             seq.setName( "tr|B3RJ64" );
4795             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4796                 return false;
4797             }
4798             n = new PhylogenyNode();
4799             seq = new org.forester.phylogeny.data.Sequence();
4800             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4801             n.getNodeData().addSequence( seq );
4802             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4803                 return false;
4804             }
4805             n = new PhylogenyNode();
4806             seq = new org.forester.phylogeny.data.Sequence();
4807             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4808             n.getNodeData().addSequence( seq );
4809             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4810                 return false;
4811             }
4812             //
4813             n = new PhylogenyNode();
4814             n.setName( "ACP19736" );
4815             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4816                 return false;
4817             }
4818             n = new PhylogenyNode();
4819             n.setName( "|ACP19736|" );
4820             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4821                 return false;
4822             }
4823         }
4824         catch ( final Exception e ) {
4825             e.printStackTrace( System.out );
4826             return false;
4827         }
4828         return true;
4829     }
4830
4831     private static boolean testFastaParser() {
4832         try {
4833             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4834                 return false;
4835             }
4836             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4837                 return false;
4838             }
4839             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4840             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4841                 return false;
4842             }
4843             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4844                 return false;
4845             }
4846             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4847                 return false;
4848             }
4849             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4850                 return false;
4851             }
4852             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4853                 return false;
4854             }
4855             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4856                 return false;
4857             }
4858         }
4859         catch ( final Exception e ) {
4860             e.printStackTrace();
4861             return false;
4862         }
4863         return true;
4864     }
4865
4866     private static boolean testGenbankAccessorParsing() {
4867         //The format for GenBank Accession numbers are:
4868         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4869         //Protein:    3 letters + 5 numerals
4870         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4871         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4872             return false;
4873         }
4874         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4875             return false;
4876         }
4877         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4878             return false;
4879         }
4880         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4881             return false;
4882         }
4883         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4884             return false;
4885         }
4886         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4887             return false;
4888         }
4889         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4890             return false;
4891         }
4892         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4893             return false;
4894         }
4895         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4896             return false;
4897         }
4898         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4899             return false;
4900         }
4901         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4902             return false;
4903         }
4904         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4905             return false;
4906         }
4907         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4908             return false;
4909         }
4910         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4911             return false;
4912         }
4913         return true;
4914     }
4915
4916     private static boolean testGeneralMsaParser() {
4917         try {
4918             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4919             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4920             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4921             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4922             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4923             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4924             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4925             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4926             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4927                 return false;
4928             }
4929             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4930                 return false;
4931             }
4932             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4933                 return false;
4934             }
4935             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4936                 return false;
4937             }
4938             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4939                 return false;
4940             }
4941             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4942                 return false;
4943             }
4944             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4945                 return false;
4946             }
4947             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4948                 return false;
4949             }
4950             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4951                 return false;
4952             }
4953             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4954                 return false;
4955             }
4956             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4957                 return false;
4958             }
4959             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4960                 return false;
4961             }
4962             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4963             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4964                 return false;
4965             }
4966             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4967                 return false;
4968             }
4969             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4970                 return false;
4971             }
4972             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4973             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4974                 return false;
4975             }
4976             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4977                 return false;
4978             }
4979             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4980                 return false;
4981             }
4982             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4983             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4984                 return false;
4985             }
4986             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4987                 return false;
4988             }
4989             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4990                 return false;
4991             }
4992         }
4993         catch ( final Exception e ) {
4994             e.printStackTrace();
4995             return false;
4996         }
4997         return true;
4998     }
4999
5000     private static boolean testGeneralTable() {
5001         try {
5002             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5003             t0.setValue( 3, 2, "23" );
5004             t0.setValue( 10, 1, "error" );
5005             t0.setValue( 10, 1, "110" );
5006             t0.setValue( 9, 1, "19" );
5007             t0.setValue( 1, 10, "101" );
5008             t0.setValue( 10, 10, "1010" );
5009             t0.setValue( 100, 10, "10100" );
5010             t0.setValue( 0, 0, "00" );
5011             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5012                 return false;
5013             }
5014             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5015                 return false;
5016             }
5017             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5018                 return false;
5019             }
5020             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5021                 return false;
5022             }
5023             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5024                 return false;
5025             }
5026             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5027                 return false;
5028             }
5029             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5030                 return false;
5031             }
5032             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5033                 return false;
5034             }
5035             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5036                 return false;
5037             }
5038             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5039             t1.setValue( "3", "2", "23" );
5040             t1.setValue( "10", "1", "error" );
5041             t1.setValue( "10", "1", "110" );
5042             t1.setValue( "9", "1", "19" );
5043             t1.setValue( "1", "10", "101" );
5044             t1.setValue( "10", "10", "1010" );
5045             t1.setValue( "100", "10", "10100" );
5046             t1.setValue( "0", "0", "00" );
5047             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5048             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5049                 return false;
5050             }
5051             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5052                 return false;
5053             }
5054             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5055                 return false;
5056             }
5057             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5058                 return false;
5059             }
5060             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5061                 return false;
5062             }
5063             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5064                 return false;
5065             }
5066             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5067                 return false;
5068             }
5069             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5070                 return false;
5071             }
5072             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5073                 return false;
5074             }
5075             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5076                 return false;
5077             }
5078         }
5079         catch ( final Exception e ) {
5080             e.printStackTrace( System.out );
5081             return false;
5082         }
5083         return true;
5084     }
5085
5086     private static boolean testGetDistance() {
5087         try {
5088             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5089             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",
5090                                                  new NHXParser() )[ 0 ];
5091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5095                 return false;
5096             }
5097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5098                 return false;
5099             }
5100             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5101                 return false;
5102             }
5103             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5104                 return false;
5105             }
5106             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5107                 return false;
5108             }
5109             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5110                 return false;
5111             }
5112             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5113                 return false;
5114             }
5115             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5116                 return false;
5117             }
5118             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5119                 return false;
5120             }
5121             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5122                 return false;
5123             }
5124             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5125                 return false;
5126             }
5127             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5128                 return false;
5129             }
5130             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5131                 return false;
5132             }
5133             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5134                 return false;
5135             }
5136             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5137                 return false;
5138             }
5139             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5140                 return false;
5141             }
5142             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5143                 return false;
5144             }
5145             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5146                 return false;
5147             }
5148             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5149                 return false;
5150             }
5151             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5152                 return false;
5153             }
5154             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5155                 return false;
5156             }
5157             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5158                 return false;
5159             }
5160             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5161                 return false;
5162             }
5163             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5164                 return false;
5165             }
5166             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5167                 return false;
5168             }
5169             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5170                 return false;
5171             }
5172             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5173                 return false;
5174             }
5175             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5176                 return false;
5177             }
5178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5179                 return false;
5180             }
5181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5182                 return false;
5183             }
5184             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",
5185                                                  new NHXParser() )[ 0 ];
5186             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5187                 return false;
5188             }
5189             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5190                 return false;
5191             }
5192             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5193                 return false;
5194             }
5195             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5196                 return false;
5197             }
5198             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5199                 return false;
5200             }
5201             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5202                 return false;
5203             }
5204             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5205                 return false;
5206             }
5207             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5208                 return false;
5209             }
5210             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5211                 return false;
5212             }
5213             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5214                 return false;
5215             }
5216             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5217                 return false;
5218             }
5219         }
5220         catch ( final Exception e ) {
5221             e.printStackTrace( System.out );
5222             return false;
5223         }
5224         return true;
5225     }
5226
5227     private static boolean testGetLCA() {
5228         try {
5229             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5230             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5231                                                  new NHXParser() )[ 0 ];
5232             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5233             if ( !A.getName().equals( "A" ) ) {
5234                 return false;
5235             }
5236             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5237             if ( !gh.getName().equals( "gh" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5241             if ( !ab.getName().equals( "ab" ) ) {
5242                 return false;
5243             }
5244             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5245             if ( !ab2.getName().equals( "ab" ) ) {
5246                 return false;
5247             }
5248             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5249             if ( !gh2.getName().equals( "gh" ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5253             if ( !gh3.getName().equals( "gh" ) ) {
5254                 return false;
5255             }
5256             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5257             if ( !abc.getName().equals( "abc" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5261             if ( !abc2.getName().equals( "abc" ) ) {
5262                 return false;
5263             }
5264             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5265             if ( !abcd.getName().equals( "abcd" ) ) {
5266                 return false;
5267             }
5268             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5269             if ( !abcd2.getName().equals( "abcd" ) ) {
5270                 return false;
5271             }
5272             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5273             if ( !abcdef.getName().equals( "abcdef" ) ) {
5274                 return false;
5275             }
5276             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5277             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5281             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5285             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5286                 return false;
5287             }
5288             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5289             if ( !abcde.getName().equals( "abcde" ) ) {
5290                 return false;
5291             }
5292             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5293             if ( !abcde2.getName().equals( "abcde" ) ) {
5294                 return false;
5295             }
5296             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5297             if ( !r.getName().equals( "abcdefgh" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5301             if ( !r2.getName().equals( "abcdefgh" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5305             if ( !r3.getName().equals( "abcdefgh" ) ) {
5306                 return false;
5307             }
5308             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5309             if ( !abcde3.getName().equals( "abcde" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5313             if ( !abcde4.getName().equals( "abcde" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5317             if ( !ab3.getName().equals( "ab" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5321             if ( !ab4.getName().equals( "ab" ) ) {
5322                 return false;
5323             }
5324             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5325             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5326             if ( !cd.getName().equals( "cd" ) ) {
5327                 return false;
5328             }
5329             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5330             if ( !cd2.getName().equals( "cd" ) ) {
5331                 return false;
5332             }
5333             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5334             if ( !cde.getName().equals( "cde" ) ) {
5335                 return false;
5336             }
5337             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5338             if ( !cde2.getName().equals( "cde" ) ) {
5339                 return false;
5340             }
5341             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5342             if ( !cdef.getName().equals( "cdef" ) ) {
5343                 return false;
5344             }
5345             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5346             if ( !cdef2.getName().equals( "cdef" ) ) {
5347                 return false;
5348             }
5349             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5350             if ( !cdef3.getName().equals( "cdef" ) ) {
5351                 return false;
5352             }
5353             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5354             if ( !rt.getName().equals( "r" ) ) {
5355                 return false;
5356             }
5357             final Phylogeny p3 = factory
5358                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5359                              new NHXParser() )[ 0 ];
5360             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5361             if ( !bc_3.getName().equals( "bc" ) ) {
5362                 return false;
5363             }
5364             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5365             if ( !ac_3.getName().equals( "abc" ) ) {
5366                 return false;
5367             }
5368             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5369             if ( !ad_3.getName().equals( "abcde" ) ) {
5370                 return false;
5371             }
5372             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5373             if ( !af_3.getName().equals( "abcdef" ) ) {
5374                 return false;
5375             }
5376             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5377             if ( !ag_3.getName().equals( "" ) ) {
5378                 return false;
5379             }
5380             if ( !ag_3.isRoot() ) {
5381                 return false;
5382             }
5383             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5384             if ( !al_3.getName().equals( "" ) ) {
5385                 return false;
5386             }
5387             if ( !al_3.isRoot() ) {
5388                 return false;
5389             }
5390             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5391             if ( !kl_3.getName().equals( "" ) ) {
5392                 return false;
5393             }
5394             if ( !kl_3.isRoot() ) {
5395                 return false;
5396             }
5397             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5398             if ( !fl_3.getName().equals( "" ) ) {
5399                 return false;
5400             }
5401             if ( !fl_3.isRoot() ) {
5402                 return false;
5403             }
5404             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5405             if ( !gk_3.getName().equals( "ghijk" ) ) {
5406                 return false;
5407             }
5408             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5409             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5410             if ( !r_4.getName().equals( "r" ) ) {
5411                 return false;
5412             }
5413             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5414             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5415             if ( !r_5.getName().equals( "root" ) ) {
5416                 return false;
5417             }
5418             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5419             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5420             if ( !r_6.getName().equals( "rot" ) ) {
5421                 return false;
5422             }
5423             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5424             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5425             if ( !r_7.getName().equals( "rott" ) ) {
5426                 return false;
5427             }
5428         }
5429         catch ( final Exception e ) {
5430             e.printStackTrace( System.out );
5431             return false;
5432         }
5433         return true;
5434     }
5435
5436     private static boolean testGetLCA2() {
5437         try {
5438             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5439             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5440             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5441             PhylogenyMethods.preOrderReId( p_a );
5442             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5443                                                                                               p_a.getNode( "a" ) );
5444             if ( !p_a_1.getName().equals( "a" ) ) {
5445                 return false;
5446             }
5447             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5448             PhylogenyMethods.preOrderReId( p_b );
5449             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5450                                                                                               p_b.getNode( "a" ) );
5451             if ( !p_b_1.getName().equals( "b" ) ) {
5452                 return false;
5453             }
5454             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5455                                                                                               p_b.getNode( "b" ) );
5456             if ( !p_b_2.getName().equals( "b" ) ) {
5457                 return false;
5458             }
5459             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5460             PhylogenyMethods.preOrderReId( p_c );
5461             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5462                                                                                               p_c.getNode( "a" ) );
5463             if ( !p_c_1.getName().equals( "b" ) ) {
5464                 return false;
5465             }
5466             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5467                                                                                               p_c.getNode( "c" ) );
5468             if ( !p_c_2.getName().equals( "c" ) ) {
5469                 System.out.println( p_c_2.getName() );
5470                 System.exit( -1 );
5471                 return false;
5472             }
5473             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5474                                                                                               p_c.getNode( "b" ) );
5475             if ( !p_c_3.getName().equals( "b" ) ) {
5476                 return false;
5477             }
5478             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5479                                                                                               p_c.getNode( "a" ) );
5480             if ( !p_c_4.getName().equals( "c" ) ) {
5481                 return false;
5482             }
5483             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5484                                                  new NHXParser() )[ 0 ];
5485             PhylogenyMethods.preOrderReId( p1 );
5486             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5487                                                                                           p1.getNode( "A" ) );
5488             if ( !A.getName().equals( "A" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5492                                                                                            p1.getNode( "gh" ) );
5493             if ( !gh.getName().equals( "gh" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5497                                                                                            p1.getNode( "B" ) );
5498             if ( !ab.getName().equals( "ab" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5502                                                                                             p1.getNode( "A" ) );
5503             if ( !ab2.getName().equals( "ab" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5507                                                                                             p1.getNode( "G" ) );
5508             if ( !gh2.getName().equals( "gh" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5512                                                                                             p1.getNode( "H" ) );
5513             if ( !gh3.getName().equals( "gh" ) ) {
5514                 return false;
5515             }
5516             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5517                                                                                             p1.getNode( "A" ) );
5518             if ( !abc.getName().equals( "abc" ) ) {
5519                 return false;
5520             }
5521             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5522                                                                                              p1.getNode( "C" ) );
5523             if ( !abc2.getName().equals( "abc" ) ) {
5524                 return false;
5525             }
5526             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5527                                                                                              p1.getNode( "D" ) );
5528             if ( !abcd.getName().equals( "abcd" ) ) {
5529                 return false;
5530             }
5531             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5532                                                                                               p1.getNode( "A" ) );
5533             if ( !abcd2.getName().equals( "abcd" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5537                                                                                                p1.getNode( "F" ) );
5538             if ( !abcdef.getName().equals( "abcdef" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5542                                                                                                 p1.getNode( "A" ) );
5543             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5544                 return false;
5545             }
5546             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5547                                                                                                 p1.getNode( "F" ) );
5548             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5552                                                                                                 p1.getNode( "ab" ) );
5553             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5554                 return false;
5555             }
5556             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5557                                                                                               p1.getNode( "E" ) );
5558             if ( !abcde.getName().equals( "abcde" ) ) {
5559                 return false;
5560             }
5561             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5562                                                                                                p1.getNode( "A" ) );
5563             if ( !abcde2.getName().equals( "abcde" ) ) {
5564                 return false;
5565             }
5566             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5567                                                                                           p1.getNode( "abcdefgh" ) );
5568             if ( !r.getName().equals( "abcdefgh" ) ) {
5569                 return false;
5570             }
5571             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5572                                                                                            p1.getNode( "H" ) );
5573             if ( !r2.getName().equals( "abcdefgh" ) ) {
5574                 return false;
5575             }
5576             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5577                                                                                            p1.getNode( "A" ) );
5578             if ( !r3.getName().equals( "abcdefgh" ) ) {
5579                 return false;
5580             }
5581             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5582                                                                                                p1.getNode( "abcde" ) );
5583             if ( !abcde3.getName().equals( "abcde" ) ) {
5584                 return false;
5585             }
5586             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5587                                                                                                p1.getNode( "E" ) );
5588             if ( !abcde4.getName().equals( "abcde" ) ) {
5589                 return false;
5590             }
5591             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5592                                                                                             p1.getNode( "B" ) );
5593             if ( !ab3.getName().equals( "ab" ) ) {
5594                 return false;
5595             }
5596             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5597                                                                                             p1.getNode( "ab" ) );
5598             if ( !ab4.getName().equals( "ab" ) ) {
5599                 return false;
5600             }
5601             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5602             PhylogenyMethods.preOrderReId( p2 );
5603             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5604                                                                                            p2.getNode( "d" ) );
5605             if ( !cd.getName().equals( "cd" ) ) {
5606                 return false;
5607             }
5608             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5609                                                                                             p2.getNode( "c" ) );
5610             if ( !cd2.getName().equals( "cd" ) ) {
5611                 return false;
5612             }
5613             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5614                                                                                             p2.getNode( "e" ) );
5615             if ( !cde.getName().equals( "cde" ) ) {
5616                 return false;
5617             }
5618             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5619                                                                                              p2.getNode( "c" ) );
5620             if ( !cde2.getName().equals( "cde" ) ) {
5621                 return false;
5622             }
5623             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5624                                                                                              p2.getNode( "f" ) );
5625             if ( !cdef.getName().equals( "cdef" ) ) {
5626                 return false;
5627             }
5628             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5629                                                                                               p2.getNode( "f" ) );
5630             if ( !cdef2.getName().equals( "cdef" ) ) {
5631                 return false;
5632             }
5633             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5634                                                                                               p2.getNode( "d" ) );
5635             if ( !cdef3.getName().equals( "cdef" ) ) {
5636                 return false;
5637             }
5638             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5639                                                                                            p2.getNode( "a" ) );
5640             if ( !rt.getName().equals( "r" ) ) {
5641                 return false;
5642             }
5643             final Phylogeny p3 = factory
5644                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5645                              new NHXParser() )[ 0 ];
5646             PhylogenyMethods.preOrderReId( p3 );
5647             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5648                                                                                              p3.getNode( "c" ) );
5649             if ( !bc_3.getName().equals( "bc" ) ) {
5650                 return false;
5651             }
5652             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5653                                                                                              p3.getNode( "c" ) );
5654             if ( !ac_3.getName().equals( "abc" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5658                                                                                              p3.getNode( "d" ) );
5659             if ( !ad_3.getName().equals( "abcde" ) ) {
5660                 return false;
5661             }
5662             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5663                                                                                              p3.getNode( "f" ) );
5664             if ( !af_3.getName().equals( "abcdef" ) ) {
5665                 return false;
5666             }
5667             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5668                                                                                              p3.getNode( "g" ) );
5669             if ( !ag_3.getName().equals( "" ) ) {
5670                 return false;
5671             }
5672             if ( !ag_3.isRoot() ) {
5673                 return false;
5674             }
5675             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5676                                                                                              p3.getNode( "l" ) );
5677             if ( !al_3.getName().equals( "" ) ) {
5678                 return false;
5679             }
5680             if ( !al_3.isRoot() ) {
5681                 return false;
5682             }
5683             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5684                                                                                              p3.getNode( "l" ) );
5685             if ( !kl_3.getName().equals( "" ) ) {
5686                 return false;
5687             }
5688             if ( !kl_3.isRoot() ) {
5689                 return false;
5690             }
5691             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5692                                                                                              p3.getNode( "l" ) );
5693             if ( !fl_3.getName().equals( "" ) ) {
5694                 return false;
5695             }
5696             if ( !fl_3.isRoot() ) {
5697                 return false;
5698             }
5699             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5700                                                                                              p3.getNode( "k" ) );
5701             if ( !gk_3.getName().equals( "ghijk" ) ) {
5702                 return false;
5703             }
5704             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5705             PhylogenyMethods.preOrderReId( p4 );
5706             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5707                                                                                             p4.getNode( "c" ) );
5708             if ( !r_4.getName().equals( "r" ) ) {
5709                 return false;
5710             }
5711             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5712             PhylogenyMethods.preOrderReId( p5 );
5713             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5714                                                                                             p5.getNode( "c" ) );
5715             if ( !r_5.getName().equals( "root" ) ) {
5716                 return false;
5717             }
5718             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5719             PhylogenyMethods.preOrderReId( p6 );
5720             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5721                                                                                             p6.getNode( "a" ) );
5722             if ( !r_6.getName().equals( "rot" ) ) {
5723                 return false;
5724             }
5725             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5726             PhylogenyMethods.preOrderReId( p7 );
5727             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5728                                                                                             p7.getNode( "e" ) );
5729             if ( !r_7.getName().equals( "rott" ) ) {
5730                 return false;
5731             }
5732             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5733                                                                                              p7.getNode( "a" ) );
5734             if ( !r_71.getName().equals( "rott" ) ) {
5735                 return false;
5736             }
5737             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5738                                                                                              p7.getNode( "rott" ) );
5739             if ( !r_72.getName().equals( "rott" ) ) {
5740                 return false;
5741             }
5742             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5743                                                                                              p7.getNode( "a" ) );
5744             if ( !r_73.getName().equals( "rott" ) ) {
5745                 return false;
5746             }
5747             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5748                                                                                              p7.getNode( "rott" ) );
5749             if ( !r_74.getName().equals( "rott" ) ) {
5750                 return false;
5751             }
5752             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5753                                                                                              p7.getNode( "e" ) );
5754             if ( !r_75.getName().equals( "e" ) ) {
5755                 return false;
5756             }
5757         }
5758         catch ( final Exception e ) {
5759             e.printStackTrace( System.out );
5760             return false;
5761         }
5762         return true;
5763     }
5764
5765     private static boolean testHmmscanOutputParser() {
5766         final String test_dir = Test.PATH_TO_TEST_DATA;
5767         try {
5768             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5769                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5770             parser1.parse();
5771             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5772                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5773             final List<Protein> proteins = parser2.parse();
5774             if ( parser2.getProteinsEncountered() != 4 ) {
5775                 return false;
5776             }
5777             if ( proteins.size() != 4 ) {
5778                 return false;
5779             }
5780             if ( parser2.getDomainsEncountered() != 69 ) {
5781                 return false;
5782             }
5783             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5784                 return false;
5785             }
5786             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5787                 return false;
5788             }
5789             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5790                 return false;
5791             }
5792             final Protein p1 = proteins.get( 0 );
5793             if ( p1.getNumberOfProteinDomains() != 15 ) {
5794                 return false;
5795             }
5796             if ( p1.getLength() != 850 ) {
5797                 return false;
5798             }
5799             final Protein p2 = proteins.get( 1 );
5800             if ( p2.getNumberOfProteinDomains() != 51 ) {
5801                 return false;
5802             }
5803             if ( p2.getLength() != 1291 ) {
5804                 return false;
5805             }
5806             final Protein p3 = proteins.get( 2 );
5807             if ( p3.getNumberOfProteinDomains() != 2 ) {
5808                 return false;
5809             }
5810             final Protein p4 = proteins.get( 3 );
5811             if ( p4.getNumberOfProteinDomains() != 1 ) {
5812                 return false;
5813             }
5814             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5815                 return false;
5816             }
5817             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5818                 return false;
5819             }
5820             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5821                 return false;
5822             }
5823             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5824                 return false;
5825             }
5826             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5827                 return false;
5828             }
5829             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5830                 return false;
5831             }
5832             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5833                 return false;
5834             }
5835         }
5836         catch ( final Exception e ) {
5837             e.printStackTrace( System.out );
5838             return false;
5839         }
5840         return true;
5841     }
5842
5843     private static boolean testLastExternalNodeMethods() {
5844         try {
5845             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5846             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5847             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5848             final PhylogenyNode n1 = t0.getNode( "A" );
5849             if ( n1.isLastExternalNode() ) {
5850                 return false;
5851             }
5852             final PhylogenyNode n2 = t0.getNode( "B" );
5853             if ( n2.isLastExternalNode() ) {
5854                 return false;
5855             }
5856             final PhylogenyNode n3 = t0.getNode( "C" );
5857             if ( n3.isLastExternalNode() ) {
5858                 return false;
5859             }
5860             final PhylogenyNode n4 = t0.getNode( "D" );
5861             if ( !n4.isLastExternalNode() ) {
5862                 return false;
5863             }
5864         }
5865         catch ( final Exception e ) {
5866             e.printStackTrace( System.out );
5867             return false;
5868         }
5869         return true;
5870     }
5871
5872     private static boolean testLevelOrderIterator() {
5873         try {
5874             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5875             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5876             PhylogenyNodeIterator it0;
5877             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5878                 it0.next();
5879             }
5880             for( it0.reset(); it0.hasNext(); ) {
5881                 it0.next();
5882             }
5883             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5884             if ( !it.next().getName().equals( "r" ) ) {
5885                 return false;
5886             }
5887             if ( !it.next().getName().equals( "ab" ) ) {
5888                 return false;
5889             }
5890             if ( !it.next().getName().equals( "cd" ) ) {
5891                 return false;
5892             }
5893             if ( !it.next().getName().equals( "A" ) ) {
5894                 return false;
5895             }
5896             if ( !it.next().getName().equals( "B" ) ) {
5897                 return false;
5898             }
5899             if ( !it.next().getName().equals( "C" ) ) {
5900                 return false;
5901             }
5902             if ( !it.next().getName().equals( "D" ) ) {
5903                 return false;
5904             }
5905             if ( it.hasNext() ) {
5906                 return false;
5907             }
5908             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",
5909                                                  new NHXParser() )[ 0 ];
5910             PhylogenyNodeIterator it2;
5911             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5912                 it2.next();
5913             }
5914             for( it2.reset(); it2.hasNext(); ) {
5915                 it2.next();
5916             }
5917             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5918             if ( !it3.next().getName().equals( "r" ) ) {
5919                 return false;
5920             }
5921             if ( !it3.next().getName().equals( "abc" ) ) {
5922                 return false;
5923             }
5924             if ( !it3.next().getName().equals( "defg" ) ) {
5925                 return false;
5926             }
5927             if ( !it3.next().getName().equals( "A" ) ) {
5928                 return false;
5929             }
5930             if ( !it3.next().getName().equals( "B" ) ) {
5931                 return false;
5932             }
5933             if ( !it3.next().getName().equals( "C" ) ) {
5934                 return false;
5935             }
5936             if ( !it3.next().getName().equals( "D" ) ) {
5937                 return false;
5938             }
5939             if ( !it3.next().getName().equals( "E" ) ) {
5940                 return false;
5941             }
5942             if ( !it3.next().getName().equals( "F" ) ) {
5943                 return false;
5944             }
5945             if ( !it3.next().getName().equals( "G" ) ) {
5946                 return false;
5947             }
5948             if ( !it3.next().getName().equals( "1" ) ) {
5949                 return false;
5950             }
5951             if ( !it3.next().getName().equals( "2" ) ) {
5952                 return false;
5953             }
5954             if ( !it3.next().getName().equals( "3" ) ) {
5955                 return false;
5956             }
5957             if ( !it3.next().getName().equals( "4" ) ) {
5958                 return false;
5959             }
5960             if ( !it3.next().getName().equals( "5" ) ) {
5961                 return false;
5962             }
5963             if ( !it3.next().getName().equals( "6" ) ) {
5964                 return false;
5965             }
5966             if ( !it3.next().getName().equals( "f1" ) ) {
5967                 return false;
5968             }
5969             if ( !it3.next().getName().equals( "f2" ) ) {
5970                 return false;
5971             }
5972             if ( !it3.next().getName().equals( "f3" ) ) {
5973                 return false;
5974             }
5975             if ( !it3.next().getName().equals( "a" ) ) {
5976                 return false;
5977             }
5978             if ( !it3.next().getName().equals( "b" ) ) {
5979                 return false;
5980             }
5981             if ( !it3.next().getName().equals( "f21" ) ) {
5982                 return false;
5983             }
5984             if ( !it3.next().getName().equals( "X" ) ) {
5985                 return false;
5986             }
5987             if ( !it3.next().getName().equals( "Y" ) ) {
5988                 return false;
5989             }
5990             if ( !it3.next().getName().equals( "Z" ) ) {
5991                 return false;
5992             }
5993             if ( it3.hasNext() ) {
5994                 return false;
5995             }
5996             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5997             PhylogenyNodeIterator it4;
5998             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5999                 it4.next();
6000             }
6001             for( it4.reset(); it4.hasNext(); ) {
6002                 it4.next();
6003             }
6004             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6005             if ( !it5.next().getName().equals( "r" ) ) {
6006                 return false;
6007             }
6008             if ( !it5.next().getName().equals( "A" ) ) {
6009                 return false;
6010             }
6011             if ( !it5.next().getName().equals( "B" ) ) {
6012                 return false;
6013             }
6014             if ( !it5.next().getName().equals( "C" ) ) {
6015                 return false;
6016             }
6017             if ( !it5.next().getName().equals( "D" ) ) {
6018                 return false;
6019             }
6020             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6021             PhylogenyNodeIterator it6;
6022             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6023                 it6.next();
6024             }
6025             for( it6.reset(); it6.hasNext(); ) {
6026                 it6.next();
6027             }
6028             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6029             if ( !it7.next().getName().equals( "A" ) ) {
6030                 return false;
6031             }
6032             if ( it.hasNext() ) {
6033                 return false;
6034             }
6035         }
6036         catch ( final Exception e ) {
6037             e.printStackTrace( System.out );
6038             return false;
6039         }
6040         return true;
6041     }
6042
6043     private static boolean testMafft( final String path ) {
6044         try {
6045             final List<String> opts = new ArrayList<String>();
6046             opts.add( "--maxiterate" );
6047             opts.add( "1000" );
6048             opts.add( "--localpair" );
6049             opts.add( "--quiet" );
6050             Msa msa = null;
6051             final MsaInferrer mafft = Mafft.createInstance( path );
6052             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6053             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6054                 return false;
6055             }
6056             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6057                 return false;
6058             }
6059         }
6060         catch ( final Exception e ) {
6061             e.printStackTrace( System.out );
6062             return false;
6063         }
6064         return true;
6065     }
6066
6067     private static boolean testMidpointrooting() {
6068         try {
6069             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6070             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6071             PhylogenyMethods.midpointRoot( t0 );
6072             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6073                 return false;
6074             }
6075             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6076                 return false;
6077             }
6078             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6079                            1 ) ) {
6080                 return false;
6081             }
6082             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",
6083                                                  new NHXParser() )[ 0 ];
6084             if ( !t1.isRooted() ) {
6085                 return false;
6086             }
6087             PhylogenyMethods.midpointRoot( t1 );
6088             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6089                 return false;
6090             }
6091             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6092                 return false;
6093             }
6094             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6095                 return false;
6096             }
6097             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6098                 return false;
6099             }
6100             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6101                 return false;
6102             }
6103             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6104                 return false;
6105             }
6106             t1.reRoot( t1.getNode( "A" ) );
6107             PhylogenyMethods.midpointRoot( t1 );
6108             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6109                 return false;
6110             }
6111             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6112                 return false;
6113             }
6114             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6115                 return false;
6116             }
6117             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6118                 return false;
6119             }
6120             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6121                 System.exit( -1 );
6122                 return false;
6123             }
6124             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6125                 return false;
6126             }
6127         }
6128         catch ( final Exception e ) {
6129             e.printStackTrace( System.out );
6130             return false;
6131         }
6132         return true;
6133     }
6134
6135     private static boolean testMsaQualityMethod() {
6136         try {
6137             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6138             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6139             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6140             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6141             final List<Sequence> l = new ArrayList<Sequence>();
6142             l.add( s0 );
6143             l.add( s1 );
6144             l.add( s2 );
6145             l.add( s3 );
6146             final Msa msa = BasicMsa.createInstance( l );
6147             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6148                 return false;
6149             }
6150             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6151                 return false;
6152             }
6153             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6154                 return false;
6155             }
6156             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6157                 return false;
6158             }
6159             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6160                 return false;
6161             }
6162             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6163                 return false;
6164             }
6165             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6166                 return false;
6167             }
6168         }
6169         catch ( final Exception e ) {
6170             e.printStackTrace( System.out );
6171             return false;
6172         }
6173         return true;
6174     }
6175
6176     private static boolean testMsaEntropy() {
6177         try {
6178             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6179             final Sequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6180             final Sequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6181             final Sequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6182             final List<Sequence> l = new ArrayList<Sequence>();
6183             l.add( s0 );
6184             l.add( s1 );
6185             l.add( s2 );
6186             l.add( s3 );
6187             final Msa msa = BasicMsa.createInstance( l );
6188             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6189             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6190             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6191             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6192             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6193             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6194             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6195             System.out.println();
6196             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6197             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6198             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6199             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6200             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6201             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6202             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6203             final List<Sequence> l2 = new ArrayList<Sequence>();
6204             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6205             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6206             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6207             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6208             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6209             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6210             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6211             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6212             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6213             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6214             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6215             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6216             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6217             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6218             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6219             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6220             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6221             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6222             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6223             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6224             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6225             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6226             final Msa msa2 = BasicMsa.createInstance( l2 );
6227             System.out.println();
6228             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6229             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6230             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6231         }
6232         catch ( final Exception e ) {
6233             e.printStackTrace( System.out );
6234             return false;
6235         }
6236         return true;
6237     }
6238
6239     private static boolean testDeleteableMsa() {
6240         try {
6241             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6242             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6243             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6244             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6245             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6246             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6247             final List<Sequence> l0 = new ArrayList<Sequence>();
6248             l0.add( s0 );
6249             l0.add( s1 );
6250             l0.add( s2 );
6251             l0.add( s3 );
6252             l0.add( s4 );
6253             l0.add( s5 );
6254             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6255             dmsa0.deleteRow( "b", false );
6256             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6257                 return false;
6258             }
6259             dmsa0.deleteRow( "e", false );
6260             dmsa0.deleteRow( "a", false );
6261             dmsa0.deleteRow( "f", false );
6262             if ( dmsa0.getLength() != 4 ) {
6263                 return false;
6264             }
6265             if ( dmsa0.getNumberOfSequences() != 2 ) {
6266                 return false;
6267             }
6268             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6269                 return false;
6270             }
6271             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6272                 return false;
6273             }
6274             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6275                 return false;
6276             }
6277             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6278                 return false;
6279             }
6280             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6281                 return false;
6282             }
6283             dmsa0.deleteRow( "c", false );
6284             dmsa0.deleteRow( "d", false );
6285             if ( dmsa0.getNumberOfSequences() != 0 ) {
6286                 return false;
6287             }
6288             //
6289             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6290             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6291             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6292             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6293             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6294             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6295             final List<Sequence> l1 = new ArrayList<Sequence>();
6296             l1.add( s_0 );
6297             l1.add( s_1 );
6298             l1.add( s_2 );
6299             l1.add( s_3 );
6300             l1.add( s_4 );
6301             l1.add( s_5 );
6302             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6303             dmsa1.deleteGapOnlyColumns();
6304             dmsa1.deleteRow( "a", false );
6305             dmsa1.deleteRow( "f", false );
6306             dmsa1.deleteRow( "d", false );
6307             dmsa1.deleteGapOnlyColumns();
6308             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6309                 return false;
6310             }
6311             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6312                 return false;
6313             }
6314             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6315                 return false;
6316             }
6317             dmsa1.deleteRow( "c", false );
6318             dmsa1.deleteGapOnlyColumns();
6319             final Writer w0 = new StringWriter();
6320             dmsa1.write( w0, MSA_FORMAT.FASTA );
6321             final Writer w1 = new StringWriter();
6322             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6323             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6324                 return false;
6325             }
6326             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6327                 return false;
6328             }
6329             //
6330             final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6331             final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6332             final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6333             final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6334             final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6335             final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6336             final List<Sequence> l2 = new ArrayList<Sequence>();
6337             l2.add( s__0 );
6338             l2.add( s__1 );
6339             l2.add( s__2 );
6340             l2.add( s__3 );
6341             l2.add( s__4 );
6342             l2.add( s__5 );
6343             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6344             dmsa2.deleteGapColumns( 0.5 );
6345             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6346                 return false;
6347             }
6348             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6349                 return false;
6350             }
6351             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6352                 return false;
6353             }
6354             dmsa2.deleteGapColumns( 0.2 );
6355             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6356                 return false;
6357             }
6358             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6359                 return false;
6360             }
6361             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6362                 return false;
6363             }
6364             dmsa2.deleteGapColumns( 0 );
6365             dmsa2.deleteRow( "a", false );
6366             dmsa2.deleteRow( "b", false );
6367             dmsa2.deleteRow( "f", false );
6368             dmsa2.deleteRow( "e", false );
6369             dmsa2.setIdentifier( 0, "new_c" );
6370             dmsa2.setIdentifier( 1, "new_d" );
6371             dmsa2.setResidueAt( 0, 0, 'x' );
6372             final Sequence s = dmsa2.deleteRow( "new_d", true );
6373             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6374                 return false;
6375             }
6376             final Writer w = new StringWriter();
6377             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6378             final String phylip = w.toString();
6379             if ( !phylip.equals( "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6380                 return false;
6381             }
6382             final Writer w2 = new StringWriter();
6383             dmsa2.write( w2, MSA_FORMAT.FASTA );
6384             final String fasta = w2.toString();
6385             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6386                 return false;
6387             }
6388         }
6389         catch ( final Exception e ) {
6390             e.printStackTrace( System.out );
6391             return false;
6392         }
6393         return true;
6394     }
6395
6396     private static boolean testNextNodeWithCollapsing() {
6397         try {
6398             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6399             PhylogenyNode n;
6400             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6401             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6402             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6403             t0.getNode( "cd" ).setCollapse( true );
6404             t0.getNode( "cde" ).setCollapse( true );
6405             n = t0.getFirstExternalNode();
6406             while ( n != null ) {
6407                 ext.add( n );
6408                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6409             }
6410             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6411                 return false;
6412             }
6413             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6414                 return false;
6415             }
6416             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6417                 return false;
6418             }
6419             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6420                 return false;
6421             }
6422             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6423                 return false;
6424             }
6425             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6426                 return false;
6427             }
6428             ext.clear();
6429             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6430             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6431             t1.getNode( "ab" ).setCollapse( true );
6432             t1.getNode( "cd" ).setCollapse( true );
6433             t1.getNode( "cde" ).setCollapse( true );
6434             n = t1.getNode( "ab" );
6435             ext = new ArrayList<PhylogenyNode>();
6436             while ( n != null ) {
6437                 ext.add( n );
6438                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6439             }
6440             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6441                 return false;
6442             }
6443             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6444                 return false;
6445             }
6446             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6447                 return false;
6448             }
6449             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6450                 return false;
6451             }
6452             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6453                 return false;
6454             }
6455             //
6456             //
6457             ext.clear();
6458             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6459             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6460             t2.getNode( "ab" ).setCollapse( true );
6461             t2.getNode( "cd" ).setCollapse( true );
6462             t2.getNode( "cde" ).setCollapse( true );
6463             t2.getNode( "c" ).setCollapse( true );
6464             t2.getNode( "d" ).setCollapse( true );
6465             t2.getNode( "e" ).setCollapse( true );
6466             t2.getNode( "gh" ).setCollapse( true );
6467             n = t2.getNode( "ab" );
6468             ext = new ArrayList<PhylogenyNode>();
6469             while ( n != null ) {
6470                 ext.add( n );
6471                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6472             }
6473             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6474                 return false;
6475             }
6476             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6477                 return false;
6478             }
6479             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6480                 return false;
6481             }
6482             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6483                 return false;
6484             }
6485             //
6486             //
6487             ext.clear();
6488             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6489             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6490             t3.getNode( "ab" ).setCollapse( true );
6491             t3.getNode( "cd" ).setCollapse( true );
6492             t3.getNode( "cde" ).setCollapse( true );
6493             t3.getNode( "c" ).setCollapse( true );
6494             t3.getNode( "d" ).setCollapse( true );
6495             t3.getNode( "e" ).setCollapse( true );
6496             t3.getNode( "gh" ).setCollapse( true );
6497             t3.getNode( "fgh" ).setCollapse( true );
6498             n = t3.getNode( "ab" );
6499             ext = new ArrayList<PhylogenyNode>();
6500             while ( n != null ) {
6501                 ext.add( n );
6502                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6503             }
6504             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6505                 return false;
6506             }
6507             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6508                 return false;
6509             }
6510             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6511                 return false;
6512             }
6513             //
6514             //
6515             ext.clear();
6516             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6517             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6518             t4.getNode( "ab" ).setCollapse( true );
6519             t4.getNode( "cd" ).setCollapse( true );
6520             t4.getNode( "cde" ).setCollapse( true );
6521             t4.getNode( "c" ).setCollapse( true );
6522             t4.getNode( "d" ).setCollapse( true );
6523             t4.getNode( "e" ).setCollapse( true );
6524             t4.getNode( "gh" ).setCollapse( true );
6525             t4.getNode( "fgh" ).setCollapse( true );
6526             t4.getNode( "abcdefgh" ).setCollapse( true );
6527             n = t4.getNode( "abcdefgh" );
6528             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6529                 return false;
6530             }
6531             //
6532             //
6533             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6534             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6535             ext.clear();
6536             n = t5.getFirstExternalNode();
6537             while ( n != null ) {
6538                 ext.add( n );
6539                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6540             }
6541             if ( ext.size() != 8 ) {
6542                 return false;
6543             }
6544             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6545                 return false;
6546             }
6547             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6548                 return false;
6549             }
6550             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6551                 return false;
6552             }
6553             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6554                 return false;
6555             }
6556             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6557                 return false;
6558             }
6559             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6560                 return false;
6561             }
6562             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6563                 return false;
6564             }
6565             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6566                 return false;
6567             }
6568             //
6569             //
6570             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6571             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6572             ext.clear();
6573             t6.getNode( "ab" ).setCollapse( true );
6574             n = t6.getNode( "ab" );
6575             while ( n != null ) {
6576                 ext.add( n );
6577                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6578             }
6579             if ( ext.size() != 7 ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6595                 return false;
6596             }
6597             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6598                 return false;
6599             }
6600             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6601                 return false;
6602             }
6603             //
6604             //
6605             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6606             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6607             ext.clear();
6608             t7.getNode( "cd" ).setCollapse( true );
6609             n = t7.getNode( "a" );
6610             while ( n != null ) {
6611                 ext.add( n );
6612                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6613             }
6614             if ( ext.size() != 7 ) {
6615                 return false;
6616             }
6617             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6618                 return false;
6619             }
6620             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6621                 return false;
6622             }
6623             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6624                 return false;
6625             }
6626             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6627                 return false;
6628             }
6629             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6630                 return false;
6631             }
6632             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6633                 return false;
6634             }
6635             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6636                 return false;
6637             }
6638             //
6639             //
6640             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6641             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6642             ext.clear();
6643             t8.getNode( "cd" ).setCollapse( true );
6644             t8.getNode( "c" ).setCollapse( true );
6645             t8.getNode( "d" ).setCollapse( true );
6646             n = t8.getNode( "a" );
6647             while ( n != null ) {
6648                 ext.add( n );
6649                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6650             }
6651             if ( ext.size() != 7 ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6661                 System.out.println( "2 fail" );
6662                 return false;
6663             }
6664             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6665                 return false;
6666             }
6667             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6668                 return false;
6669             }
6670             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6671                 return false;
6672             }
6673             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6674                 return false;
6675             }
6676             //
6677             //
6678             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6679             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6680             ext.clear();
6681             t9.getNode( "gh" ).setCollapse( true );
6682             n = t9.getNode( "a" );
6683             while ( n != null ) {
6684                 ext.add( n );
6685                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6686             }
6687             if ( ext.size() != 7 ) {
6688                 return false;
6689             }
6690             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6691                 return false;
6692             }
6693             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6694                 return false;
6695             }
6696             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6697                 return false;
6698             }
6699             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6700                 return false;
6701             }
6702             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6703                 return false;
6704             }
6705             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6706                 return false;
6707             }
6708             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6709                 return false;
6710             }
6711             //
6712             //
6713             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6714             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6715             ext.clear();
6716             t10.getNode( "gh" ).setCollapse( true );
6717             t10.getNode( "g" ).setCollapse( true );
6718             t10.getNode( "h" ).setCollapse( true );
6719             n = t10.getNode( "a" );
6720             while ( n != null ) {
6721                 ext.add( n );
6722                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6723             }
6724             if ( ext.size() != 7 ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6728                 return false;
6729             }
6730             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6731                 return false;
6732             }
6733             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6734                 return false;
6735             }
6736             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6737                 return false;
6738             }
6739             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6740                 return false;
6741             }
6742             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6743                 return false;
6744             }
6745             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6746                 return false;
6747             }
6748             //
6749             //
6750             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6751             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6752             ext.clear();
6753             t11.getNode( "gh" ).setCollapse( true );
6754             t11.getNode( "fgh" ).setCollapse( true );
6755             n = t11.getNode( "a" );
6756             while ( n != null ) {
6757                 ext.add( n );
6758                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6759             }
6760             if ( ext.size() != 6 ) {
6761                 return false;
6762             }
6763             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6764                 return false;
6765             }
6766             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6767                 return false;
6768             }
6769             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6770                 return false;
6771             }
6772             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6773                 return false;
6774             }
6775             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6776                 return false;
6777             }
6778             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6779                 return false;
6780             }
6781             //
6782             //
6783             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6784             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6785             ext.clear();
6786             t12.getNode( "gh" ).setCollapse( true );
6787             t12.getNode( "fgh" ).setCollapse( true );
6788             t12.getNode( "g" ).setCollapse( true );
6789             t12.getNode( "h" ).setCollapse( true );
6790             t12.getNode( "f" ).setCollapse( true );
6791             n = t12.getNode( "a" );
6792             while ( n != null ) {
6793                 ext.add( n );
6794                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6795             }
6796             if ( ext.size() != 6 ) {
6797                 return false;
6798             }
6799             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6800                 return false;
6801             }
6802             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6803                 return false;
6804             }
6805             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6806                 return false;
6807             }
6808             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6809                 return false;
6810             }
6811             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6812                 return false;
6813             }
6814             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6815                 return false;
6816             }
6817             //
6818             //
6819             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6820             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6821             ext.clear();
6822             t13.getNode( "ab" ).setCollapse( true );
6823             t13.getNode( "b" ).setCollapse( true );
6824             t13.getNode( "fgh" ).setCollapse( true );
6825             t13.getNode( "gh" ).setCollapse( true );
6826             n = t13.getNode( "ab" );
6827             while ( n != null ) {
6828                 ext.add( n );
6829                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6830             }
6831             if ( ext.size() != 5 ) {
6832                 return false;
6833             }
6834             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6835                 return false;
6836             }
6837             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6838                 return false;
6839             }
6840             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6841                 return false;
6842             }
6843             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6844                 return false;
6845             }
6846             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6847                 return false;
6848             }
6849             //
6850             //
6851             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6852             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6853             ext.clear();
6854             t14.getNode( "ab" ).setCollapse( true );
6855             t14.getNode( "a" ).setCollapse( true );
6856             t14.getNode( "fgh" ).setCollapse( true );
6857             t14.getNode( "gh" ).setCollapse( true );
6858             n = t14.getNode( "ab" );
6859             while ( n != null ) {
6860                 ext.add( n );
6861                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6862             }
6863             if ( ext.size() != 5 ) {
6864                 return false;
6865             }
6866             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6867                 return false;
6868             }
6869             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6870                 return false;
6871             }
6872             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6873                 return false;
6874             }
6875             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6876                 return false;
6877             }
6878             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6879                 return false;
6880             }
6881             //
6882             //
6883             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" );
6884             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6885             ext.clear();
6886             t15.getNode( "ab" ).setCollapse( true );
6887             t15.getNode( "a" ).setCollapse( true );
6888             t15.getNode( "fgh" ).setCollapse( true );
6889             t15.getNode( "gh" ).setCollapse( true );
6890             n = t15.getNode( "ab" );
6891             while ( n != null ) {
6892                 ext.add( n );
6893                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6894             }
6895             if ( ext.size() != 6 ) {
6896                 return false;
6897             }
6898             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6899                 return false;
6900             }
6901             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6902                 return false;
6903             }
6904             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6905                 return false;
6906             }
6907             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6908                 return false;
6909             }
6910             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6914                 return false;
6915             }
6916             //
6917             //
6918             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" );
6919             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6920             ext.clear();
6921             t16.getNode( "ab" ).setCollapse( true );
6922             t16.getNode( "a" ).setCollapse( true );
6923             t16.getNode( "fgh" ).setCollapse( true );
6924             t16.getNode( "gh" ).setCollapse( true );
6925             t16.getNode( "cd" ).setCollapse( true );
6926             t16.getNode( "cde" ).setCollapse( true );
6927             t16.getNode( "d" ).setCollapse( true );
6928             t16.getNode( "x" ).setCollapse( true );
6929             n = t16.getNode( "ab" );
6930             while ( n != null ) {
6931                 ext.add( n );
6932                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6933             }
6934             if ( ext.size() != 4 ) {
6935                 return false;
6936             }
6937             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6938                 return false;
6939             }
6940             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6941                 return false;
6942             }
6943             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6944                 return false;
6945             }
6946             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6947                 return false;
6948             }
6949         }
6950         catch ( final Exception e ) {
6951             e.printStackTrace( System.out );
6952             return false;
6953         }
6954         return true;
6955     }
6956
6957     private static boolean testNexusCharactersParsing() {
6958         try {
6959             final NexusCharactersParser parser = new NexusCharactersParser();
6960             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6961             parser.parse();
6962             String[] labels = parser.getCharStateLabels();
6963             if ( labels.length != 7 ) {
6964                 return false;
6965             }
6966             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6967                 return false;
6968             }
6969             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6970                 return false;
6971             }
6972             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6973                 return false;
6974             }
6975             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6976                 return false;
6977             }
6978             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6979                 return false;
6980             }
6981             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6982                 return false;
6983             }
6984             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6985                 return false;
6986             }
6987             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6988             parser.parse();
6989             labels = parser.getCharStateLabels();
6990             if ( labels.length != 7 ) {
6991                 return false;
6992             }
6993             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6994                 return false;
6995             }
6996             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6997                 return false;
6998             }
6999             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7000                 return false;
7001             }
7002             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7003                 return false;
7004             }
7005             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7006                 return false;
7007             }
7008             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7009                 return false;
7010             }
7011             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7012                 return false;
7013             }
7014         }
7015         catch ( final Exception e ) {
7016             e.printStackTrace( System.out );
7017             return false;
7018         }
7019         return true;
7020     }
7021
7022     private static boolean testNexusMatrixParsing() {
7023         try {
7024             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7025             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7026             parser.parse();
7027             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7028             if ( m.getNumberOfCharacters() != 9 ) {
7029                 return false;
7030             }
7031             if ( m.getNumberOfIdentifiers() != 5 ) {
7032                 return false;
7033             }
7034             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7035                 return false;
7036             }
7037             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7038                 return false;
7039             }
7040             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7041                 return false;
7042             }
7043             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7044                 return false;
7045             }
7046             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7047                 return false;
7048             }
7049             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7050                 return false;
7051             }
7052             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7053                 return false;
7054             }
7055             //            if ( labels.length != 7 ) {
7056             //                return false;
7057             //            }
7058             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7059             //                return false;
7060             //            }
7061             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7062             //                return false;
7063             //            }
7064             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7065             //                return false;
7066             //            }
7067             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7068             //                return false;
7069             //            }
7070             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7071             //                return false;
7072             //            }
7073             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7074             //                return false;
7075             //            }
7076             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7077             //                return false;
7078             //            }
7079             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7080             //            parser.parse();
7081             //            labels = parser.getCharStateLabels();
7082             //            if ( labels.length != 7 ) {
7083             //                return false;
7084             //            }
7085             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7086             //                return false;
7087             //            }
7088             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7089             //                return false;
7090             //            }
7091             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7092             //                return false;
7093             //            }
7094             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7095             //                return false;
7096             //            }
7097             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7098             //                return false;
7099             //            }
7100             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7104             //                return false;
7105             //            }
7106         }
7107         catch ( final Exception e ) {
7108             e.printStackTrace( System.out );
7109             return false;
7110         }
7111         return true;
7112     }
7113
7114     private static boolean testNexusTreeParsing() {
7115         try {
7116             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7117             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7118             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7119             if ( phylogenies.length != 1 ) {
7120                 return false;
7121             }
7122             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7123                 return false;
7124             }
7125             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7126                 return false;
7127             }
7128             phylogenies = null;
7129             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7130             if ( phylogenies.length != 1 ) {
7131                 return false;
7132             }
7133             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7134                 return false;
7135             }
7136             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7137                 return false;
7138             }
7139             phylogenies = null;
7140             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7141             if ( phylogenies.length != 1 ) {
7142                 return false;
7143             }
7144             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7145                 return false;
7146             }
7147             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7148                 return false;
7149             }
7150             if ( phylogenies[ 0 ].isRooted() ) {
7151                 return false;
7152             }
7153             phylogenies = null;
7154             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7155             if ( phylogenies.length != 18 ) {
7156                 return false;
7157             }
7158             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7159                 return false;
7160             }
7161             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7162                 return false;
7163             }
7164             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7165                 return false;
7166             }
7167             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7168                 return false;
7169             }
7170             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7171                 return false;
7172             }
7173             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7174                 return false;
7175             }
7176             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7177                 return false;
7178             }
7179             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7180                 return false;
7181             }
7182             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7183                 return false;
7184             }
7185             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7186                 return false;
7187             }
7188             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7189                 return false;
7190             }
7191             if ( phylogenies[ 8 ].isRooted() ) {
7192                 return false;
7193             }
7194             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7195                 return false;
7196             }
7197             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7198                 return false;
7199             }
7200             if ( !phylogenies[ 9 ].isRooted() ) {
7201                 return false;
7202             }
7203             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7204                 return false;
7205             }
7206             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7207                 return false;
7208             }
7209             if ( !phylogenies[ 10 ].isRooted() ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7216                 return false;
7217             }
7218             if ( phylogenies[ 11 ].isRooted() ) {
7219                 return false;
7220             }
7221             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7225                 return false;
7226             }
7227             if ( !phylogenies[ 12 ].isRooted() ) {
7228                 return false;
7229             }
7230             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7231                 return false;
7232             }
7233             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7234                 return false;
7235             }
7236             if ( !phylogenies[ 13 ].isRooted() ) {
7237                 return false;
7238             }
7239             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 14 ].isRooted() ) {
7246                 return false;
7247             }
7248             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7249                 return false;
7250             }
7251             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7252                 return false;
7253             }
7254             if ( phylogenies[ 15 ].isRooted() ) {
7255                 return false;
7256             }
7257             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7258                 return false;
7259             }
7260             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7261                 return false;
7262             }
7263             if ( !phylogenies[ 16 ].isRooted() ) {
7264                 return false;
7265             }
7266             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7270                 return false;
7271             }
7272             if ( phylogenies[ 17 ].isRooted() ) {
7273                 return false;
7274             }
7275             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7276                 return false;
7277             }
7278             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7279             phylogenies = null;
7280             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7281             if ( phylogenies.length != 9 ) {
7282                 return false;
7283             }
7284             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7285                     .getDistanceToParent() ) ) {
7286                 return false;
7287             }
7288             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7289                     .getDistanceToParent() ) ) {
7290                 return false;
7291             }
7292             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7293                 return false;
7294             }
7295             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7296                 return false;
7297             }
7298             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7299                 return false;
7300             }
7301             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7302                 return false;
7303             }
7304             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7305                 return false;
7306             }
7307         }
7308         catch ( final Exception e ) {
7309             e.printStackTrace( System.out );
7310             return false;
7311         }
7312         return true;
7313     }
7314
7315     private static boolean testNexusTreeParsingIterating() {
7316         try {
7317             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7318             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7319             if ( !p.hasNext() ) {
7320                 return false;
7321             }
7322             Phylogeny phy = p.next();
7323             if ( phy == null ) {
7324                 return false;
7325             }
7326             if ( phy.getNumberOfExternalNodes() != 25 ) {
7327                 return false;
7328             }
7329             if ( !phy.getName().equals( "" ) ) {
7330                 return false;
7331             }
7332             if ( p.hasNext() ) {
7333                 return false;
7334             }
7335             phy = p.next();
7336             if ( phy != null ) {
7337                 return false;
7338             }
7339             //
7340             p.reset();
7341             if ( !p.hasNext() ) {
7342                 return false;
7343             }
7344             phy = p.next();
7345             if ( phy == null ) {
7346                 return false;
7347             }
7348             if ( phy.getNumberOfExternalNodes() != 25 ) {
7349                 return false;
7350             }
7351             if ( !phy.getName().equals( "" ) ) {
7352                 return false;
7353             }
7354             if ( p.hasNext() ) {
7355                 return false;
7356             }
7357             phy = p.next();
7358             if ( phy != null ) {
7359                 return false;
7360             }
7361             ////
7362             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7363             if ( !p.hasNext() ) {
7364                 return false;
7365             }
7366             phy = p.next();
7367             if ( phy == null ) {
7368                 return false;
7369             }
7370             if ( phy.getNumberOfExternalNodes() != 10 ) {
7371                 return false;
7372             }
7373             if ( !phy.getName().equals( "name" ) ) {
7374                 return false;
7375             }
7376             if ( p.hasNext() ) {
7377                 return false;
7378             }
7379             phy = p.next();
7380             if ( phy != null ) {
7381                 return false;
7382             }
7383             //
7384             p.reset();
7385             if ( !p.hasNext() ) {
7386                 return false;
7387             }
7388             phy = p.next();
7389             if ( phy == null ) {
7390                 return false;
7391             }
7392             if ( phy.getNumberOfExternalNodes() != 10 ) {
7393                 return false;
7394             }
7395             if ( !phy.getName().equals( "name" ) ) {
7396                 return false;
7397             }
7398             if ( p.hasNext() ) {
7399                 return false;
7400             }
7401             phy = p.next();
7402             if ( phy != null ) {
7403                 return false;
7404             }
7405             //
7406             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7407             if ( !p.hasNext() ) {
7408                 return false;
7409             }
7410             phy = p.next();
7411             if ( phy == null ) {
7412                 return false;
7413             }
7414             if ( phy.getNumberOfExternalNodes() != 3 ) {
7415                 return false;
7416             }
7417             if ( !phy.getName().equals( "" ) ) {
7418                 return false;
7419             }
7420             if ( phy.isRooted() ) {
7421                 return false;
7422             }
7423             if ( p.hasNext() ) {
7424                 return false;
7425             }
7426             phy = p.next();
7427             if ( phy != null ) {
7428                 return false;
7429             }
7430             //
7431             p.reset();
7432             if ( !p.hasNext() ) {
7433                 return false;
7434             }
7435             phy = p.next();
7436             if ( phy == null ) {
7437                 return false;
7438             }
7439             if ( phy.getNumberOfExternalNodes() != 3 ) {
7440                 return false;
7441             }
7442             if ( !phy.getName().equals( "" ) ) {
7443                 return false;
7444             }
7445             if ( p.hasNext() ) {
7446                 return false;
7447             }
7448             phy = p.next();
7449             if ( phy != null ) {
7450                 return false;
7451             }
7452             //
7453             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7454             if ( !p.hasNext() ) {
7455                 return false;
7456             }
7457             //0
7458             phy = p.next();
7459             if ( phy == null ) {
7460                 return false;
7461             }
7462             if ( phy.getNumberOfExternalNodes() != 10 ) {
7463                 return false;
7464             }
7465             if ( !phy.getName().equals( "tree 0" ) ) {
7466                 return false;
7467             }
7468             //1
7469             if ( !p.hasNext() ) {
7470                 return false;
7471             }
7472             phy = p.next();
7473             if ( phy == null ) {
7474                 return false;
7475             }
7476             if ( phy.getNumberOfExternalNodes() != 10 ) {
7477                 return false;
7478             }
7479             if ( !phy.getName().equals( "tree 1" ) ) {
7480                 return false;
7481             }
7482             //2
7483             if ( !p.hasNext() ) {
7484                 return false;
7485             }
7486             phy = p.next();
7487             if ( phy == null ) {
7488                 return false;
7489             }
7490             if ( phy.getNumberOfExternalNodes() != 3 ) {
7491                 System.out.println( phy.toString() );
7492                 return false;
7493             }
7494             if ( !phy.getName().equals( "" ) ) {
7495                 return false;
7496             }
7497             if ( phy.isRooted() ) {
7498                 return false;
7499             }
7500             //3
7501             if ( !p.hasNext() ) {
7502                 return false;
7503             }
7504             phy = p.next();
7505             if ( phy == null ) {
7506                 return false;
7507             }
7508             if ( phy.getNumberOfExternalNodes() != 4 ) {
7509                 return false;
7510             }
7511             if ( !phy.getName().equals( "" ) ) {
7512                 return false;
7513             }
7514             if ( !phy.isRooted() ) {
7515                 return false;
7516             }
7517             //4
7518             if ( !p.hasNext() ) {
7519                 return false;
7520             }
7521             phy = p.next();
7522             if ( phy == null ) {
7523                 return false;
7524             }
7525             if ( phy.getNumberOfExternalNodes() != 5 ) {
7526                 System.out.println( phy.getNumberOfExternalNodes() );
7527                 return false;
7528             }
7529             if ( !phy.getName().equals( "" ) ) {
7530                 return false;
7531             }
7532             if ( !phy.isRooted() ) {
7533                 return false;
7534             }
7535             //5
7536             if ( !p.hasNext() ) {
7537                 return false;
7538             }
7539             phy = p.next();
7540             if ( phy == null ) {
7541                 return false;
7542             }
7543             if ( phy.getNumberOfExternalNodes() != 3 ) {
7544                 return false;
7545             }
7546             if ( !phy.getName().equals( "" ) ) {
7547                 return false;
7548             }
7549             if ( phy.isRooted() ) {
7550                 return false;
7551             }
7552             //6
7553             if ( !p.hasNext() ) {
7554                 return false;
7555             }
7556             phy = p.next();
7557             if ( phy == null ) {
7558                 return false;
7559             }
7560             if ( phy.getNumberOfExternalNodes() != 2 ) {
7561                 return false;
7562             }
7563             if ( !phy.getName().equals( "" ) ) {
7564                 return false;
7565             }
7566             if ( !phy.isRooted() ) {
7567                 return false;
7568             }
7569             //7
7570             if ( !p.hasNext() ) {
7571                 return false;
7572             }
7573             phy = p.next();
7574             if ( phy.getNumberOfExternalNodes() != 3 ) {
7575                 return false;
7576             }
7577             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7578                 return false;
7579             }
7580             if ( !phy.isRooted() ) {
7581                 return false;
7582             }
7583             //8
7584             if ( !p.hasNext() ) {
7585                 return false;
7586             }
7587             phy = p.next();
7588             if ( phy.getNumberOfExternalNodes() != 3 ) {
7589                 return false;
7590             }
7591             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7592                 return false;
7593             }
7594             if ( !phy.getName().equals( "tree 8" ) ) {
7595                 return false;
7596             }
7597             //9
7598             if ( !p.hasNext() ) {
7599                 return false;
7600             }
7601             phy = p.next();
7602             if ( phy.getNumberOfExternalNodes() != 3 ) {
7603                 return false;
7604             }
7605             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7606                 return false;
7607             }
7608             if ( !phy.getName().equals( "tree 9" ) ) {
7609                 return false;
7610             }
7611             //10
7612             if ( !p.hasNext() ) {
7613                 return false;
7614             }
7615             phy = p.next();
7616             if ( phy.getNumberOfExternalNodes() != 3 ) {
7617                 return false;
7618             }
7619             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7620                 return false;
7621             }
7622             if ( !phy.getName().equals( "tree 10" ) ) {
7623                 return false;
7624             }
7625             if ( !phy.isRooted() ) {
7626                 return false;
7627             }
7628             //11
7629             if ( !p.hasNext() ) {
7630                 return false;
7631             }
7632             phy = p.next();
7633             if ( phy.getNumberOfExternalNodes() != 3 ) {
7634                 return false;
7635             }
7636             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7637                 return false;
7638             }
7639             if ( !phy.getName().equals( "tree 11" ) ) {
7640                 return false;
7641             }
7642             if ( phy.isRooted() ) {
7643                 return false;
7644             }
7645             //12
7646             if ( !p.hasNext() ) {
7647                 return false;
7648             }
7649             phy = p.next();
7650             if ( phy.getNumberOfExternalNodes() != 3 ) {
7651                 return false;
7652             }
7653             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7654                 return false;
7655             }
7656             if ( !phy.getName().equals( "tree 12" ) ) {
7657                 return false;
7658             }
7659             if ( !phy.isRooted() ) {
7660                 return false;
7661             }
7662             //13
7663             if ( !p.hasNext() ) {
7664                 return false;
7665             }
7666             phy = p.next();
7667             if ( phy.getNumberOfExternalNodes() != 3 ) {
7668                 return false;
7669             }
7670             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7671                 return false;
7672             }
7673             if ( !phy.getName().equals( "tree 13" ) ) {
7674                 return false;
7675             }
7676             if ( !phy.isRooted() ) {
7677                 return false;
7678             }
7679             //14
7680             if ( !p.hasNext() ) {
7681                 return false;
7682             }
7683             phy = p.next();
7684             if ( phy.getNumberOfExternalNodes() != 10 ) {
7685                 System.out.println( phy.getNumberOfExternalNodes() );
7686                 return false;
7687             }
7688             if ( !phy
7689                     .toNewHampshire()
7690                     .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;" ) ) {
7691                 System.out.println( phy.toNewHampshire() );
7692                 return false;
7693             }
7694             if ( !phy.getName().equals( "tree 14" ) ) {
7695                 return false;
7696             }
7697             if ( !phy.isRooted() ) {
7698                 return false;
7699             }
7700             //15
7701             if ( !p.hasNext() ) {
7702                 return false;
7703             }
7704             phy = p.next();
7705             if ( phy.getNumberOfExternalNodes() != 10 ) {
7706                 System.out.println( phy.getNumberOfExternalNodes() );
7707                 return false;
7708             }
7709             if ( !phy
7710                     .toNewHampshire()
7711                     .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;" ) ) {
7712                 System.out.println( phy.toNewHampshire() );
7713                 return false;
7714             }
7715             if ( !phy.getName().equals( "tree 15" ) ) {
7716                 return false;
7717             }
7718             if ( phy.isRooted() ) {
7719                 return false;
7720             }
7721             //16
7722             if ( !p.hasNext() ) {
7723                 return false;
7724             }
7725             phy = p.next();
7726             if ( phy.getNumberOfExternalNodes() != 10 ) {
7727                 System.out.println( phy.getNumberOfExternalNodes() );
7728                 return false;
7729             }
7730             if ( !phy
7731                     .toNewHampshire()
7732                     .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;" ) ) {
7733                 System.out.println( phy.toNewHampshire() );
7734                 return false;
7735             }
7736             if ( !phy.getName().equals( "tree 16" ) ) {
7737                 return false;
7738             }
7739             if ( !phy.isRooted() ) {
7740                 return false;
7741             }
7742             //17
7743             if ( !p.hasNext() ) {
7744                 return false;
7745             }
7746             phy = p.next();
7747             if ( phy.getNumberOfExternalNodes() != 10 ) {
7748                 System.out.println( phy.getNumberOfExternalNodes() );
7749                 return false;
7750             }
7751             if ( !phy
7752                     .toNewHampshire()
7753                     .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;" ) ) {
7754                 System.out.println( phy.toNewHampshire() );
7755                 return false;
7756             }
7757             if ( !phy.getName().equals( "tree 17" ) ) {
7758                 return false;
7759             }
7760             if ( phy.isRooted() ) {
7761                 return false;
7762             }
7763             //
7764             if ( p.hasNext() ) {
7765                 return false;
7766             }
7767             phy = p.next();
7768             if ( phy != null ) {
7769                 return false;
7770             }
7771             p.reset();
7772             //0
7773             if ( !p.hasNext() ) {
7774                 return false;
7775             }
7776             phy = p.next();
7777             if ( phy == null ) {
7778                 return false;
7779             }
7780             if ( phy.getNumberOfExternalNodes() != 10 ) {
7781                 return false;
7782             }
7783             if ( !phy.getName().equals( "tree 0" ) ) {
7784                 return false;
7785             }
7786             //1
7787             if ( !p.hasNext() ) {
7788                 return false;
7789             }
7790             phy = p.next();
7791             if ( phy == null ) {
7792                 return false;
7793             }
7794             if ( phy.getNumberOfExternalNodes() != 10 ) {
7795                 return false;
7796             }
7797             if ( !phy.getName().equals( "tree 1" ) ) {
7798                 return false;
7799             }
7800             //2
7801             if ( !p.hasNext() ) {
7802                 return false;
7803             }
7804             phy = p.next();
7805             if ( phy == null ) {
7806                 return false;
7807             }
7808             if ( phy.getNumberOfExternalNodes() != 3 ) {
7809                 return false;
7810             }
7811             if ( !phy.getName().equals( "" ) ) {
7812                 return false;
7813             }
7814             if ( phy.isRooted() ) {
7815                 return false;
7816             }
7817             //3
7818             if ( !p.hasNext() ) {
7819                 return false;
7820             }
7821             phy = p.next();
7822             if ( phy == null ) {
7823                 return false;
7824             }
7825             if ( phy.getNumberOfExternalNodes() != 4 ) {
7826                 return false;
7827             }
7828             if ( !phy.getName().equals( "" ) ) {
7829                 return false;
7830             }
7831             if ( !phy.isRooted() ) {
7832                 return false;
7833             }
7834             //4
7835             if ( !p.hasNext() ) {
7836                 return false;
7837             }
7838             phy = p.next();
7839             if ( phy == null ) {
7840                 return false;
7841             }
7842             if ( phy.getNumberOfExternalNodes() != 5 ) {
7843                 System.out.println( phy.getNumberOfExternalNodes() );
7844                 return false;
7845             }
7846             if ( !phy.getName().equals( "" ) ) {
7847                 return false;
7848             }
7849             if ( !phy.isRooted() ) {
7850                 return false;
7851             }
7852             //5
7853             if ( !p.hasNext() ) {
7854                 return false;
7855             }
7856             phy = p.next();
7857             if ( phy == null ) {
7858                 return false;
7859             }
7860             if ( phy.getNumberOfExternalNodes() != 3 ) {
7861                 return false;
7862             }
7863             if ( !phy.getName().equals( "" ) ) {
7864                 return false;
7865             }
7866             if ( phy.isRooted() ) {
7867                 return false;
7868             }
7869             //
7870             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7871             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7872             // 0
7873             if ( !p2.hasNext() ) {
7874                 return false;
7875             }
7876             phy = p2.next();
7877             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7878                 return false;
7879             }
7880             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7881                 return false;
7882             }
7883             // 1
7884             if ( !p2.hasNext() ) {
7885                 return false;
7886             }
7887             phy = p2.next();
7888             // 2
7889             if ( !p2.hasNext() ) {
7890                 return false;
7891             }
7892             phy = p2.next();
7893             // 3
7894             if ( !p2.hasNext() ) {
7895                 return false;
7896             }
7897             phy = p2.next();
7898             // 4
7899             if ( !p2.hasNext() ) {
7900                 return false;
7901             }
7902             phy = p2.next();
7903             // 5
7904             if ( !p2.hasNext() ) {
7905                 return false;
7906             }
7907             phy = p2.next();
7908             // 6
7909             if ( !p2.hasNext() ) {
7910                 return false;
7911             }
7912             phy = p2.next();
7913             // 7
7914             if ( !p2.hasNext() ) {
7915                 return false;
7916             }
7917             phy = p2.next();
7918             // 8
7919             if ( !p2.hasNext() ) {
7920                 return false;
7921             }
7922             phy = p2.next();
7923             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7924                 return false;
7925             }
7926             if ( p2.hasNext() ) {
7927                 return false;
7928             }
7929             phy = p2.next();
7930             if ( phy != null ) {
7931                 return false;
7932             }
7933             // 0
7934             p2.reset();
7935             if ( !p2.hasNext() ) {
7936                 return false;
7937             }
7938             phy = p2.next();
7939             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7940                 return false;
7941             }
7942             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7943                 return false;
7944             }
7945         }
7946         catch ( final Exception e ) {
7947             e.printStackTrace( System.out );
7948             return false;
7949         }
7950         return true;
7951     }
7952
7953     private static boolean testNexusTreeParsingTranslating() {
7954         try {
7955             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7956             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7957             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7958             if ( phylogenies.length != 1 ) {
7959                 return false;
7960             }
7961             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7962                 return false;
7963             }
7964             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7965                 return false;
7966             }
7967             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7968                 return false;
7969             }
7970             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7971                 return false;
7972             }
7973             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7974                     .equals( "Aranaeus" ) ) {
7975                 return false;
7976             }
7977             phylogenies = null;
7978             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7979             if ( phylogenies.length != 3 ) {
7980                 return false;
7981             }
7982             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7983                 return false;
7984             }
7985             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7986                 return false;
7987             }
7988             if ( phylogenies[ 0 ].isRooted() ) {
7989                 return false;
7990             }
7991             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7992                 return false;
7993             }
7994             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7995                 return false;
7996             }
7997             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7998                     .equals( "Aranaeus" ) ) {
7999                 return false;
8000             }
8001             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8002                 return false;
8003             }
8004             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8005                 return false;
8006             }
8007             if ( phylogenies[ 1 ].isRooted() ) {
8008                 return false;
8009             }
8010             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8011                 return false;
8012             }
8013             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8014                 return false;
8015             }
8016             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8017                     .equals( "Aranaeus" ) ) {
8018                 return false;
8019             }
8020             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8021                 return false;
8022             }
8023             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8024                 return false;
8025             }
8026             if ( !phylogenies[ 2 ].isRooted() ) {
8027                 return false;
8028             }
8029             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8030                 return false;
8031             }
8032             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8033                 return false;
8034             }
8035             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8036                     .equals( "Aranaeus" ) ) {
8037                 return false;
8038             }
8039             phylogenies = null;
8040             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8041             if ( phylogenies.length != 3 ) {
8042                 return false;
8043             }
8044             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8045                 return false;
8046             }
8047             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8048                 return false;
8049             }
8050             if ( phylogenies[ 0 ].isRooted() ) {
8051                 return false;
8052             }
8053             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8054                 return false;
8055             }
8056             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8057                 return false;
8058             }
8059             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8060                     .equals( "Aranaeus" ) ) {
8061                 return false;
8062             }
8063             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8064                 return false;
8065             }
8066             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8067                 return false;
8068             }
8069             if ( phylogenies[ 1 ].isRooted() ) {
8070                 return false;
8071             }
8072             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8073                 return false;
8074             }
8075             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8076                 return false;
8077             }
8078             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8079                     .equals( "Aranaeus" ) ) {
8080                 return false;
8081             }
8082             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8083                 return false;
8084             }
8085             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8086                 return false;
8087             }
8088             if ( !phylogenies[ 2 ].isRooted() ) {
8089                 return false;
8090             }
8091             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8092                 return false;
8093             }
8094             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8095                 return false;
8096             }
8097             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8098                     .equals( "Aranaeus" ) ) {
8099                 return false;
8100             }
8101             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8102             if ( phylogenies.length != 3 ) {
8103                 return false;
8104             }
8105             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8106                            0.00100049 ) ) {
8107                 return false;
8108             }
8109         }
8110         catch ( final Exception e ) {
8111             e.printStackTrace( System.out );
8112             return false;
8113         }
8114         return true;
8115     }
8116
8117     private static boolean testNHParsing() {
8118         try {
8119             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8120             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8121             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8122                 return false;
8123             }
8124             final NHXParser nhxp = new NHXParser();
8125             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8126             nhxp.setReplaceUnderscores( true );
8127             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8128             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8129                 return false;
8130             }
8131             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8132                 return false;
8133             }
8134             final Phylogeny p1b = factory
8135                     .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 ",
8136                              new NHXParser() )[ 0 ];
8137             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8138                 return false;
8139             }
8140             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8141                 return false;
8142             }
8143             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8144             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8145             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8146             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8147             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8148             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8149             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8150             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8151             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8152             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8153             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8154                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8155                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8156                                                     new NHXParser() );
8157             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8158                 return false;
8159             }
8160             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8161                 return false;
8162             }
8163             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8164                 return false;
8165             }
8166             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8167                 return false;
8168             }
8169             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8170             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8171             final String p16_S = "((A,B),C)";
8172             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8173             if ( p16.length != 1 ) {
8174                 return false;
8175             }
8176             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8177                 return false;
8178             }
8179             final String p17_S = "(C,(A,B))";
8180             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8181             if ( p17.length != 1 ) {
8182                 return false;
8183             }
8184             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8185                 return false;
8186             }
8187             final String p18_S = "((A,B),(C,D))";
8188             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8189             if ( p18.length != 1 ) {
8190                 return false;
8191             }
8192             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8193                 return false;
8194             }
8195             final String p19_S = "(((A,B),C),D)";
8196             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8197             if ( p19.length != 1 ) {
8198                 return false;
8199             }
8200             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8201                 return false;
8202             }
8203             final String p20_S = "(A,(B,(C,D)))";
8204             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8205             if ( p20.length != 1 ) {
8206                 return false;
8207             }
8208             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8209                 return false;
8210             }
8211             final String p21_S = "(A,(B,(C,(D,E))))";
8212             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8213             if ( p21.length != 1 ) {
8214                 return false;
8215             }
8216             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8217                 return false;
8218             }
8219             final String p22_S = "((((A,B),C),D),E)";
8220             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8221             if ( p22.length != 1 ) {
8222                 return false;
8223             }
8224             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8225                 return false;
8226             }
8227             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8228             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8229             if ( p23.length != 1 ) {
8230                 System.out.println( "xl=" + p23.length );
8231                 System.exit( -1 );
8232                 return false;
8233             }
8234             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8235                 return false;
8236             }
8237             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8238             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8239             if ( p24.length != 1 ) {
8240                 return false;
8241             }
8242             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8243                 return false;
8244             }
8245             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8246             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8247             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8248             if ( p241.length != 2 ) {
8249                 return false;
8250             }
8251             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8252                 return false;
8253             }
8254             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8255                 return false;
8256             }
8257             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8258                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8259                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8260                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8261                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8262                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8263                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8264                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8265             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8266             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8267                 return false;
8268             }
8269             final String p26_S = "(A,B)ab";
8270             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8271             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8272                 return false;
8273             }
8274             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8275             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8276             if ( p27s.length != 1 ) {
8277                 System.out.println( "xxl=" + p27s.length );
8278                 System.exit( -1 );
8279                 return false;
8280             }
8281             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8282                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8283                 System.exit( -1 );
8284                 return false;
8285             }
8286             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8287                                                     new NHXParser() );
8288             if ( p27.length != 1 ) {
8289                 System.out.println( "yl=" + p27.length );
8290                 System.exit( -1 );
8291                 return false;
8292             }
8293             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8294                 System.out.println( p27[ 0 ].toNewHampshireX() );
8295                 System.exit( -1 );
8296                 return false;
8297             }
8298             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8299             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8300             final String p28_S3 = "(A,B)ab";
8301             final String p28_S4 = "((((A,B),C),D),;E;)";
8302             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8303                                                     new NHXParser() );
8304             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8305                 return false;
8306             }
8307             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8308                 return false;
8309             }
8310             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8311                 return false;
8312             }
8313             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8314                 return false;
8315             }
8316             if ( p28.length != 4 ) {
8317                 return false;
8318             }
8319             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";
8320             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8321             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8322                 return false;
8323             }
8324             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";
8325             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8326             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8327                 return false;
8328             }
8329             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8330             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8331             if ( ( p32.length != 0 ) ) {
8332                 return false;
8333             }
8334             final String p33_S = "A";
8335             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8336             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8337                 return false;
8338             }
8339             final String p34_S = "B;";
8340             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8341             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8342                 return false;
8343             }
8344             final String p35_S = "B:0.2";
8345             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8346             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8347                 return false;
8348             }
8349             final String p36_S = "(A)";
8350             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8351             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8352                 return false;
8353             }
8354             final String p37_S = "((A))";
8355             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8356             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8357                 return false;
8358             }
8359             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8360             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8361             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8362                 return false;
8363             }
8364             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8365             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8366             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8367                 return false;
8368             }
8369             final String p40_S = "(A,B,C)";
8370             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8371             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8372                 return false;
8373             }
8374             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8375             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8376             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8377                 return false;
8378             }
8379             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8380             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8381             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8382                 return false;
8383             }
8384             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)";
8385             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8386             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8387                 return false;
8388             }
8389             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)))";
8390             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8391             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8392                 return false;
8393             }
8394             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8395             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8396             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8397                 return false;
8398             }
8399             final String p46_S = "";
8400             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8401             if ( p46.length != 0 ) {
8402                 return false;
8403             }
8404             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8405             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8406                 return false;
8407             }
8408             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8409             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8410                 return false;
8411             }
8412             final Phylogeny p49 = factory
8413                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8414                              new NHXParser() )[ 0 ];
8415             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8416                 return false;
8417             }
8418             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8419             if ( p50.getNode( "A" ) == null ) {
8420                 return false;
8421             }
8422             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8423                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8424                 return false;
8425             }
8426             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8427                 return false;
8428             }
8429             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8430                     .equals( "((A,B)88:2.0,C);" ) ) {
8431                 return false;
8432             }
8433             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8434             if ( p51.getNode( "A(A" ) == null ) {
8435                 return false;
8436             }
8437             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8438             if ( p52.getNode( "A(A" ) == null ) {
8439                 return false;
8440             }
8441             final Phylogeny p53 = factory
8442                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8443                              new NHXParser() )[ 0 ];
8444             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8445                 return false;
8446             }
8447             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8448             if ( p54.getNode( "A" ) == null ) {
8449                 return false;
8450             }
8451             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8452                 return false;
8453             }
8454             final Phylogeny p55 = factory
8455                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1  s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1x\":0.0798012);" ),
8456                              new NHXParser() )[ 0 ];
8457             if ( !p55
8458                     .toNewHampshire()
8459                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,lcl|HPV66_L1.1x:0.0798012);" ) ) {
8460                 System.out.println( p55.toNewHampshire() );
8461                 return false;
8462             }
8463             final Phylogeny p56 = factory
8464                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8465                              new NHXParser() )[ 0 ];
8466             if ( !p56
8467                     .toNewHampshire()
8468                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8469                 System.out.println( p56.toNewHampshire() );
8470                 return false;
8471             }
8472             final Phylogeny p57 = factory
8473                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8474                              new NHXParser() )[ 0 ];
8475             if ( !p57
8476                     .toNewHampshire()
8477                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8478                 System.out.println( p56.toNewHampshire() );
8479                 return false;
8480             }
8481             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8482             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8483             if ( !p58.toNewHampshire().equals( s58 ) ) {
8484                 System.out.println( p58.toNewHampshire() );
8485                 return false;
8486             }
8487             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8488             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8489             if ( !p59.toNewHampshire().equals( s59 ) ) {
8490                 System.out.println( p59.toNewHampshire() );
8491                 return false;
8492             }
8493             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8494             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8495             if ( !p60.toNewHampshire().equals( s60 ) ) {
8496                 System.out.println( p60.toNewHampshire() );
8497                 return false;
8498             }
8499             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8500             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8501             if ( !p61.toNewHampshire()
8502                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8503                 System.out.println( p61.toNewHampshire() );
8504                 return false;
8505             }
8506         }
8507         catch ( final Exception e ) {
8508             e.printStackTrace( System.out );
8509             return false;
8510         }
8511         return true;
8512     }
8513
8514     private static boolean testNHParsingIter() {
8515         try {
8516             final String p0_str = "(A,B);";
8517             final NHXParser p = new NHXParser();
8518             p.setSource( p0_str );
8519             if ( !p.hasNext() ) {
8520                 return false;
8521             }
8522             final Phylogeny p0 = p.next();
8523             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8524                 System.out.println( p0.toNewHampshire() );
8525                 return false;
8526             }
8527             if ( p.hasNext() ) {
8528                 return false;
8529             }
8530             if ( p.next() != null ) {
8531                 return false;
8532             }
8533             //
8534             final String p00_str = "(A,B)root;";
8535             p.setSource( p00_str );
8536             final Phylogeny p00 = p.next();
8537             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8538                 System.out.println( p00.toNewHampshire() );
8539                 return false;
8540             }
8541             //
8542             final String p000_str = "A;";
8543             p.setSource( p000_str );
8544             final Phylogeny p000 = p.next();
8545             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8546                 System.out.println( p000.toNewHampshire() );
8547                 return false;
8548             }
8549             //
8550             final String p0000_str = "A";
8551             p.setSource( p0000_str );
8552             final Phylogeny p0000 = p.next();
8553             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8554                 System.out.println( p0000.toNewHampshire() );
8555                 return false;
8556             }
8557             //
8558             p.setSource( "(A)" );
8559             final Phylogeny p00000 = p.next();
8560             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8561                 System.out.println( p00000.toNewHampshire() );
8562                 return false;
8563             }
8564             //
8565             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8566             p.setSource( p1_str );
8567             if ( !p.hasNext() ) {
8568                 return false;
8569             }
8570             final Phylogeny p1_0 = p.next();
8571             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8572                 System.out.println( p1_0.toNewHampshire() );
8573                 return false;
8574             }
8575             if ( !p.hasNext() ) {
8576                 return false;
8577             }
8578             final Phylogeny p1_1 = p.next();
8579             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8580                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8581                 return false;
8582             }
8583             if ( !p.hasNext() ) {
8584                 return false;
8585             }
8586             final Phylogeny p1_2 = p.next();
8587             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8588                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8589                 return false;
8590             }
8591             if ( !p.hasNext() ) {
8592                 return false;
8593             }
8594             final Phylogeny p1_3 = p.next();
8595             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8596                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8597                 return false;
8598             }
8599             if ( p.hasNext() ) {
8600                 return false;
8601             }
8602             if ( p.next() != null ) {
8603                 return false;
8604             }
8605             //
8606             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8607             p.setSource( p2_str );
8608             if ( !p.hasNext() ) {
8609                 return false;
8610             }
8611             Phylogeny p2_0 = p.next();
8612             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8613                 System.out.println( p2_0.toNewHampshire() );
8614                 return false;
8615             }
8616             if ( !p.hasNext() ) {
8617                 return false;
8618             }
8619             Phylogeny p2_1 = p.next();
8620             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8621                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8622                 return false;
8623             }
8624             if ( !p.hasNext() ) {
8625                 return false;
8626             }
8627             Phylogeny p2_2 = p.next();
8628             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8629                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8630                 return false;
8631             }
8632             if ( !p.hasNext() ) {
8633                 return false;
8634             }
8635             Phylogeny p2_3 = p.next();
8636             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8637                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8638                 return false;
8639             }
8640             if ( !p.hasNext() ) {
8641                 return false;
8642             }
8643             Phylogeny p2_4 = p.next();
8644             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8645                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8646                 return false;
8647             }
8648             if ( p.hasNext() ) {
8649                 return false;
8650             }
8651             if ( p.next() != null ) {
8652                 return false;
8653             }
8654             ////
8655             p.reset();
8656             if ( !p.hasNext() ) {
8657                 return false;
8658             }
8659             p2_0 = p.next();
8660             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8661                 System.out.println( p2_0.toNewHampshire() );
8662                 return false;
8663             }
8664             if ( !p.hasNext() ) {
8665                 return false;
8666             }
8667             p2_1 = p.next();
8668             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8669                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8670                 return false;
8671             }
8672             if ( !p.hasNext() ) {
8673                 return false;
8674             }
8675             p2_2 = p.next();
8676             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8677                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8678                 return false;
8679             }
8680             if ( !p.hasNext() ) {
8681                 return false;
8682             }
8683             p2_3 = p.next();
8684             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8685                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8686                 return false;
8687             }
8688             if ( !p.hasNext() ) {
8689                 return false;
8690             }
8691             p2_4 = p.next();
8692             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8693                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8694                 return false;
8695             }
8696             if ( p.hasNext() ) {
8697                 return false;
8698             }
8699             if ( p.next() != null ) {
8700                 return false;
8701             }
8702             //
8703             final String p3_str = "((A,B),C)abc";
8704             p.setSource( p3_str );
8705             if ( !p.hasNext() ) {
8706                 return false;
8707             }
8708             final Phylogeny p3_0 = p.next();
8709             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8710                 return false;
8711             }
8712             if ( p.hasNext() ) {
8713                 return false;
8714             }
8715             if ( p.next() != null ) {
8716                 return false;
8717             }
8718             //
8719             final String p4_str = "((A,B)ab,C)abc";
8720             p.setSource( p4_str );
8721             if ( !p.hasNext() ) {
8722                 return false;
8723             }
8724             final Phylogeny p4_0 = p.next();
8725             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8726                 return false;
8727             }
8728             if ( p.hasNext() ) {
8729                 return false;
8730             }
8731             if ( p.next() != null ) {
8732                 return false;
8733             }
8734             //
8735             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8736             p.setSource( p5_str );
8737             if ( !p.hasNext() ) {
8738                 return false;
8739             }
8740             final Phylogeny p5_0 = p.next();
8741             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8742                 return false;
8743             }
8744             if ( p.hasNext() ) {
8745                 return false;
8746             }
8747             if ( p.next() != null ) {
8748                 return false;
8749             }
8750             //
8751             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8752             p.setSource( p6_str );
8753             if ( !p.hasNext() ) {
8754                 return false;
8755             }
8756             Phylogeny p6_0 = p.next();
8757             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8758                 return false;
8759             }
8760             if ( p.hasNext() ) {
8761                 return false;
8762             }
8763             if ( p.next() != null ) {
8764                 return false;
8765             }
8766             p.reset();
8767             if ( !p.hasNext() ) {
8768                 return false;
8769             }
8770             p6_0 = p.next();
8771             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8772                 return false;
8773             }
8774             if ( p.hasNext() ) {
8775                 return false;
8776             }
8777             if ( p.next() != null ) {
8778                 return false;
8779             }
8780             //
8781             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8782             p.setSource( p7_str );
8783             if ( !p.hasNext() ) {
8784                 return false;
8785             }
8786             Phylogeny p7_0 = p.next();
8787             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8788                 return false;
8789             }
8790             if ( p.hasNext() ) {
8791                 return false;
8792             }
8793             if ( p.next() != null ) {
8794                 return false;
8795             }
8796             p.reset();
8797             if ( !p.hasNext() ) {
8798                 return false;
8799             }
8800             p7_0 = p.next();
8801             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8802                 return false;
8803             }
8804             if ( p.hasNext() ) {
8805                 return false;
8806             }
8807             if ( p.next() != null ) {
8808                 return false;
8809             }
8810             //
8811             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8812             p.setSource( p8_str );
8813             if ( !p.hasNext() ) {
8814                 return false;
8815             }
8816             Phylogeny p8_0 = p.next();
8817             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8818                 return false;
8819             }
8820             if ( !p.hasNext() ) {
8821                 return false;
8822             }
8823             if ( !p.hasNext() ) {
8824                 return false;
8825             }
8826             Phylogeny p8_1 = p.next();
8827             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8828                 return false;
8829             }
8830             if ( p.hasNext() ) {
8831                 return false;
8832             }
8833             if ( p.next() != null ) {
8834                 return false;
8835             }
8836             p.reset();
8837             if ( !p.hasNext() ) {
8838                 return false;
8839             }
8840             p8_0 = p.next();
8841             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8842                 return false;
8843             }
8844             if ( !p.hasNext() ) {
8845                 return false;
8846             }
8847             p8_1 = p.next();
8848             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8849                 return false;
8850             }
8851             if ( p.hasNext() ) {
8852                 return false;
8853             }
8854             if ( p.next() != null ) {
8855                 return false;
8856             }
8857             p.reset();
8858             //
8859             p.setSource( "" );
8860             if ( p.hasNext() ) {
8861                 return false;
8862             }
8863             //
8864             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8865             if ( !p.hasNext() ) {
8866                 return false;
8867             }
8868             Phylogeny p_27 = p.next();
8869             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8870                 System.out.println( p_27.toNewHampshireX() );
8871                 System.exit( -1 );
8872                 return false;
8873             }
8874             if ( p.hasNext() ) {
8875                 return false;
8876             }
8877             if ( p.next() != null ) {
8878                 return false;
8879             }
8880             p.reset();
8881             if ( !p.hasNext() ) {
8882                 return false;
8883             }
8884             p_27 = p.next();
8885             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8886                 System.out.println( p_27.toNewHampshireX() );
8887                 System.exit( -1 );
8888                 return false;
8889             }
8890             if ( p.hasNext() ) {
8891                 return false;
8892             }
8893             if ( p.next() != null ) {
8894                 return false;
8895             }
8896             //
8897             final String p30_str = "(A,B);(C,D)";
8898             final NHXParser p30 = new NHXParser();
8899             p30.setSource( p30_str );
8900             if ( !p30.hasNext() ) {
8901                 return false;
8902             }
8903             Phylogeny phy30 = p30.next();
8904             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8905                 System.out.println( phy30.toNewHampshire() );
8906                 return false;
8907             }
8908             if ( !p30.hasNext() ) {
8909                 return false;
8910             }
8911             Phylogeny phy301 = p30.next();
8912             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8913                 System.out.println( phy301.toNewHampshire() );
8914                 return false;
8915             }
8916             if ( p30.hasNext() ) {
8917                 return false;
8918             }
8919             if ( p30.hasNext() ) {
8920                 return false;
8921             }
8922             if ( p30.next() != null ) {
8923                 return false;
8924             }
8925             if ( p30.next() != null ) {
8926                 return false;
8927             }
8928             p30.reset();
8929             if ( !p30.hasNext() ) {
8930                 return false;
8931             }
8932             phy30 = p30.next();
8933             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8934                 System.out.println( phy30.toNewHampshire() );
8935                 return false;
8936             }
8937             if ( !p30.hasNext() ) {
8938                 return false;
8939             }
8940             phy301 = p30.next();
8941             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8942                 System.out.println( phy301.toNewHampshire() );
8943                 return false;
8944             }
8945             if ( p30.hasNext() ) {
8946                 return false;
8947             }
8948             if ( p30.hasNext() ) {
8949                 return false;
8950             }
8951             if ( p30.next() != null ) {
8952                 return false;
8953             }
8954             if ( p30.next() != null ) {
8955                 return false;
8956             }
8957         }
8958         catch ( final Exception e ) {
8959             e.printStackTrace( System.out );
8960             return false;
8961         }
8962         return true;
8963     }
8964
8965     private static boolean testNHXconversion() {
8966         try {
8967             final PhylogenyNode n1 = new PhylogenyNode();
8968             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8969             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8970             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8971             final PhylogenyNode n5 = PhylogenyNode
8972                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8973             final PhylogenyNode n6 = PhylogenyNode
8974                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8975             if ( !n1.toNewHampshireX().equals( "" ) ) {
8976                 return false;
8977             }
8978             if ( !n2.toNewHampshireX().equals( "" ) ) {
8979                 return false;
8980             }
8981             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8982                 return false;
8983             }
8984             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8985                 return false;
8986             }
8987             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8988                 return false;
8989             }
8990             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8991                 System.out.println( n6.toNewHampshireX() );
8992                 return false;
8993             }
8994             final PhylogenyNode n7 = new PhylogenyNode();
8995             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8996             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8997                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8998                 System.out.println( n7
8999                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9000                 return false;
9001             }
9002         }
9003         catch ( final Exception e ) {
9004             e.printStackTrace( System.out );
9005             return false;
9006         }
9007         return true;
9008     }
9009
9010     private static boolean testNHXNodeParsing() {
9011         try {
9012             final PhylogenyNode n1 = new PhylogenyNode();
9013             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9014             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9015             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9016             final PhylogenyNode n5 = PhylogenyNode
9017                     .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]" );
9018             if ( !n3.getName().equals( "n3" ) ) {
9019                 return false;
9020             }
9021             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9022                 return false;
9023             }
9024             if ( n3.isDuplication() ) {
9025                 return false;
9026             }
9027             if ( n3.isHasAssignedEvent() ) {
9028                 return false;
9029             }
9030             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9031                 return false;
9032             }
9033             if ( !n4.getName().equals( "n4" ) ) {
9034                 return false;
9035             }
9036             if ( n4.getDistanceToParent() != 0.01 ) {
9037                 return false;
9038             }
9039             if ( !n5.getName().equals( "n5" ) ) {
9040                 return false;
9041             }
9042             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9043                 return false;
9044             }
9045             if ( n5.getDistanceToParent() != 0.1 ) {
9046                 return false;
9047             }
9048             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9049                 return false;
9050             }
9051             if ( !n5.isDuplication() ) {
9052                 return false;
9053             }
9054             if ( !n5.isHasAssignedEvent() ) {
9055                 return false;
9056             }
9057             final PhylogenyNode n8 = PhylogenyNode
9058                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9059                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9060             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9061                 return false;
9062             }
9063             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9064                 return false;
9065             }
9066             final PhylogenyNode n9 = PhylogenyNode
9067                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9068                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9069             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9070                 return false;
9071             }
9072             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9073                 return false;
9074             }
9075             final PhylogenyNode n10 = PhylogenyNode
9076                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9077             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9078                 return false;
9079             }
9080             final PhylogenyNode n20 = PhylogenyNode
9081                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9082             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9083                 return false;
9084             }
9085             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9086                 return false;
9087             }
9088             final PhylogenyNode n20x = PhylogenyNode
9089                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9090             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9091                 return false;
9092             }
9093             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9094                 return false;
9095             }
9096             final PhylogenyNode n20xx = PhylogenyNode
9097                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9098             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9099                 return false;
9100             }
9101             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9102                 return false;
9103             }
9104             final PhylogenyNode n20xxx = PhylogenyNode
9105                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9106             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9107                 return false;
9108             }
9109             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9110                 return false;
9111             }
9112             final PhylogenyNode n20xxxx = PhylogenyNode
9113                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9114             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9115                 return false;
9116             }
9117             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9118                 return false;
9119             }
9120             final PhylogenyNode n21 = PhylogenyNode
9121                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9122             if ( !n21.getName().equals( "N21_PIG" ) ) {
9123                 return false;
9124             }
9125             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9126                 return false;
9127             }
9128             final PhylogenyNode n21x = PhylogenyNode
9129                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9130             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9131                 return false;
9132             }
9133             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9134                 return false;
9135             }
9136             final PhylogenyNode n22 = PhylogenyNode
9137                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9138             if ( !n22.getName().equals( "n22/PIG" ) ) {
9139                 return false;
9140             }
9141             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9142                 return false;
9143             }
9144             final PhylogenyNode n23 = PhylogenyNode
9145                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9146             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9147                 return false;
9148             }
9149             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9150                 return false;
9151             }
9152             final PhylogenyNode a = PhylogenyNode
9153                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9154             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9155                 return false;
9156             }
9157             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9158                 return false;
9159             }
9160             final PhylogenyNode c1 = PhylogenyNode
9161                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9162                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9163             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9164                 return false;
9165             }
9166             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9167                 return false;
9168             }
9169             final PhylogenyNode c2 = PhylogenyNode
9170                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9171                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9172             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9173                 return false;
9174             }
9175             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9176                 return false;
9177             }
9178             final PhylogenyNode e3 = PhylogenyNode
9179                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9180             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9181                 return false;
9182             }
9183             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9184                 return false;
9185             }
9186             final PhylogenyNode n11 = PhylogenyNode
9187                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9188                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9189             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9190                 return false;
9191             }
9192             if ( n11.getDistanceToParent() != 0.4 ) {
9193                 return false;
9194             }
9195             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9196                 return false;
9197             }
9198             final PhylogenyNode n12 = PhylogenyNode
9199                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9200                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9201             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9202                 return false;
9203             }
9204             if ( n12.getDistanceToParent() != 0.4 ) {
9205                 return false;
9206             }
9207             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9208                 return false;
9209             }
9210             final PhylogenyNode o = PhylogenyNode
9211                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9212             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9213                 return false;
9214             }
9215             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9216                 return false;
9217             }
9218             if ( n1.getName().compareTo( "" ) != 0 ) {
9219                 return false;
9220             }
9221             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9222                 return false;
9223             }
9224             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9225                 return false;
9226             }
9227             if ( n2.getName().compareTo( "" ) != 0 ) {
9228                 return false;
9229             }
9230             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9231                 return false;
9232             }
9233             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9234                 return false;
9235             }
9236             final PhylogenyNode n00 = PhylogenyNode
9237                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9238             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9239                 return false;
9240             }
9241             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9242                 return false;
9243             }
9244             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9245             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9246                 return false;
9247             }
9248             final PhylogenyNode n13 = PhylogenyNode
9249                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9250             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9251                 return false;
9252             }
9253             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9254                 return false;
9255             }
9256             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9257                 return false;
9258             }
9259             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9260                 return false;
9261             }
9262             final PhylogenyNode n14 = PhylogenyNode
9263                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9264             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9265                 return false;
9266             }
9267             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9268                 return false;
9269             }
9270             final PhylogenyNode n15 = PhylogenyNode
9271                     .createInstanceFromNhxString( "something_wicked[123]",
9272                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9273             if ( !n15.getName().equals( "something_wicked" ) ) {
9274                 return false;
9275             }
9276             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9277                 return false;
9278             }
9279             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9280                 return false;
9281             }
9282             final PhylogenyNode n16 = PhylogenyNode
9283                     .createInstanceFromNhxString( "something_wicked2[9]",
9284                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9285             if ( !n16.getName().equals( "something_wicked2" ) ) {
9286                 return false;
9287             }
9288             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9289                 return false;
9290             }
9291             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9292                 return false;
9293             }
9294             final PhylogenyNode n17 = PhylogenyNode
9295                     .createInstanceFromNhxString( "something_wicked3[a]",
9296                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9297             if ( !n17.getName().equals( "something_wicked3" ) ) {
9298                 return false;
9299             }
9300             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9301                 return false;
9302             }
9303             final PhylogenyNode n18 = PhylogenyNode
9304                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9305             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9306                 return false;
9307             }
9308             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9309                 return false;
9310             }
9311             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9312                 return false;
9313             }
9314             final PhylogenyNode n19 = PhylogenyNode
9315                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9316             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9317                 return false;
9318             }
9319             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9320                 return false;
9321             }
9322             final PhylogenyNode n30 = PhylogenyNode
9323                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9324                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9325             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9326                 return false;
9327             }
9328             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9329                 return false;
9330             }
9331             final PhylogenyNode n31 = PhylogenyNode
9332                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9333                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9334             if ( n31.getNodeData().isHasTaxonomy() ) {
9335                 return false;
9336             }
9337             final PhylogenyNode n32 = PhylogenyNode
9338                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9339             if ( n32.getNodeData().isHasTaxonomy() ) {
9340                 return false;
9341             }
9342             final PhylogenyNode n40 = PhylogenyNode
9343                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9344             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9345                 return false;
9346             }
9347             final PhylogenyNode n41 = PhylogenyNode
9348                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9349             if ( n41.getNodeData().isHasTaxonomy() ) {
9350                 return false;
9351             }
9352             final PhylogenyNode n42 = PhylogenyNode
9353                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9354             if ( n42.getNodeData().isHasTaxonomy() ) {
9355                 return false;
9356             }
9357             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9358                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9359             if ( n43.getNodeData().isHasTaxonomy() ) {
9360                 return false;
9361             }
9362             final PhylogenyNode n44 = PhylogenyNode
9363                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9364             if ( n44.getNodeData().isHasTaxonomy() ) {
9365                 return false;
9366             }
9367         }
9368         catch ( final Exception e ) {
9369             e.printStackTrace( System.out );
9370             return false;
9371         }
9372         return true;
9373     }
9374
9375     private static boolean testNHXParsing() {
9376         try {
9377             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9378             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9379             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9380                 return false;
9381             }
9382             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]";
9383             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9384             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9385                 return false;
9386             }
9387             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]";
9388             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9389             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9390                 return false;
9391             }
9392             final Phylogeny[] p3 = factory
9393                     .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]",
9394                              new NHXParser() );
9395             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9396                 return false;
9397             }
9398             final Phylogeny[] p4 = factory
9399                     .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(]",
9400                              new NHXParser() );
9401             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9402                 return false;
9403             }
9404             final Phylogeny[] p5 = factory
9405                     .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(((]",
9406                              new NHXParser() );
9407             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9408                 return false;
9409             }
9410             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)";
9411             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)";
9412             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9413             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9414                 return false;
9415             }
9416             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)))";
9417             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)))";
9418             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9419             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9420                 return false;
9421             }
9422             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])   ))[,,, ])))))))";
9423             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9424             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9425             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9426                 return false;
9427             }
9428             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9429             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9430                 return false;
9431             }
9432             final Phylogeny p10 = factory
9433                     .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]",
9434                              new NHXParser() )[ 0 ];
9435             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9436                 return false;
9437             }
9438             final Phylogeny p11 = factory
9439                     .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]",
9440                              new NHXParser() )[ 0 ];
9441             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9442                 return false;
9443             }
9444         }
9445         catch ( final Exception e ) {
9446             e.printStackTrace( System.out );
9447             return false;
9448         }
9449         return true;
9450     }
9451
9452     private static boolean testNHXParsingMB() {
9453         try {
9454             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9455             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9456                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9457                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9458                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9459                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9460                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9461                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9462                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9463                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9464             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9465                 return false;
9466             }
9467             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9468                 return false;
9469             }
9470             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9471                            0.1100000000000000e+00 ) ) {
9472                 return false;
9473             }
9474             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9475                 return false;
9476             }
9477             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9478                 return false;
9479             }
9480             final Phylogeny p2 = factory
9481                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9482                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9483                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9484                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9485                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9486                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9487                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9488                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9489                                      + "7.369400000000000e-02}])",
9490                              new NHXParser() )[ 0 ];
9491             if ( p2.getNode( "1" ) == null ) {
9492                 return false;
9493             }
9494             if ( p2.getNode( "2" ) == null ) {
9495                 return false;
9496             }
9497         }
9498         catch ( final Exception e ) {
9499             e.printStackTrace( System.out );
9500             System.exit( -1 );
9501             return false;
9502         }
9503         return true;
9504     }
9505
9506     private static boolean testNHXParsingQuotes() {
9507         try {
9508             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9509             final NHXParser p = new NHXParser();
9510             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9511             if ( phylogenies_0.length != 5 ) {
9512                 return false;
9513             }
9514             final Phylogeny phy = phylogenies_0[ 4 ];
9515             if ( phy.getNumberOfExternalNodes() != 7 ) {
9516                 return false;
9517             }
9518             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9519                 return false;
9520             }
9521             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9522                 return false;
9523             }
9524             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9525                     .getScientificName().equals( "hsapiens" ) ) {
9526                 return false;
9527             }
9528             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9529                 return false;
9530             }
9531             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9532                 return false;
9533             }
9534             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9535                 return false;
9536             }
9537             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9538                 return false;
9539             }
9540             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9541                 return false;
9542             }
9543             final NHXParser p1p = new NHXParser();
9544             p1p.setIgnoreQuotes( true );
9545             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9546             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9547                 return false;
9548             }
9549             final NHXParser p2p = new NHXParser();
9550             p1p.setIgnoreQuotes( false );
9551             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9552             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9553                 return false;
9554             }
9555             final NHXParser p3p = new NHXParser();
9556             p3p.setIgnoreQuotes( false );
9557             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9558             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9559                 return false;
9560             }
9561             final NHXParser p4p = new NHXParser();
9562             p4p.setIgnoreQuotes( false );
9563             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9564             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9565                 return false;
9566             }
9567             final Phylogeny p10 = factory
9568                     .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]",
9569                              new NHXParser() )[ 0 ];
9570             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]";
9571             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9572                 return false;
9573             }
9574             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9575             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9576                 return false;
9577             }
9578             final Phylogeny p12 = factory
9579                     .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]",
9580                              new NHXParser() )[ 0 ];
9581             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]";
9582             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9583                 return false;
9584             }
9585             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9586             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9587                 return false;
9588             }
9589             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;";
9590             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9591                 return false;
9592             }
9593             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9594             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9595                 return false;
9596             }
9597         }
9598         catch ( final Exception e ) {
9599             e.printStackTrace( System.out );
9600             return false;
9601         }
9602         return true;
9603     }
9604
9605     private static boolean testNodeRemoval() {
9606         try {
9607             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9608             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9609             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9610             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9611                 return false;
9612             }
9613             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9614             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9615             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9616                 return false;
9617             }
9618             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9619             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9620             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9621                 return false;
9622             }
9623         }
9624         catch ( final Exception e ) {
9625             e.printStackTrace( System.out );
9626             return false;
9627         }
9628         return true;
9629     }
9630
9631     private static boolean testPhylogenyBranch() {
9632         try {
9633             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9634             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9635             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9636             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9637             if ( !a1b1.equals( a1b1 ) ) {
9638                 return false;
9639             }
9640             if ( !a1b1.equals( b1a1 ) ) {
9641                 return false;
9642             }
9643             if ( !b1a1.equals( a1b1 ) ) {
9644                 return false;
9645             }
9646             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9647             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9648             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9649             if ( a1_b1.equals( b1_a1 ) ) {
9650                 return false;
9651             }
9652             if ( a1_b1.equals( a1_b1_ ) ) {
9653                 return false;
9654             }
9655             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9656             if ( !a1_b1.equals( b1_a1_ ) ) {
9657                 return false;
9658             }
9659             if ( a1_b1_.equals( b1_a1_ ) ) {
9660                 return false;
9661             }
9662             if ( !a1_b1_.equals( b1_a1 ) ) {
9663                 return false;
9664             }
9665         }
9666         catch ( final Exception e ) {
9667             e.printStackTrace( System.out );
9668             return false;
9669         }
9670         return true;
9671     }
9672
9673     private static boolean testPhyloXMLparsingOfDistributionElement() {
9674         try {
9675             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9676             PhyloXmlParser xml_parser = null;
9677             try {
9678                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9679             }
9680             catch ( final Exception e ) {
9681                 // Do nothing -- means were not running from jar.
9682             }
9683             if ( xml_parser == null ) {
9684                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9685                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9686                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9687                 }
9688                 else {
9689                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9690                 }
9691             }
9692             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9693                                                               xml_parser );
9694             if ( xml_parser.getErrorCount() > 0 ) {
9695                 System.out.println( xml_parser.getErrorMessages().toString() );
9696                 return false;
9697             }
9698             if ( phylogenies_0.length != 1 ) {
9699                 return false;
9700             }
9701             final Phylogeny t1 = phylogenies_0[ 0 ];
9702             PhylogenyNode n = null;
9703             Distribution d = null;
9704             n = t1.getNode( "root node" );
9705             if ( !n.getNodeData().isHasDistribution() ) {
9706                 return false;
9707             }
9708             if ( n.getNodeData().getDistributions().size() != 1 ) {
9709                 return false;
9710             }
9711             d = n.getNodeData().getDistribution();
9712             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9713                 return false;
9714             }
9715             if ( d.getPoints().size() != 1 ) {
9716                 return false;
9717             }
9718             if ( d.getPolygons() != null ) {
9719                 return false;
9720             }
9721             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9722                 return false;
9723             }
9724             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9725                 return false;
9726             }
9727             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9728                 return false;
9729             }
9730             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9731                 return false;
9732             }
9733             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9734                 return false;
9735             }
9736             n = t1.getNode( "node a" );
9737             if ( !n.getNodeData().isHasDistribution() ) {
9738                 return false;
9739             }
9740             if ( n.getNodeData().getDistributions().size() != 2 ) {
9741                 return false;
9742             }
9743             d = n.getNodeData().getDistribution( 1 );
9744             if ( !d.getDesc().equals( "San Diego" ) ) {
9745                 return false;
9746             }
9747             if ( d.getPoints().size() != 1 ) {
9748                 return false;
9749             }
9750             if ( d.getPolygons() != null ) {
9751                 return false;
9752             }
9753             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9754                 return false;
9755             }
9756             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9757                 return false;
9758             }
9759             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9760                 return false;
9761             }
9762             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9763                 return false;
9764             }
9765             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9766                 return false;
9767             }
9768             n = t1.getNode( "node bb" );
9769             if ( !n.getNodeData().isHasDistribution() ) {
9770                 return false;
9771             }
9772             if ( n.getNodeData().getDistributions().size() != 1 ) {
9773                 return false;
9774             }
9775             d = n.getNodeData().getDistribution( 0 );
9776             if ( d.getPoints().size() != 3 ) {
9777                 return false;
9778             }
9779             if ( d.getPolygons().size() != 2 ) {
9780                 return false;
9781             }
9782             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9783                 return false;
9784             }
9785             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9786                 return false;
9787             }
9788             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9789                 return false;
9790             }
9791             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9792                 return false;
9793             }
9794             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9795                 return false;
9796             }
9797             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9798                 return false;
9799             }
9800             Polygon p = d.getPolygons().get( 0 );
9801             if ( p.getPoints().size() != 3 ) {
9802                 return false;
9803             }
9804             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9805                 return false;
9806             }
9807             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9808                 return false;
9809             }
9810             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9811                 return false;
9812             }
9813             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9814                 return false;
9815             }
9816             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9817                 return false;
9818             }
9819             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9820                 return false;
9821             }
9822             p = d.getPolygons().get( 1 );
9823             if ( p.getPoints().size() != 3 ) {
9824                 return false;
9825             }
9826             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9827                 return false;
9828             }
9829             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9830                 return false;
9831             }
9832             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9833                 return false;
9834             }
9835             // Roundtrip:
9836             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9837             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9838             if ( rt.length != 1 ) {
9839                 return false;
9840             }
9841             final Phylogeny t1_rt = rt[ 0 ];
9842             n = t1_rt.getNode( "root node" );
9843             if ( !n.getNodeData().isHasDistribution() ) {
9844                 return false;
9845             }
9846             if ( n.getNodeData().getDistributions().size() != 1 ) {
9847                 return false;
9848             }
9849             d = n.getNodeData().getDistribution();
9850             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9851                 return false;
9852             }
9853             if ( d.getPoints().size() != 1 ) {
9854                 return false;
9855             }
9856             if ( d.getPolygons() != null ) {
9857                 return false;
9858             }
9859             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9860                 return false;
9861             }
9862             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9863                 return false;
9864             }
9865             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9866                 return false;
9867             }
9868             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9869                 return false;
9870             }
9871             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9872                 return false;
9873             }
9874             n = t1_rt.getNode( "node a" );
9875             if ( !n.getNodeData().isHasDistribution() ) {
9876                 return false;
9877             }
9878             if ( n.getNodeData().getDistributions().size() != 2 ) {
9879                 return false;
9880             }
9881             d = n.getNodeData().getDistribution( 1 );
9882             if ( !d.getDesc().equals( "San Diego" ) ) {
9883                 return false;
9884             }
9885             if ( d.getPoints().size() != 1 ) {
9886                 return false;
9887             }
9888             if ( d.getPolygons() != null ) {
9889                 return false;
9890             }
9891             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9892                 return false;
9893             }
9894             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9895                 return false;
9896             }
9897             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9898                 return false;
9899             }
9900             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9901                 return false;
9902             }
9903             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9904                 return false;
9905             }
9906             n = t1_rt.getNode( "node bb" );
9907             if ( !n.getNodeData().isHasDistribution() ) {
9908                 return false;
9909             }
9910             if ( n.getNodeData().getDistributions().size() != 1 ) {
9911                 return false;
9912             }
9913             d = n.getNodeData().getDistribution( 0 );
9914             if ( d.getPoints().size() != 3 ) {
9915                 return false;
9916             }
9917             if ( d.getPolygons().size() != 2 ) {
9918                 return false;
9919             }
9920             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9921                 return false;
9922             }
9923             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9924                 return false;
9925             }
9926             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9927                 return false;
9928             }
9929             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9930                 return false;
9931             }
9932             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9933                 return false;
9934             }
9935             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9936                 return false;
9937             }
9938             p = d.getPolygons().get( 0 );
9939             if ( p.getPoints().size() != 3 ) {
9940                 return false;
9941             }
9942             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9943                 return false;
9944             }
9945             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9946                 return false;
9947             }
9948             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9949                 return false;
9950             }
9951             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9952                 return false;
9953             }
9954             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9955                 return false;
9956             }
9957             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9958                 return false;
9959             }
9960             p = d.getPolygons().get( 1 );
9961             if ( p.getPoints().size() != 3 ) {
9962                 return false;
9963             }
9964             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9965                 return false;
9966             }
9967             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9968                 return false;
9969             }
9970             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9971                 return false;
9972             }
9973         }
9974         catch ( final Exception e ) {
9975             e.printStackTrace( System.out );
9976             return false;
9977         }
9978         return true;
9979     }
9980
9981     private static boolean testPostOrderIterator() {
9982         try {
9983             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9984             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9985             PhylogenyNodeIterator it0;
9986             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9987                 it0.next();
9988             }
9989             for( it0.reset(); it0.hasNext(); ) {
9990                 it0.next();
9991             }
9992             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9993             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9994             if ( !it.next().getName().equals( "A" ) ) {
9995                 return false;
9996             }
9997             if ( !it.next().getName().equals( "B" ) ) {
9998                 return false;
9999             }
10000             if ( !it.next().getName().equals( "ab" ) ) {
10001                 return false;
10002             }
10003             if ( !it.next().getName().equals( "C" ) ) {
10004                 return false;
10005             }
10006             if ( !it.next().getName().equals( "D" ) ) {
10007                 return false;
10008             }
10009             if ( !it.next().getName().equals( "cd" ) ) {
10010                 return false;
10011             }
10012             if ( !it.next().getName().equals( "abcd" ) ) {
10013                 return false;
10014             }
10015             if ( !it.next().getName().equals( "E" ) ) {
10016                 return false;
10017             }
10018             if ( !it.next().getName().equals( "F" ) ) {
10019                 return false;
10020             }
10021             if ( !it.next().getName().equals( "ef" ) ) {
10022                 return false;
10023             }
10024             if ( !it.next().getName().equals( "G" ) ) {
10025                 return false;
10026             }
10027             if ( !it.next().getName().equals( "H" ) ) {
10028                 return false;
10029             }
10030             if ( !it.next().getName().equals( "gh" ) ) {
10031                 return false;
10032             }
10033             if ( !it.next().getName().equals( "efgh" ) ) {
10034                 return false;
10035             }
10036             if ( !it.next().getName().equals( "r" ) ) {
10037                 return false;
10038             }
10039             if ( it.hasNext() ) {
10040                 return false;
10041             }
10042         }
10043         catch ( final Exception e ) {
10044             e.printStackTrace( System.out );
10045             return false;
10046         }
10047         return true;
10048     }
10049
10050     private static boolean testPreOrderIterator() {
10051         try {
10052             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10053             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10054             PhylogenyNodeIterator it0;
10055             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10056                 it0.next();
10057             }
10058             for( it0.reset(); it0.hasNext(); ) {
10059                 it0.next();
10060             }
10061             PhylogenyNodeIterator it = t0.iteratorPreorder();
10062             if ( !it.next().getName().equals( "r" ) ) {
10063                 return false;
10064             }
10065             if ( !it.next().getName().equals( "ab" ) ) {
10066                 return false;
10067             }
10068             if ( !it.next().getName().equals( "A" ) ) {
10069                 return false;
10070             }
10071             if ( !it.next().getName().equals( "B" ) ) {
10072                 return false;
10073             }
10074             if ( !it.next().getName().equals( "cd" ) ) {
10075                 return false;
10076             }
10077             if ( !it.next().getName().equals( "C" ) ) {
10078                 return false;
10079             }
10080             if ( !it.next().getName().equals( "D" ) ) {
10081                 return false;
10082             }
10083             if ( it.hasNext() ) {
10084                 return false;
10085             }
10086             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10087             it = t1.iteratorPreorder();
10088             if ( !it.next().getName().equals( "r" ) ) {
10089                 return false;
10090             }
10091             if ( !it.next().getName().equals( "abcd" ) ) {
10092                 return false;
10093             }
10094             if ( !it.next().getName().equals( "ab" ) ) {
10095                 return false;
10096             }
10097             if ( !it.next().getName().equals( "A" ) ) {
10098                 return false;
10099             }
10100             if ( !it.next().getName().equals( "B" ) ) {
10101                 return false;
10102             }
10103             if ( !it.next().getName().equals( "cd" ) ) {
10104                 return false;
10105             }
10106             if ( !it.next().getName().equals( "C" ) ) {
10107                 return false;
10108             }
10109             if ( !it.next().getName().equals( "D" ) ) {
10110                 return false;
10111             }
10112             if ( !it.next().getName().equals( "efgh" ) ) {
10113                 return false;
10114             }
10115             if ( !it.next().getName().equals( "ef" ) ) {
10116                 return false;
10117             }
10118             if ( !it.next().getName().equals( "E" ) ) {
10119                 return false;
10120             }
10121             if ( !it.next().getName().equals( "F" ) ) {
10122                 return false;
10123             }
10124             if ( !it.next().getName().equals( "gh" ) ) {
10125                 return false;
10126             }
10127             if ( !it.next().getName().equals( "G" ) ) {
10128                 return false;
10129             }
10130             if ( !it.next().getName().equals( "H" ) ) {
10131                 return false;
10132             }
10133             if ( it.hasNext() ) {
10134                 return false;
10135             }
10136         }
10137         catch ( final Exception e ) {
10138             e.printStackTrace( System.out );
10139             return false;
10140         }
10141         return true;
10142     }
10143
10144     private static boolean testPropertiesMap() {
10145         try {
10146             final PropertiesMap pm = new PropertiesMap();
10147             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10148             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10149             final Property p2 = new Property( "something:else",
10150                                               "?",
10151                                               "improbable:research",
10152                                               "xsd:decimal",
10153                                               AppliesTo.NODE );
10154             pm.addProperty( p0 );
10155             pm.addProperty( p1 );
10156             pm.addProperty( p2 );
10157             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10158                 return false;
10159             }
10160             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10161                 return false;
10162             }
10163             if ( pm.getProperties().size() != 3 ) {
10164                 return false;
10165             }
10166             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10167                 return false;
10168             }
10169             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10170                 return false;
10171             }
10172             if ( pm.getProperties().size() != 3 ) {
10173                 return false;
10174             }
10175             pm.removeProperty( "dimensions:diameter" );
10176             if ( pm.getProperties().size() != 2 ) {
10177                 return false;
10178             }
10179             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10180                 return false;
10181             }
10182             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10183                 return false;
10184             }
10185         }
10186         catch ( final Exception e ) {
10187             e.printStackTrace( System.out );
10188             return false;
10189         }
10190         return true;
10191     }
10192
10193     private static boolean testProteinId() {
10194         try {
10195             final ProteinId id1 = new ProteinId( "a" );
10196             final ProteinId id2 = new ProteinId( "a" );
10197             final ProteinId id3 = new ProteinId( "A" );
10198             final ProteinId id4 = new ProteinId( "b" );
10199             if ( !id1.equals( id1 ) ) {
10200                 return false;
10201             }
10202             if ( id1.getId().equals( "x" ) ) {
10203                 return false;
10204             }
10205             if ( id1.getId().equals( null ) ) {
10206                 return false;
10207             }
10208             if ( !id1.equals( id2 ) ) {
10209                 return false;
10210             }
10211             if ( id1.equals( id3 ) ) {
10212                 return false;
10213             }
10214             if ( id1.hashCode() != id1.hashCode() ) {
10215                 return false;
10216             }
10217             if ( id1.hashCode() != id2.hashCode() ) {
10218                 return false;
10219             }
10220             if ( id1.hashCode() == id3.hashCode() ) {
10221                 return false;
10222             }
10223             if ( id1.compareTo( id1 ) != 0 ) {
10224                 return false;
10225             }
10226             if ( id1.compareTo( id2 ) != 0 ) {
10227                 return false;
10228             }
10229             if ( id1.compareTo( id3 ) != 0 ) {
10230                 return false;
10231             }
10232             if ( id1.compareTo( id4 ) >= 0 ) {
10233                 return false;
10234             }
10235             if ( id4.compareTo( id1 ) <= 0 ) {
10236                 return false;
10237             }
10238             if ( !id4.getId().equals( "b" ) ) {
10239                 return false;
10240             }
10241             final ProteinId id5 = new ProteinId( " C " );
10242             if ( !id5.getId().equals( "C" ) ) {
10243                 return false;
10244             }
10245             if ( id5.equals( id1 ) ) {
10246                 return false;
10247             }
10248         }
10249         catch ( final Exception e ) {
10250             e.printStackTrace( System.out );
10251             return false;
10252         }
10253         return true;
10254     }
10255
10256     private static boolean testReIdMethods() {
10257         try {
10258             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10259             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10260             final long count = PhylogenyNode.getNodeCount();
10261             p.levelOrderReID();
10262             if ( p.getNode( "r" ).getId() != count ) {
10263                 return false;
10264             }
10265             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10266                 return false;
10267             }
10268             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10269                 return false;
10270             }
10271             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10272                 return false;
10273             }
10274             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10275                 return false;
10276             }
10277             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10278                 return false;
10279             }
10280             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10281                 return false;
10282             }
10283             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10284                 return false;
10285             }
10286             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10287                 return false;
10288             }
10289             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10290                 return false;
10291             }
10292             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10293                 return false;
10294             }
10295             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10296                 return false;
10297             }
10298             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10299                 return false;
10300             }
10301             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10302                 return false;
10303             }
10304             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10305                 return false;
10306             }
10307         }
10308         catch ( final Exception e ) {
10309             e.printStackTrace( System.out );
10310             return false;
10311         }
10312         return true;
10313     }
10314
10315     private static boolean testRerooting() {
10316         try {
10317             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10318             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",
10319                                                  new NHXParser() )[ 0 ];
10320             if ( !t1.isRooted() ) {
10321                 return false;
10322             }
10323             t1.reRoot( t1.getNode( "D" ) );
10324             t1.reRoot( t1.getNode( "CD" ) );
10325             t1.reRoot( t1.getNode( "A" ) );
10326             t1.reRoot( t1.getNode( "B" ) );
10327             t1.reRoot( t1.getNode( "AB" ) );
10328             t1.reRoot( t1.getNode( "D" ) );
10329             t1.reRoot( t1.getNode( "C" ) );
10330             t1.reRoot( t1.getNode( "CD" ) );
10331             t1.reRoot( t1.getNode( "A" ) );
10332             t1.reRoot( t1.getNode( "B" ) );
10333             t1.reRoot( t1.getNode( "AB" ) );
10334             t1.reRoot( t1.getNode( "D" ) );
10335             t1.reRoot( t1.getNode( "D" ) );
10336             t1.reRoot( t1.getNode( "C" ) );
10337             t1.reRoot( t1.getNode( "A" ) );
10338             t1.reRoot( t1.getNode( "B" ) );
10339             t1.reRoot( t1.getNode( "AB" ) );
10340             t1.reRoot( t1.getNode( "C" ) );
10341             t1.reRoot( t1.getNode( "D" ) );
10342             t1.reRoot( t1.getNode( "CD" ) );
10343             t1.reRoot( t1.getNode( "D" ) );
10344             t1.reRoot( t1.getNode( "A" ) );
10345             t1.reRoot( t1.getNode( "B" ) );
10346             t1.reRoot( t1.getNode( "AB" ) );
10347             t1.reRoot( t1.getNode( "C" ) );
10348             t1.reRoot( t1.getNode( "D" ) );
10349             t1.reRoot( t1.getNode( "CD" ) );
10350             t1.reRoot( t1.getNode( "D" ) );
10351             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10352                 return false;
10353             }
10354             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10355                 return false;
10356             }
10357             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10358                 return false;
10359             }
10360             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10361                 return false;
10362             }
10363             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10364                 return false;
10365             }
10366             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10367                 return false;
10368             }
10369             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",
10370                                                  new NHXParser() )[ 0 ];
10371             t2.reRoot( t2.getNode( "A" ) );
10372             t2.reRoot( t2.getNode( "D" ) );
10373             t2.reRoot( t2.getNode( "ABC" ) );
10374             t2.reRoot( t2.getNode( "A" ) );
10375             t2.reRoot( t2.getNode( "B" ) );
10376             t2.reRoot( t2.getNode( "D" ) );
10377             t2.reRoot( t2.getNode( "C" ) );
10378             t2.reRoot( t2.getNode( "ABC" ) );
10379             t2.reRoot( t2.getNode( "A" ) );
10380             t2.reRoot( t2.getNode( "B" ) );
10381             t2.reRoot( t2.getNode( "AB" ) );
10382             t2.reRoot( t2.getNode( "AB" ) );
10383             t2.reRoot( t2.getNode( "D" ) );
10384             t2.reRoot( t2.getNode( "C" ) );
10385             t2.reRoot( t2.getNode( "B" ) );
10386             t2.reRoot( t2.getNode( "AB" ) );
10387             t2.reRoot( t2.getNode( "D" ) );
10388             t2.reRoot( t2.getNode( "D" ) );
10389             t2.reRoot( t2.getNode( "ABC" ) );
10390             t2.reRoot( t2.getNode( "A" ) );
10391             t2.reRoot( t2.getNode( "B" ) );
10392             t2.reRoot( t2.getNode( "AB" ) );
10393             t2.reRoot( t2.getNode( "D" ) );
10394             t2.reRoot( t2.getNode( "C" ) );
10395             t2.reRoot( t2.getNode( "ABC" ) );
10396             t2.reRoot( t2.getNode( "A" ) );
10397             t2.reRoot( t2.getNode( "B" ) );
10398             t2.reRoot( t2.getNode( "AB" ) );
10399             t2.reRoot( t2.getNode( "D" ) );
10400             t2.reRoot( t2.getNode( "D" ) );
10401             t2.reRoot( t2.getNode( "C" ) );
10402             t2.reRoot( t2.getNode( "A" ) );
10403             t2.reRoot( t2.getNode( "B" ) );
10404             t2.reRoot( t2.getNode( "AB" ) );
10405             t2.reRoot( t2.getNode( "C" ) );
10406             t2.reRoot( t2.getNode( "D" ) );
10407             t2.reRoot( t2.getNode( "ABC" ) );
10408             t2.reRoot( t2.getNode( "D" ) );
10409             t2.reRoot( t2.getNode( "A" ) );
10410             t2.reRoot( t2.getNode( "B" ) );
10411             t2.reRoot( t2.getNode( "AB" ) );
10412             t2.reRoot( t2.getNode( "C" ) );
10413             t2.reRoot( t2.getNode( "D" ) );
10414             t2.reRoot( t2.getNode( "ABC" ) );
10415             t2.reRoot( t2.getNode( "D" ) );
10416             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10417                 return false;
10418             }
10419             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10420                 return false;
10421             }
10422             t2.reRoot( t2.getNode( "ABC" ) );
10423             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10424                 return false;
10425             }
10426             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10427                 return false;
10428             }
10429             t2.reRoot( t2.getNode( "AB" ) );
10430             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10431                 return false;
10432             }
10433             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10434                 return false;
10435             }
10436             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10437                 return false;
10438             }
10439             t2.reRoot( t2.getNode( "AB" ) );
10440             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10441                 return false;
10442             }
10443             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10444                 return false;
10445             }
10446             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10447                 return false;
10448             }
10449             t2.reRoot( t2.getNode( "D" ) );
10450             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10451                 return false;
10452             }
10453             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10454                 return false;
10455             }
10456             t2.reRoot( t2.getNode( "ABC" ) );
10457             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10458                 return false;
10459             }
10460             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10461                 return false;
10462             }
10463             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10464                                                  new NHXParser() )[ 0 ];
10465             t3.reRoot( t3.getNode( "B" ) );
10466             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10467                 return false;
10468             }
10469             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10470                 return false;
10471             }
10472             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10473                 return false;
10474             }
10475             t3.reRoot( t3.getNode( "B" ) );
10476             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10477                 return false;
10478             }
10479             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10480                 return false;
10481             }
10482             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10483                 return false;
10484             }
10485             t3.reRoot( t3.getRoot() );
10486             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10487                 return false;
10488             }
10489             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10490                 return false;
10491             }
10492             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10493                 return false;
10494             }
10495         }
10496         catch ( final Exception e ) {
10497             e.printStackTrace( System.out );
10498             return false;
10499         }
10500         return true;
10501     }
10502
10503     private static boolean testSDIse() {
10504         try {
10505             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10506             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10507             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10508             gene1.setRooted( true );
10509             species1.setRooted( true );
10510             final SDI sdi = new SDI( gene1, species1 );
10511             if ( !gene1.getRoot().isDuplication() ) {
10512                 return false;
10513             }
10514             final Phylogeny species2 = factory
10515                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10516                              new NHXParser() )[ 0 ];
10517             final Phylogeny gene2 = factory
10518                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10519                              new NHXParser() )[ 0 ];
10520             species2.setRooted( true );
10521             gene2.setRooted( true );
10522             final SDI sdi2 = new SDI( gene2, species2 );
10523             if ( sdi2.getDuplicationsSum() != 0 ) {
10524                 return false;
10525             }
10526             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10527                 return false;
10528             }
10529             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10530                 return false;
10531             }
10532             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10533                 return false;
10534             }
10535             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10536                 return false;
10537             }
10538             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10539                 return false;
10540             }
10541             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10542                 return false;
10543             }
10544             final Phylogeny species3 = factory
10545                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10546                              new NHXParser() )[ 0 ];
10547             final Phylogeny gene3 = factory
10548                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10549                              new NHXParser() )[ 0 ];
10550             species3.setRooted( true );
10551             gene3.setRooted( true );
10552             final SDI sdi3 = new SDI( gene3, species3 );
10553             if ( sdi3.getDuplicationsSum() != 1 ) {
10554                 return false;
10555             }
10556             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10557                 return false;
10558             }
10559             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10560                 return false;
10561             }
10562             final Phylogeny species4 = factory
10563                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10564                              new NHXParser() )[ 0 ];
10565             final Phylogeny gene4 = factory
10566                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10567                              new NHXParser() )[ 0 ];
10568             species4.setRooted( true );
10569             gene4.setRooted( true );
10570             final SDI sdi4 = new SDI( gene4, species4 );
10571             if ( sdi4.getDuplicationsSum() != 1 ) {
10572                 return false;
10573             }
10574             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10575                 return false;
10576             }
10577             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10578                 return false;
10579             }
10580             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10581                 return false;
10582             }
10583             if ( species4.getNumberOfExternalNodes() != 6 ) {
10584                 return false;
10585             }
10586             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10587                 return false;
10588             }
10589             final Phylogeny species5 = factory
10590                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10591                              new NHXParser() )[ 0 ];
10592             final Phylogeny gene5 = factory
10593                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10594                              new NHXParser() )[ 0 ];
10595             species5.setRooted( true );
10596             gene5.setRooted( true );
10597             final SDI sdi5 = new SDI( gene5, species5 );
10598             if ( sdi5.getDuplicationsSum() != 2 ) {
10599                 return false;
10600             }
10601             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10602                 return false;
10603             }
10604             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10605                 return false;
10606             }
10607             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10608                 return false;
10609             }
10610             if ( species5.getNumberOfExternalNodes() != 6 ) {
10611                 return false;
10612             }
10613             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10614                 return false;
10615             }
10616             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10617             // Conjecture for Comparing Molecular Phylogenies"
10618             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10619             final Phylogeny species6 = factory
10620                     .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,"
10621                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10622                              new NHXParser() )[ 0 ];
10623             final Phylogeny gene6 = factory
10624                     .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,"
10625                                      + "((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,"
10626                                      + "(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;",
10627                              new NHXParser() )[ 0 ];
10628             species6.setRooted( true );
10629             gene6.setRooted( true );
10630             final SDI sdi6 = new SDI( gene6, species6 );
10631             if ( sdi6.getDuplicationsSum() != 3 ) {
10632                 return false;
10633             }
10634             if ( !gene6.getNode( "r" ).isDuplication() ) {
10635                 return false;
10636             }
10637             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10638                 return false;
10639             }
10640             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10641                 return false;
10642             }
10643             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10644                 return false;
10645             }
10646             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10647                 return false;
10648             }
10649             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10650                 return false;
10651             }
10652             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10653                 return false;
10654             }
10655             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10656                 return false;
10657             }
10658             sdi6.computeMappingCostL();
10659             if ( sdi6.computeMappingCostL() != 17 ) {
10660                 return false;
10661             }
10662             if ( species6.getNumberOfExternalNodes() != 9 ) {
10663                 return false;
10664             }
10665             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10666                 return false;
10667             }
10668             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10669                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10670                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10671                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10672                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10673             species7.setRooted( true );
10674             final Phylogeny gene7_1 = Test
10675                     .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])" );
10676             gene7_1.setRooted( true );
10677             final SDI sdi7 = new SDI( gene7_1, species7 );
10678             if ( sdi7.getDuplicationsSum() != 0 ) {
10679                 return false;
10680             }
10681             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10682                 return false;
10683             }
10684             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10685                 return false;
10686             }
10687             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10688                 return false;
10689             }
10690             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10691                 return false;
10692             }
10693             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10694                 return false;
10695             }
10696             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10697                 return false;
10698             }
10699             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10700                 return false;
10701             }
10702             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10703                 return false;
10704             }
10705             final Phylogeny gene7_2 = Test
10706                     .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])" );
10707             gene7_2.setRooted( true );
10708             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10709             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10710                 return false;
10711             }
10712             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10713                 return false;
10714             }
10715             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10716                 return false;
10717             }
10718             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10719                 return false;
10720             }
10721             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10722                 return false;
10723             }
10724             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10725                 return false;
10726             }
10727             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10728                 return false;
10729             }
10730             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10731                 return false;
10732             }
10733             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10734                 return false;
10735             }
10736             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10737                 return false;
10738             }
10739         }
10740         catch ( final Exception e ) {
10741             return false;
10742         }
10743         return true;
10744     }
10745
10746     private static boolean testSDIunrooted() {
10747         try {
10748             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10749             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10750             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10751             final Iterator<PhylogenyBranch> iter = l.iterator();
10752             PhylogenyBranch br = iter.next();
10753             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10754                 return false;
10755             }
10756             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10757                 return false;
10758             }
10759             br = iter.next();
10760             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10761                 return false;
10762             }
10763             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10764                 return false;
10765             }
10766             br = iter.next();
10767             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10768                 return false;
10769             }
10770             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10771                 return false;
10772             }
10773             br = iter.next();
10774             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10775                 return false;
10776             }
10777             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10778                 return false;
10779             }
10780             br = iter.next();
10781             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10782                 return false;
10783             }
10784             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10785                 return false;
10786             }
10787             br = iter.next();
10788             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10789                 return false;
10790             }
10791             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10792                 return false;
10793             }
10794             br = iter.next();
10795             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10796                 return false;
10797             }
10798             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10799                 return false;
10800             }
10801             br = iter.next();
10802             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10803                 return false;
10804             }
10805             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10806                 return false;
10807             }
10808             br = iter.next();
10809             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10810                 return false;
10811             }
10812             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10813                 return false;
10814             }
10815             br = iter.next();
10816             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10817                 return false;
10818             }
10819             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10820                 return false;
10821             }
10822             br = iter.next();
10823             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10824                 return false;
10825             }
10826             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10827                 return false;
10828             }
10829             br = iter.next();
10830             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10831                 return false;
10832             }
10833             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10834                 return false;
10835             }
10836             br = iter.next();
10837             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10838                 return false;
10839             }
10840             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10841                 return false;
10842             }
10843             br = iter.next();
10844             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10845                 return false;
10846             }
10847             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10848                 return false;
10849             }
10850             br = iter.next();
10851             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10852                 return false;
10853             }
10854             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10855                 return false;
10856             }
10857             if ( iter.hasNext() ) {
10858                 return false;
10859             }
10860             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10861             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10862             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10863             br = iter1.next();
10864             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10865                 return false;
10866             }
10867             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10868                 return false;
10869             }
10870             br = iter1.next();
10871             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10872                 return false;
10873             }
10874             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10875                 return false;
10876             }
10877             br = iter1.next();
10878             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10879                 return false;
10880             }
10881             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10882                 return false;
10883             }
10884             if ( iter1.hasNext() ) {
10885                 return false;
10886             }
10887             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10888             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10889             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10890             br = iter2.next();
10891             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10892                 return false;
10893             }
10894             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10895                 return false;
10896             }
10897             br = iter2.next();
10898             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10899                 return false;
10900             }
10901             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10902                 return false;
10903             }
10904             br = iter2.next();
10905             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10906                 return false;
10907             }
10908             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10909                 return false;
10910             }
10911             if ( iter2.hasNext() ) {
10912                 return false;
10913             }
10914             final Phylogeny species0 = factory
10915                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10916                              new NHXParser() )[ 0 ];
10917             final Phylogeny gene1 = factory
10918                     .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])",
10919                              new NHXParser() )[ 0 ];
10920             species0.setRooted( true );
10921             gene1.setRooted( true );
10922             final SDIR sdi_unrooted = new SDIR();
10923             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10924             if ( sdi_unrooted.getCount() != 1 ) {
10925                 return false;
10926             }
10927             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10928                 return false;
10929             }
10930             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10931                 return false;
10932             }
10933             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10934                 return false;
10935             }
10936             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10937                 return false;
10938             }
10939             final Phylogeny gene2 = factory
10940                     .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])",
10941                              new NHXParser() )[ 0 ];
10942             gene2.setRooted( true );
10943             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10944             if ( sdi_unrooted.getCount() != 1 ) {
10945                 return false;
10946             }
10947             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10948                 return false;
10949             }
10950             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10951                 return false;
10952             }
10953             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10954                 return false;
10955             }
10956             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10957                 return false;
10958             }
10959             final Phylogeny species6 = factory
10960                     .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,"
10961                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10962                              new NHXParser() )[ 0 ];
10963             final Phylogeny gene6 = factory
10964                     .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],"
10965                                      + "(((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],"
10966                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10967                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10968                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10969                              new NHXParser() )[ 0 ];
10970             species6.setRooted( true );
10971             gene6.setRooted( true );
10972             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10973             if ( sdi_unrooted.getCount() != 1 ) {
10974                 return false;
10975             }
10976             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10977                 return false;
10978             }
10979             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10980                 return false;
10981             }
10982             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10983                 return false;
10984             }
10985             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10986                 return false;
10987             }
10988             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10989                 return false;
10990             }
10991             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10992                 return false;
10993             }
10994             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10995                 return false;
10996             }
10997             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10998                 return false;
10999             }
11000             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11001                 return false;
11002             }
11003             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11004                 return false;
11005             }
11006             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11007                 return false;
11008             }
11009             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11010                 return false;
11011             }
11012             p6 = null;
11013             final Phylogeny species7 = factory
11014                     .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,"
11015                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11016                              new NHXParser() )[ 0 ];
11017             final Phylogeny gene7 = factory
11018                     .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],"
11019                                      + "(((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],"
11020                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11021                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11022                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11023                              new NHXParser() )[ 0 ];
11024             species7.setRooted( true );
11025             gene7.setRooted( true );
11026             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11027             if ( sdi_unrooted.getCount() != 1 ) {
11028                 return false;
11029             }
11030             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11031                 return false;
11032             }
11033             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11034                 return false;
11035             }
11036             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11037                 return false;
11038             }
11039             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11040                 return false;
11041             }
11042             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11043                 return false;
11044             }
11045             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11046                 return false;
11047             }
11048             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11049                 return false;
11050             }
11051             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11052                 return false;
11053             }
11054             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11055                 return false;
11056             }
11057             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11058                 return false;
11059             }
11060             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11061                 return false;
11062             }
11063             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11064                 return false;
11065             }
11066             p7 = null;
11067             final Phylogeny species8 = factory
11068                     .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,"
11069                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11070                              new NHXParser() )[ 0 ];
11071             final Phylogeny gene8 = factory
11072                     .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],"
11073                                      + "(((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],"
11074                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11075                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11076                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11077                              new NHXParser() )[ 0 ];
11078             species8.setRooted( true );
11079             gene8.setRooted( true );
11080             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11081             if ( sdi_unrooted.getCount() != 1 ) {
11082                 return false;
11083             }
11084             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11085                 return false;
11086             }
11087             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11088                 return false;
11089             }
11090             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11091                 return false;
11092             }
11093             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11094                 return false;
11095             }
11096             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11097                 return false;
11098             }
11099             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11100                 return false;
11101             }
11102             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11103                 return false;
11104             }
11105             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11106                 return false;
11107             }
11108             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11109                 return false;
11110             }
11111             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11112                 return false;
11113             }
11114             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11115                 return false;
11116             }
11117             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11118                 return false;
11119             }
11120             p8 = null;
11121         }
11122         catch ( final Exception e ) {
11123             e.printStackTrace( System.out );
11124             return false;
11125         }
11126         return true;
11127     }
11128
11129     private static boolean testSequenceDbWsTools1() {
11130         try {
11131             final PhylogenyNode n = new PhylogenyNode();
11132             n.setName( "NP_001025424" );
11133             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11134             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11135                     || !acc.getValue().equals( "NP_001025424" ) ) {
11136                 return false;
11137             }
11138             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11139             acc = SequenceDbWsTools.obtainSeqAccession( n );
11140             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11141                     || !acc.getValue().equals( "NP_001025424" ) ) {
11142                 return false;
11143             }
11144             n.setName( "NP_001025424.1" );
11145             acc = SequenceDbWsTools.obtainSeqAccession( n );
11146             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11147                     || !acc.getValue().equals( "NP_001025424" ) ) {
11148                 return false;
11149             }
11150             n.setName( "NM_001030253" );
11151             acc = SequenceDbWsTools.obtainSeqAccession( n );
11152             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11153                     || !acc.getValue().equals( "NM_001030253" ) ) {
11154                 return false;
11155             }
11156             n.setName( "BCL2_HUMAN" );
11157             acc = SequenceDbWsTools.obtainSeqAccession( n );
11158             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11159                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11160                 System.out.println( acc.toString() );
11161                 return false;
11162             }
11163             n.setName( "P10415" );
11164             acc = SequenceDbWsTools.obtainSeqAccession( n );
11165             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11166                     || !acc.getValue().equals( "P10415" ) ) {
11167                 System.out.println( acc.toString() );
11168                 return false;
11169             }
11170             n.setName( " P10415 " );
11171             acc = SequenceDbWsTools.obtainSeqAccession( n );
11172             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11173                     || !acc.getValue().equals( "P10415" ) ) {
11174                 System.out.println( acc.toString() );
11175                 return false;
11176             }
11177             n.setName( "_P10415|" );
11178             acc = SequenceDbWsTools.obtainSeqAccession( n );
11179             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11180                     || !acc.getValue().equals( "P10415" ) ) {
11181                 System.out.println( acc.toString() );
11182                 return false;
11183             }
11184             n.setName( "AY695820" );
11185             acc = SequenceDbWsTools.obtainSeqAccession( n );
11186             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11187                     || !acc.getValue().equals( "AY695820" ) ) {
11188                 System.out.println( acc.toString() );
11189                 return false;
11190             }
11191             n.setName( "_AY695820_" );
11192             acc = SequenceDbWsTools.obtainSeqAccession( n );
11193             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11194                     || !acc.getValue().equals( "AY695820" ) ) {
11195                 System.out.println( acc.toString() );
11196                 return false;
11197             }
11198             n.setName( "AAA59452" );
11199             acc = SequenceDbWsTools.obtainSeqAccession( n );
11200             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11201                     || !acc.getValue().equals( "AAA59452" ) ) {
11202                 System.out.println( acc.toString() );
11203                 return false;
11204             }
11205             n.setName( "_AAA59452_" );
11206             acc = SequenceDbWsTools.obtainSeqAccession( n );
11207             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11208                     || !acc.getValue().equals( "AAA59452" ) ) {
11209                 System.out.println( acc.toString() );
11210                 return false;
11211             }
11212             n.setName( "AAA59452.1" );
11213             acc = SequenceDbWsTools.obtainSeqAccession( n );
11214             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11215                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11216                 System.out.println( acc.toString() );
11217                 return false;
11218             }
11219             n.setName( "_AAA59452.1_" );
11220             acc = SequenceDbWsTools.obtainSeqAccession( n );
11221             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11222                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11223                 System.out.println( acc.toString() );
11224                 return false;
11225             }
11226             n.setName( "GI:94894583" );
11227             acc = SequenceDbWsTools.obtainSeqAccession( n );
11228             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11229                     || !acc.getValue().equals( "94894583" ) ) {
11230                 System.out.println( acc.toString() );
11231                 return false;
11232             }
11233             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11234             acc = SequenceDbWsTools.obtainSeqAccession( n );
11235             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11236                     || !acc.getValue().equals( "71845847" ) ) {
11237                 System.out.println( acc.toString() );
11238                 return false;
11239             }
11240             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11241             acc = SequenceDbWsTools.obtainSeqAccession( n );
11242             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11243                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11244                 System.out.println( acc.toString() );
11245                 return false;
11246             }
11247         }
11248         catch ( final Exception e ) {
11249             return false;
11250         }
11251         return true;
11252     }
11253
11254     private static boolean testSequenceDbWsTools2() {
11255         try {
11256             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11257             SequenceDbWsTools.obtainSeqInformation( n1 );
11258             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11259                 return false;
11260             }
11261             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11262                 return false;
11263             }
11264             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11265                 return false;
11266             }
11267             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11268                 return false;
11269             }
11270             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11271             SequenceDbWsTools.obtainSeqInformation( n2 );
11272             if ( !n2.getNodeData().getSequence().getName()
11273                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11274                 return false;
11275             }
11276             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11277                 return false;
11278             }
11279             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11280                 return false;
11281             }
11282             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11283                 return false;
11284             }
11285             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11286             SequenceDbWsTools.obtainSeqInformation( n3 );
11287             if ( !n3.getNodeData().getSequence().getName()
11288                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11289                 return false;
11290             }
11291             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11292                 return false;
11293             }
11294             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11295                 return false;
11296             }
11297             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11298                 return false;
11299             }
11300         }
11301         catch ( final IOException e ) {
11302             System.out.println();
11303             System.out.println( "the following might be due to absence internet connection:" );
11304             e.printStackTrace( System.out );
11305             return true;
11306         }
11307         catch ( final Exception e ) {
11308             e.printStackTrace();
11309             return false;
11310         }
11311         return true;
11312     }
11313
11314     private static boolean testSequenceIdParsing() {
11315         try {
11316             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11317             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11318                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11319                 if ( id != null ) {
11320                     System.out.println( "value   =" + id.getValue() );
11321                     System.out.println( "provider=" + id.getSource() );
11322                 }
11323                 return false;
11324             }
11325             //
11326             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11327             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11328                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11329                 if ( id != null ) {
11330                     System.out.println( "value   =" + id.getValue() );
11331                     System.out.println( "provider=" + id.getSource() );
11332                 }
11333                 return false;
11334             }
11335             //
11336             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11337             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11338                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11339                 if ( id != null ) {
11340                     System.out.println( "value   =" + id.getValue() );
11341                     System.out.println( "provider=" + id.getSource() );
11342                 }
11343                 return false;
11344             }
11345             // 
11346             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11347             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11348                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11349                 if ( id != null ) {
11350                     System.out.println( "value   =" + id.getValue() );
11351                     System.out.println( "provider=" + id.getSource() );
11352                 }
11353                 return false;
11354             }
11355             // 
11356             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11357             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11358                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11359                 if ( id != null ) {
11360                     System.out.println( "value   =" + id.getValue() );
11361                     System.out.println( "provider=" + id.getSource() );
11362                 }
11363                 return false;
11364             }
11365             // 
11366             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11367             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11368                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11369                 if ( id != null ) {
11370                     System.out.println( "value   =" + id.getValue() );
11371                     System.out.println( "provider=" + id.getSource() );
11372                 }
11373                 return false;
11374             }
11375             // 
11376             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11377             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11378                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11379                 if ( id != null ) {
11380                     System.out.println( "value   =" + id.getValue() );
11381                     System.out.println( "provider=" + id.getSource() );
11382                 }
11383                 return false;
11384             }
11385             // 
11386             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11387             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11388                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11389                 if ( id != null ) {
11390                     System.out.println( "value   =" + id.getValue() );
11391                     System.out.println( "provider=" + id.getSource() );
11392                 }
11393                 return false;
11394             }
11395             // 
11396             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11397             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11398                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11399                 if ( id != null ) {
11400                     System.out.println( "value   =" + id.getValue() );
11401                     System.out.println( "provider=" + id.getSource() );
11402                 }
11403                 return false;
11404             }
11405             // 
11406             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11407             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11408                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11409                 if ( id != null ) {
11410                     System.out.println( "value   =" + id.getValue() );
11411                     System.out.println( "provider=" + id.getSource() );
11412                 }
11413                 return false;
11414             }
11415             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11416             if ( id != null ) {
11417                 System.out.println( "value   =" + id.getValue() );
11418                 System.out.println( "provider=" + id.getSource() );
11419                 return false;
11420             }
11421         }
11422         catch ( final Exception e ) {
11423             e.printStackTrace( System.out );
11424             return false;
11425         }
11426         return true;
11427     }
11428
11429     private static boolean testSequenceWriter() {
11430         try {
11431             final String n = ForesterUtil.LINE_SEPARATOR;
11432             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11433                 return false;
11434             }
11435             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11436                 return false;
11437             }
11438             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11439                 return false;
11440             }
11441             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11442                 return false;
11443             }
11444             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11445                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11446                 return false;
11447             }
11448             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11449                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11450                 return false;
11451             }
11452         }
11453         catch ( final Exception e ) {
11454             e.printStackTrace();
11455             return false;
11456         }
11457         return true;
11458     }
11459
11460     private static boolean testSpecies() {
11461         try {
11462             final Species s1 = new BasicSpecies( "a" );
11463             final Species s2 = new BasicSpecies( "a" );
11464             final Species s3 = new BasicSpecies( "A" );
11465             final Species s4 = new BasicSpecies( "b" );
11466             if ( !s1.equals( s1 ) ) {
11467                 return false;
11468             }
11469             if ( s1.getSpeciesId().equals( "x" ) ) {
11470                 return false;
11471             }
11472             if ( s1.getSpeciesId().equals( null ) ) {
11473                 return false;
11474             }
11475             if ( !s1.equals( s2 ) ) {
11476                 return false;
11477             }
11478             if ( s1.equals( s3 ) ) {
11479                 return false;
11480             }
11481             if ( s1.hashCode() != s1.hashCode() ) {
11482                 return false;
11483             }
11484             if ( s1.hashCode() != s2.hashCode() ) {
11485                 return false;
11486             }
11487             if ( s1.hashCode() == s3.hashCode() ) {
11488                 return false;
11489             }
11490             if ( s1.compareTo( s1 ) != 0 ) {
11491                 return false;
11492             }
11493             if ( s1.compareTo( s2 ) != 0 ) {
11494                 return false;
11495             }
11496             if ( s1.compareTo( s3 ) != 0 ) {
11497                 return false;
11498             }
11499             if ( s1.compareTo( s4 ) >= 0 ) {
11500                 return false;
11501             }
11502             if ( s4.compareTo( s1 ) <= 0 ) {
11503                 return false;
11504             }
11505             if ( !s4.getSpeciesId().equals( "b" ) ) {
11506                 return false;
11507             }
11508             final Species s5 = new BasicSpecies( " C " );
11509             if ( !s5.getSpeciesId().equals( "C" ) ) {
11510                 return false;
11511             }
11512             if ( s5.equals( s1 ) ) {
11513                 return false;
11514             }
11515         }
11516         catch ( final Exception e ) {
11517             e.printStackTrace( System.out );
11518             return false;
11519         }
11520         return true;
11521     }
11522
11523     private static boolean testSplit() {
11524         try {
11525             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11526             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11527             //Archaeopteryx.createApplication( p0 );
11528             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11529             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11530             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11531             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11532             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11533             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11534             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11535             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11536             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11537             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11538             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11539             // System.out.println( s0.toString() );
11540             //
11541             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11542             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11543             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11544             if ( s0.match( query_nodes ) ) {
11545                 return false;
11546             }
11547             query_nodes = new HashSet<PhylogenyNode>();
11548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11551             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11552             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11555             if ( !s0.match( query_nodes ) ) {
11556                 return false;
11557             }
11558             //
11559             query_nodes = new HashSet<PhylogenyNode>();
11560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11561             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11563             if ( !s0.match( query_nodes ) ) {
11564                 return false;
11565             }
11566             //
11567             query_nodes = new HashSet<PhylogenyNode>();
11568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11572             if ( !s0.match( query_nodes ) ) {
11573                 return false;
11574             }
11575             //
11576             query_nodes = new HashSet<PhylogenyNode>();
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11581             if ( !s0.match( query_nodes ) ) {
11582                 return false;
11583             }
11584             //
11585             query_nodes = new HashSet<PhylogenyNode>();
11586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11589             if ( !s0.match( query_nodes ) ) {
11590                 return false;
11591             }
11592             //
11593             query_nodes = new HashSet<PhylogenyNode>();
11594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11596             if ( !s0.match( query_nodes ) ) {
11597                 return false;
11598             }
11599             //
11600             query_nodes = new HashSet<PhylogenyNode>();
11601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11606             if ( !s0.match( query_nodes ) ) {
11607                 return false;
11608             }
11609             //
11610             query_nodes = new HashSet<PhylogenyNode>();
11611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11614             if ( !s0.match( query_nodes ) ) {
11615                 return false;
11616             }
11617             //
11618             query_nodes = new HashSet<PhylogenyNode>();
11619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11623             if ( !s0.match( query_nodes ) ) {
11624                 return false;
11625             }
11626             //
11627             query_nodes = new HashSet<PhylogenyNode>();
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11630             if ( s0.match( query_nodes ) ) {
11631                 return false;
11632             }
11633             //
11634             query_nodes = new HashSet<PhylogenyNode>();
11635             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11639             if ( s0.match( query_nodes ) ) {
11640                 return false;
11641             }
11642             //
11643             query_nodes = new HashSet<PhylogenyNode>();
11644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11649             if ( s0.match( query_nodes ) ) {
11650                 return false;
11651             }
11652             //
11653             query_nodes = new HashSet<PhylogenyNode>();
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11657             if ( s0.match( query_nodes ) ) {
11658                 return false;
11659             }
11660             //
11661             query_nodes = new HashSet<PhylogenyNode>();
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11664             if ( s0.match( query_nodes ) ) {
11665                 return false;
11666             }
11667             //
11668             query_nodes = new HashSet<PhylogenyNode>();
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11671             if ( s0.match( query_nodes ) ) {
11672                 return false;
11673             }
11674             //
11675             query_nodes = new HashSet<PhylogenyNode>();
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11678             if ( s0.match( query_nodes ) ) {
11679                 return false;
11680             }
11681             //
11682             query_nodes = new HashSet<PhylogenyNode>();
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11685             if ( s0.match( query_nodes ) ) {
11686                 return false;
11687             }
11688             //
11689             query_nodes = new HashSet<PhylogenyNode>();
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11692             if ( s0.match( query_nodes ) ) {
11693                 return false;
11694             }
11695             //
11696             query_nodes = new HashSet<PhylogenyNode>();
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11699             if ( s0.match( query_nodes ) ) {
11700                 return false;
11701             }
11702             //
11703             query_nodes = new HashSet<PhylogenyNode>();
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11707             if ( s0.match( query_nodes ) ) {
11708                 return false;
11709             }
11710             //
11711             query_nodes = new HashSet<PhylogenyNode>();
11712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11715             if ( s0.match( query_nodes ) ) {
11716                 return false;
11717             }
11718             //
11719             query_nodes = new HashSet<PhylogenyNode>();
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11723             if ( s0.match( query_nodes ) ) {
11724                 return false;
11725             }
11726             //
11727             query_nodes = new HashSet<PhylogenyNode>();
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11732             if ( s0.match( query_nodes ) ) {
11733                 return false;
11734             }
11735             /////////
11736             //            query_nodes = new HashSet<PhylogenyNode>();
11737             //            query_nodes.add( new PhylogenyNode( "X" ) );
11738             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11739             //            query_nodes.add( new PhylogenyNode( "A" ) );
11740             //            query_nodes.add( new PhylogenyNode( "B" ) );
11741             //            query_nodes.add( new PhylogenyNode( "C" ) );
11742             //            query_nodes.add( new PhylogenyNode( "D" ) );
11743             //            query_nodes.add( new PhylogenyNode( "E" ) );
11744             //            query_nodes.add( new PhylogenyNode( "F" ) );
11745             //            query_nodes.add( new PhylogenyNode( "G" ) );
11746             //            if ( !s0.match( query_nodes ) ) {
11747             //                return false;
11748             //            }
11749             //            query_nodes = new HashSet<PhylogenyNode>();
11750             //            query_nodes.add( new PhylogenyNode( "X" ) );
11751             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11752             //            query_nodes.add( new PhylogenyNode( "A" ) );
11753             //            query_nodes.add( new PhylogenyNode( "B" ) );
11754             //            query_nodes.add( new PhylogenyNode( "C" ) );
11755             //            if ( !s0.match( query_nodes ) ) {
11756             //                return false;
11757             //            }
11758             //            //
11759             //            query_nodes = new HashSet<PhylogenyNode>();
11760             //            query_nodes.add( new PhylogenyNode( "X" ) );
11761             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11762             //            query_nodes.add( new PhylogenyNode( "D" ) );
11763             //            query_nodes.add( new PhylogenyNode( "E" ) );
11764             //            query_nodes.add( new PhylogenyNode( "F" ) );
11765             //            query_nodes.add( new PhylogenyNode( "G" ) );
11766             //            if ( !s0.match( query_nodes ) ) {
11767             //                return false;
11768             //            }
11769             //            //
11770             //            query_nodes = new HashSet<PhylogenyNode>();
11771             //            query_nodes.add( new PhylogenyNode( "X" ) );
11772             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11773             //            query_nodes.add( new PhylogenyNode( "A" ) );
11774             //            query_nodes.add( new PhylogenyNode( "B" ) );
11775             //            query_nodes.add( new PhylogenyNode( "C" ) );
11776             //            query_nodes.add( new PhylogenyNode( "D" ) );
11777             //            if ( !s0.match( query_nodes ) ) {
11778             //                return false;
11779             //            }
11780             //            //
11781             //            query_nodes = new HashSet<PhylogenyNode>();
11782             //            query_nodes.add( new PhylogenyNode( "X" ) );
11783             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11784             //            query_nodes.add( new PhylogenyNode( "E" ) );
11785             //            query_nodes.add( new PhylogenyNode( "F" ) );
11786             //            query_nodes.add( new PhylogenyNode( "G" ) );
11787             //            if ( !s0.match( query_nodes ) ) {
11788             //                return false;
11789             //            }
11790             //            //
11791             //            query_nodes = new HashSet<PhylogenyNode>();
11792             //            query_nodes.add( new PhylogenyNode( "X" ) );
11793             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11794             //            query_nodes.add( new PhylogenyNode( "F" ) );
11795             //            query_nodes.add( new PhylogenyNode( "G" ) );
11796             //            if ( !s0.match( query_nodes ) ) {
11797             //                return false;
11798             //            }
11799             //
11800             query_nodes = new HashSet<PhylogenyNode>();
11801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11805             if ( s0.match( query_nodes ) ) {
11806                 return false;
11807             }
11808             //
11809             query_nodes = new HashSet<PhylogenyNode>();
11810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11814             if ( s0.match( query_nodes ) ) {
11815                 return false;
11816             }
11817             ///////////////////////////
11818             //
11819             query_nodes = new HashSet<PhylogenyNode>();
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11824             if ( s0.match( query_nodes ) ) {
11825                 return false;
11826             }
11827             //
11828             query_nodes = new HashSet<PhylogenyNode>();
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11833             if ( s0.match( query_nodes ) ) {
11834                 return false;
11835             }
11836             //
11837             query_nodes = new HashSet<PhylogenyNode>();
11838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11842             if ( s0.match( query_nodes ) ) {
11843                 return false;
11844             }
11845             //
11846             query_nodes = new HashSet<PhylogenyNode>();
11847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11851             if ( s0.match( query_nodes ) ) {
11852                 return false;
11853             }
11854             //
11855             query_nodes = new HashSet<PhylogenyNode>();
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11860             if ( s0.match( query_nodes ) ) {
11861                 return false;
11862             }
11863             //
11864             query_nodes = new HashSet<PhylogenyNode>();
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11868             if ( s0.match( query_nodes ) ) {
11869                 return false;
11870             }
11871             //
11872             query_nodes = new HashSet<PhylogenyNode>();
11873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11878             if ( s0.match( query_nodes ) ) {
11879                 return false;
11880             }
11881             //
11882             query_nodes = new HashSet<PhylogenyNode>();
11883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11888             if ( s0.match( query_nodes ) ) {
11889                 return false;
11890             }
11891             //
11892             query_nodes = new HashSet<PhylogenyNode>();
11893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11898             if ( s0.match( query_nodes ) ) {
11899                 return false;
11900             }
11901             //
11902             query_nodes = new HashSet<PhylogenyNode>();
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11909             if ( s0.match( query_nodes ) ) {
11910                 return false;
11911             }
11912         }
11913         catch ( final Exception e ) {
11914             e.printStackTrace();
11915             return false;
11916         }
11917         return true;
11918     }
11919
11920     private static boolean testSplitStrict() {
11921         try {
11922             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11923             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11924             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11925             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11926             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11927             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11928             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11929             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11930             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11931             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11932             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11933             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11936             if ( s0.match( query_nodes ) ) {
11937                 return false;
11938             }
11939             query_nodes = new HashSet<PhylogenyNode>();
11940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11947             if ( !s0.match( query_nodes ) ) {
11948                 return false;
11949             }
11950             //
11951             query_nodes = new HashSet<PhylogenyNode>();
11952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11955             if ( !s0.match( query_nodes ) ) {
11956                 return false;
11957             }
11958             //
11959             query_nodes = new HashSet<PhylogenyNode>();
11960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11964             if ( !s0.match( query_nodes ) ) {
11965                 return false;
11966             }
11967             //
11968             query_nodes = new HashSet<PhylogenyNode>();
11969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11973             if ( !s0.match( query_nodes ) ) {
11974                 return false;
11975             }
11976             //
11977             query_nodes = new HashSet<PhylogenyNode>();
11978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11981             if ( !s0.match( query_nodes ) ) {
11982                 return false;
11983             }
11984             //
11985             query_nodes = new HashSet<PhylogenyNode>();
11986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11988             if ( !s0.match( query_nodes ) ) {
11989                 return false;
11990             }
11991             //
11992             query_nodes = new HashSet<PhylogenyNode>();
11993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11998             if ( !s0.match( query_nodes ) ) {
11999                 return false;
12000             }
12001             //
12002             query_nodes = new HashSet<PhylogenyNode>();
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12006             if ( !s0.match( query_nodes ) ) {
12007                 return false;
12008             }
12009             //
12010             query_nodes = new HashSet<PhylogenyNode>();
12011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12015             if ( !s0.match( query_nodes ) ) {
12016                 return false;
12017             }
12018             //
12019             query_nodes = new HashSet<PhylogenyNode>();
12020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12022             if ( s0.match( query_nodes ) ) {
12023                 return false;
12024             }
12025             //
12026             query_nodes = new HashSet<PhylogenyNode>();
12027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12031             if ( s0.match( query_nodes ) ) {
12032                 return false;
12033             }
12034             //
12035             query_nodes = new HashSet<PhylogenyNode>();
12036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12041             if ( s0.match( query_nodes ) ) {
12042                 return false;
12043             }
12044             //
12045             query_nodes = new HashSet<PhylogenyNode>();
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12049             if ( s0.match( query_nodes ) ) {
12050                 return false;
12051             }
12052             //
12053             query_nodes = new HashSet<PhylogenyNode>();
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12056             if ( s0.match( query_nodes ) ) {
12057                 return false;
12058             }
12059             //
12060             query_nodes = new HashSet<PhylogenyNode>();
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12063             if ( s0.match( query_nodes ) ) {
12064                 return false;
12065             }
12066             //
12067             query_nodes = new HashSet<PhylogenyNode>();
12068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12070             if ( s0.match( query_nodes ) ) {
12071                 return false;
12072             }
12073             //
12074             query_nodes = new HashSet<PhylogenyNode>();
12075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12077             if ( s0.match( query_nodes ) ) {
12078                 return false;
12079             }
12080             //
12081             query_nodes = new HashSet<PhylogenyNode>();
12082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12084             if ( s0.match( query_nodes ) ) {
12085                 return false;
12086             }
12087             //
12088             query_nodes = new HashSet<PhylogenyNode>();
12089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12091             if ( s0.match( query_nodes ) ) {
12092                 return false;
12093             }
12094             //
12095             query_nodes = new HashSet<PhylogenyNode>();
12096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12099             if ( s0.match( query_nodes ) ) {
12100                 return false;
12101             }
12102             //
12103             query_nodes = new HashSet<PhylogenyNode>();
12104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12107             if ( s0.match( query_nodes ) ) {
12108                 return false;
12109             }
12110             //
12111             query_nodes = new HashSet<PhylogenyNode>();
12112             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12115             if ( s0.match( query_nodes ) ) {
12116                 return false;
12117             }
12118             //
12119             query_nodes = new HashSet<PhylogenyNode>();
12120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12124             if ( s0.match( query_nodes ) ) {
12125                 return false;
12126             }
12127         }
12128         catch ( final Exception e ) {
12129             e.printStackTrace();
12130             return false;
12131         }
12132         return true;
12133     }
12134
12135     private static boolean testSubtreeDeletion() {
12136         try {
12137             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12138             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12139             t1.deleteSubtree( t1.getNode( "A" ), false );
12140             if ( t1.getNumberOfExternalNodes() != 5 ) {
12141                 return false;
12142             }
12143             t1.toNewHampshireX();
12144             t1.deleteSubtree( t1.getNode( "E" ), false );
12145             if ( t1.getNumberOfExternalNodes() != 4 ) {
12146                 return false;
12147             }
12148             t1.toNewHampshireX();
12149             t1.deleteSubtree( t1.getNode( "F" ), false );
12150             if ( t1.getNumberOfExternalNodes() != 3 ) {
12151                 return false;
12152             }
12153             t1.toNewHampshireX();
12154             t1.deleteSubtree( t1.getNode( "D" ), false );
12155             t1.toNewHampshireX();
12156             if ( t1.getNumberOfExternalNodes() != 3 ) {
12157                 return false;
12158             }
12159             t1.deleteSubtree( t1.getNode( "def" ), false );
12160             t1.toNewHampshireX();
12161             if ( t1.getNumberOfExternalNodes() != 2 ) {
12162                 return false;
12163             }
12164             t1.deleteSubtree( t1.getNode( "B" ), false );
12165             t1.toNewHampshireX();
12166             if ( t1.getNumberOfExternalNodes() != 1 ) {
12167                 return false;
12168             }
12169             t1.deleteSubtree( t1.getNode( "C" ), false );
12170             t1.toNewHampshireX();
12171             if ( t1.getNumberOfExternalNodes() != 1 ) {
12172                 return false;
12173             }
12174             t1.deleteSubtree( t1.getNode( "abc" ), false );
12175             t1.toNewHampshireX();
12176             if ( t1.getNumberOfExternalNodes() != 1 ) {
12177                 return false;
12178             }
12179             t1.deleteSubtree( t1.getNode( "r" ), false );
12180             if ( t1.getNumberOfExternalNodes() != 0 ) {
12181                 return false;
12182             }
12183             if ( !t1.isEmpty() ) {
12184                 return false;
12185             }
12186             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12187             t2.deleteSubtree( t2.getNode( "A" ), false );
12188             t2.toNewHampshireX();
12189             if ( t2.getNumberOfExternalNodes() != 5 ) {
12190                 return false;
12191             }
12192             t2.deleteSubtree( t2.getNode( "abc" ), false );
12193             t2.toNewHampshireX();
12194             if ( t2.getNumberOfExternalNodes() != 3 ) {
12195                 return false;
12196             }
12197             t2.deleteSubtree( t2.getNode( "def" ), false );
12198             t2.toNewHampshireX();
12199             if ( t2.getNumberOfExternalNodes() != 1 ) {
12200                 return false;
12201             }
12202         }
12203         catch ( final Exception e ) {
12204             e.printStackTrace( System.out );
12205             return false;
12206         }
12207         return true;
12208     }
12209
12210     private static boolean testSupportCount() {
12211         try {
12212             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12213             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12214             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12215                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12216                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12217                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12218                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12219                                                               new NHXParser() );
12220             SupportCount.count( t0_1, phylogenies_1, true, false );
12221             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12222             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12223                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12224                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12225                                                                       + "(((((A,B),C),D),E),(F,G))"
12226                                                                       + "(((((A,B),C),D),E),(F,G))"
12227                                                                       + "(((((A,B),C),D),E),(F,G))"
12228                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12229                                                                       + "(((((A,B),C),D),E),(F,G))"
12230                                                                       + "((((((A,B),C),D),E),F),G)"
12231                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12232                                                               new NHXParser() );
12233             SupportCount.count( t0_2, phylogenies_2, true, false );
12234             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12235             while ( it.hasNext() ) {
12236                 final PhylogenyNode n = it.next();
12237                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12238                     return false;
12239                 }
12240             }
12241             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12242             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12243                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12244             SupportCount.count( t0_3, phylogenies_3, true, false );
12245             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12246             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12247                 return false;
12248             }
12249             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12250                 return false;
12251             }
12252             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12253                 return false;
12254             }
12255             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12256                 return false;
12257             }
12258             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12259                 return false;
12260             }
12261             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12262                 return false;
12263             }
12264             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12265                 return false;
12266             }
12267             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12268                 return false;
12269             }
12270             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12271                 return false;
12272             }
12273             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12274                 return false;
12275             }
12276             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12277             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12278                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12279             SupportCount.count( t0_4, phylogenies_4, true, false );
12280             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12281             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12282                 return false;
12283             }
12284             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12285                 return false;
12286             }
12287             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12288                 return false;
12289             }
12290             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12291                 return false;
12292             }
12293             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12294                 return false;
12295             }
12296             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12297                 return false;
12298             }
12299             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12300                 return false;
12301             }
12302             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12303                 return false;
12304             }
12305             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12306                 return false;
12307             }
12308             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12309                 return false;
12310             }
12311             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12312             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12313             double d = SupportCount.compare( b1, a, true, true, true );
12314             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12315                 return false;
12316             }
12317             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12318             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12319             d = SupportCount.compare( b2, a, true, true, true );
12320             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12321                 return false;
12322             }
12323             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12324             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12325             d = SupportCount.compare( b3, a, true, true, true );
12326             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12327                 return false;
12328             }
12329             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12330             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12331             d = SupportCount.compare( b4, a, true, true, false );
12332             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12333                 return false;
12334             }
12335         }
12336         catch ( final Exception e ) {
12337             e.printStackTrace( System.out );
12338             return false;
12339         }
12340         return true;
12341     }
12342
12343     private static boolean testSupportTransfer() {
12344         try {
12345             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12346             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)",
12347                                                  new NHXParser() )[ 0 ];
12348             final Phylogeny p2 = factory
12349                     .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 ];
12350             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12351                 return false;
12352             }
12353             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12354                 return false;
12355             }
12356             support_transfer.moveBranchLengthsToBootstrap( p1 );
12357             support_transfer.transferSupportValues( p1, p2 );
12358             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12359                 return false;
12360             }
12361             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12362                 return false;
12363             }
12364             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12365                 return false;
12366             }
12367             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12368                 return false;
12369             }
12370             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12371                 return false;
12372             }
12373             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12374                 return false;
12375             }
12376             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12377                 return false;
12378             }
12379             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12380                 return false;
12381             }
12382         }
12383         catch ( final Exception e ) {
12384             e.printStackTrace( System.out );
12385             return false;
12386         }
12387         return true;
12388     }
12389
12390     private static boolean testTaxonomyExtraction() {
12391         try {
12392             final PhylogenyNode n0 = PhylogenyNode
12393                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12394             if ( n0.getNodeData().isHasTaxonomy() ) {
12395                 return false;
12396             }
12397             final PhylogenyNode n1 = PhylogenyNode
12398                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12399             if ( n1.getNodeData().isHasTaxonomy() ) {
12400                 System.out.println( n1.toString() );
12401                 return false;
12402             }
12403             final PhylogenyNode n2x = PhylogenyNode
12404                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12405             if ( n2x.getNodeData().isHasTaxonomy() ) {
12406                 return false;
12407             }
12408             final PhylogenyNode n3 = PhylogenyNode
12409                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12410             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12411                 System.out.println( n3.toString() );
12412                 return false;
12413             }
12414             final PhylogenyNode n4 = PhylogenyNode
12415                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12416             if ( n4.getNodeData().isHasTaxonomy() ) {
12417                 System.out.println( n4.toString() );
12418                 return false;
12419             }
12420             final PhylogenyNode n5 = PhylogenyNode
12421                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12422             if ( n5.getNodeData().isHasTaxonomy() ) {
12423                 System.out.println( n5.toString() );
12424                 return false;
12425             }
12426             final PhylogenyNode n6 = PhylogenyNode
12427                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12428             if ( n6.getNodeData().isHasTaxonomy() ) {
12429                 System.out.println( n6.toString() );
12430                 return false;
12431             }
12432             final PhylogenyNode n7 = PhylogenyNode
12433                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12434             if ( n7.getNodeData().isHasTaxonomy() ) {
12435                 System.out.println( n7.toString() );
12436                 return false;
12437             }
12438             final PhylogenyNode n8 = PhylogenyNode
12439                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12440             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12441                 System.out.println( n8.toString() );
12442                 return false;
12443             }
12444             final PhylogenyNode n9 = PhylogenyNode
12445                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12446             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12447                 System.out.println( n9.toString() );
12448                 return false;
12449             }
12450             final PhylogenyNode n10x = PhylogenyNode
12451                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12452             if ( n10x.getNodeData().isHasTaxonomy() ) {
12453                 System.out.println( n10x.toString() );
12454                 return false;
12455             }
12456             final PhylogenyNode n10xx = PhylogenyNode
12457                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12458             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12459                 System.out.println( n10xx.toString() );
12460                 return false;
12461             }
12462             final PhylogenyNode n10 = PhylogenyNode
12463                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12464             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12465                 System.out.println( n10.toString() );
12466                 return false;
12467             }
12468             final PhylogenyNode n11 = PhylogenyNode
12469                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12470             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12471                 System.out.println( n11.toString() );
12472                 return false;
12473             }
12474             final PhylogenyNode n12 = PhylogenyNode
12475                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12476                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12477             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12478                 System.out.println( n12.toString() );
12479                 return false;
12480             }
12481             final PhylogenyNode n13 = PhylogenyNode
12482                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12483             if ( n13.getNodeData().isHasTaxonomy() ) {
12484                 System.out.println( n13.toString() );
12485                 return false;
12486             }
12487             final PhylogenyNode n14 = PhylogenyNode
12488                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12489             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12490                 System.out.println( n14.toString() );
12491                 return false;
12492             }
12493             final PhylogenyNode n15 = PhylogenyNode
12494                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12495             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12496                 System.out.println( n15.toString() );
12497                 return false;
12498             }
12499             final PhylogenyNode n16 = PhylogenyNode
12500                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12501             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12502                 System.out.println( n16.toString() );
12503                 return false;
12504             }
12505             final PhylogenyNode n17 = PhylogenyNode
12506                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12507             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12508                 System.out.println( n17.toString() );
12509                 return false;
12510             }
12511             //
12512             final PhylogenyNode n18 = PhylogenyNode
12513                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12514             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12515                 System.out.println( n18.toString() );
12516                 return false;
12517             }
12518             final PhylogenyNode n19 = PhylogenyNode
12519                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12520                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12521             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12522                 System.out.println( n19.toString() );
12523                 return false;
12524             }
12525             final PhylogenyNode n20 = PhylogenyNode
12526                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12527             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12528                 System.out.println( n20.toString() );
12529                 return false;
12530             }
12531             final PhylogenyNode n21 = PhylogenyNode
12532                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12533                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12534             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12535                 System.out.println( n21.toString() );
12536                 return false;
12537             }
12538             final PhylogenyNode n22 = PhylogenyNode
12539                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12540                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12541             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12542                 System.out.println( n22.toString() );
12543                 return false;
12544             }
12545             final PhylogenyNode n23 = PhylogenyNode
12546                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12547                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12548             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12549                 System.out.println( n23.toString() );
12550                 return false;
12551             }
12552             final PhylogenyNode n24 = PhylogenyNode
12553                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12554             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12555                 System.out.println( n24.toString() );
12556                 return false;
12557             }
12558             //
12559             final PhylogenyNode n25 = PhylogenyNode
12560                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12561                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12562             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12563                 System.out.println( n25.toString() );
12564                 return false;
12565             }
12566             final PhylogenyNode n26 = PhylogenyNode
12567                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12568                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12569             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12570                 System.out.println( n26.toString() );
12571                 return false;
12572             }
12573             final PhylogenyNode n27 = PhylogenyNode
12574                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12576                 System.out.println( n27.toString() );
12577                 return false;
12578             }
12579         }
12580         catch ( final Exception e ) {
12581             e.printStackTrace( System.out );
12582             return false;
12583         }
12584         return true;
12585     }
12586
12587     private static boolean testTreeCopy() {
12588         try {
12589             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12590             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12591             final Phylogeny t1 = t0.copy();
12592             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12593                 return false;
12594             }
12595             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12596                 return false;
12597             }
12598             t0.deleteSubtree( t0.getNode( "c" ), true );
12599             t0.deleteSubtree( t0.getNode( "a" ), true );
12600             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12601             t0.getNode( "b" ).setName( "Bee" );
12602             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12603                 return false;
12604             }
12605             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12606                 return false;
12607             }
12608             t0.deleteSubtree( t0.getNode( "e" ), true );
12609             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12610             t0.deleteSubtree( t0.getNode( "d" ), true );
12611             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12612                 return false;
12613             }
12614         }
12615         catch ( final Exception e ) {
12616             e.printStackTrace();
12617             return false;
12618         }
12619         return true;
12620     }
12621
12622     private static boolean testTreeMethods() {
12623         try {
12624             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12625             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12626             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12627             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12628                 System.out.println( t0.toNewHampshireX() );
12629                 return false;
12630             }
12631             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12632             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12633             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12634                 return false;
12635             }
12636             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12637                 return false;
12638             }
12639             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12640                 return false;
12641             }
12642         }
12643         catch ( final Exception e ) {
12644             e.printStackTrace( System.out );
12645             return false;
12646         }
12647         return true;
12648     }
12649
12650     private static boolean testUniprotEntryRetrieval() {
12651         try {
12652             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12653             if ( !entry.getAccession().equals( "P12345" ) ) {
12654                 return false;
12655             }
12656             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12657                 return false;
12658             }
12659             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12660                 return false;
12661             }
12662             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12663                 return false;
12664             }
12665             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12666                 return false;
12667             }
12668             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12669                 return false;
12670             }
12671         }
12672         catch ( final IOException e ) {
12673             System.out.println();
12674             System.out.println( "the following might be due to absence internet connection:" );
12675             e.printStackTrace( System.out );
12676             return true;
12677         }
12678         catch ( final Exception e ) {
12679             return false;
12680         }
12681         return true;
12682     }
12683
12684     private static boolean testUniprotTaxonomySearch() {
12685         try {
12686             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12687                                                                                                  10 );
12688             if ( results.size() != 1 ) {
12689                 return false;
12690             }
12691             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12692                 return false;
12693             }
12694             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12695                 return false;
12696             }
12697             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12698                 return false;
12699             }
12700             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12701                 return false;
12702             }
12703             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12704                 return false;
12705             }
12706             results = null;
12707             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12708             if ( results.size() != 1 ) {
12709                 return false;
12710             }
12711             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12712                 return false;
12713             }
12714             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12715                 return false;
12716             }
12717             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12718                 return false;
12719             }
12720             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12721                 return false;
12722             }
12723             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12724                 return false;
12725             }
12726             results = null;
12727             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12728             if ( results.size() != 1 ) {
12729                 return false;
12730             }
12731             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12732                 return false;
12733             }
12734             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12735                 return false;
12736             }
12737             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12738                 return false;
12739             }
12740             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12741                 return false;
12742             }
12743             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12744                 return false;
12745             }
12746             results = null;
12747             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12748             if ( results.size() != 1 ) {
12749                 return false;
12750             }
12751             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12752                 return false;
12753             }
12754             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12755                 return false;
12756             }
12757             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12758                 return false;
12759             }
12760             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12761                 return false;
12762             }
12763             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12764                 return false;
12765             }
12766             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12767                 return false;
12768             }
12769             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12770                 return false;
12771             }
12772             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12773                     .equals( "Nematostella vectensis" ) ) {
12774                 System.out.println( results.get( 0 ).getLineage() );
12775                 return false;
12776             }
12777             //
12778             results = null;
12779             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12780             if ( results.size() != 1 ) {
12781                 return false;
12782             }
12783             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12784                 return false;
12785             }
12786             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12787                 return false;
12788             }
12789             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12790                 return false;
12791             }
12792             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12793                 return false;
12794             }
12795             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12796                 return false;
12797             }
12798             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12799                     .equals( "Xenopus tropicalis" ) ) {
12800                 System.out.println( results.get( 0 ).getLineage() );
12801                 return false;
12802             }
12803             //
12804             results = null;
12805             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12806             if ( results.size() != 1 ) {
12807                 return false;
12808             }
12809             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12810                 return false;
12811             }
12812             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12813                 return false;
12814             }
12815             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12816                 return false;
12817             }
12818             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12819                 return false;
12820             }
12821             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12822                 return false;
12823             }
12824             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12825                     .equals( "Xenopus tropicalis" ) ) {
12826                 System.out.println( results.get( 0 ).getLineage() );
12827                 return false;
12828             }
12829             //
12830             results = null;
12831             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12832             if ( results.size() != 1 ) {
12833                 return false;
12834             }
12835             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12836                 return false;
12837             }
12838             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12839                 return false;
12840             }
12841             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12842                 return false;
12843             }
12844             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12845                 return false;
12846             }
12847             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12848                 return false;
12849             }
12850             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12851                     .equals( "Xenopus tropicalis" ) ) {
12852                 System.out.println( results.get( 0 ).getLineage() );
12853                 return false;
12854             }
12855         }
12856         catch ( final IOException e ) {
12857             System.out.println();
12858             System.out.println( "the following might be due to absence internet connection:" );
12859             e.printStackTrace( System.out );
12860             return true;
12861         }
12862         catch ( final Exception e ) {
12863             return false;
12864         }
12865         return true;
12866     }
12867
12868     private static boolean testWabiTxSearch() {
12869         try {
12870             String result = "";
12871             result = TxSearch.searchSimple( "nematostella" );
12872             result = TxSearch.getTxId( "nematostella" );
12873             if ( !result.equals( "45350" ) ) {
12874                 return false;
12875             }
12876             result = TxSearch.getTxName( "45350" );
12877             if ( !result.equals( "Nematostella" ) ) {
12878                 return false;
12879             }
12880             result = TxSearch.getTxId( "nematostella vectensis" );
12881             if ( !result.equals( "45351" ) ) {
12882                 return false;
12883             }
12884             result = TxSearch.getTxName( "45351" );
12885             if ( !result.equals( "Nematostella vectensis" ) ) {
12886                 return false;
12887             }
12888             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12889             if ( !result.equals( "536089" ) ) {
12890                 return false;
12891             }
12892             result = TxSearch.getTxName( "536089" );
12893             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12894                 return false;
12895             }
12896             final List<String> queries = new ArrayList<String>();
12897             queries.add( "Campylobacter coli" );
12898             queries.add( "Escherichia coli" );
12899             queries.add( "Arabidopsis" );
12900             queries.add( "Trichoplax" );
12901             queries.add( "Samanea saman" );
12902             queries.add( "Kluyveromyces marxianus" );
12903             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12904             queries.add( "Bornavirus parrot/PDD/2008" );
12905             final List<RANKS> ranks = new ArrayList<RANKS>();
12906             ranks.add( RANKS.SUPERKINGDOM );
12907             ranks.add( RANKS.KINGDOM );
12908             ranks.add( RANKS.FAMILY );
12909             ranks.add( RANKS.GENUS );
12910             ranks.add( RANKS.TRIBE );
12911             result = TxSearch.searchLineage( queries, ranks );
12912             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12913             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12914         }
12915         catch ( final Exception e ) {
12916             System.out.println();
12917             System.out.println( "the following might be due to absence internet connection:" );
12918             e.printStackTrace( System.out );
12919             return false;
12920         }
12921         return true;
12922     }
12923 }