allow confidence values of 0.0 for domains
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesMap;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.MolecularSequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128 import org.forester.ws.wabi.TxSearch;
129 import org.forester.ws.wabi.TxSearch.RANKS;
130 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
131 import org.forester.ws.wabi.TxSearch.TAX_RANK;
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137                                                                    + ForesterUtil.getFileSeparator() + "resources"
138                                                                    + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140                                                                    + ForesterUtil.getFileSeparator() + "test_data"
141                                                                    + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = true;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
146                                                                    + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
149                                                                    + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     public static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                 + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         System.out.print( "Basic node methods: " );
185         if ( Test.testBasicNodeMethods() ) {
186             System.out.println( "OK." );
187             succeeded++;
188         }
189         else {
190             System.out.println( "failed." );
191             failed++;
192         }
193         System.out.print( "Protein id: " );
194         if ( !testProteinId() ) {
195             System.out.println( "failed." );
196             failed++;
197         }
198         else {
199             succeeded++;
200         }
201         System.out.println( "OK." );
202         System.out.print( "Species: " );
203         if ( !testSpecies() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Basic domain: " );
212         if ( !testBasicDomain() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Basic protein: " );
221         if ( !testBasicProtein() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Sequence writer: " );
230         if ( testSequenceWriter() ) {
231             System.out.println( "OK." );
232             succeeded++;
233         }
234         else {
235             System.out.println( "failed." );
236             failed++;
237         }
238         System.out.print( "Sequence id parsing: " );
239         if ( testSequenceIdParsing() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "UniProtKB id extraction: " );
248         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "Sequence DB tools 1: " );
257         if ( testSequenceDbWsTools1() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Hmmscan output parser: " );
266         if ( testHmmscanOutputParser() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Overlap removal: " );
275         if ( !org.forester.test.Test.testOverlapRemoval() ) {
276             System.out.println( "failed." );
277             failed++;
278         }
279         else {
280             succeeded++;
281         }
282         System.out.println( "OK." );
283         System.out.print( "Engulfing overlap removal: " );
284         if ( !Test.testEngulfingOverlapRemoval() ) {
285             System.out.println( "failed." );
286             failed++;
287         }
288         else {
289             succeeded++;
290         }
291         System.out.println( "OK." );
292         System.out.print( "Taxonomy data extraction: " );
293         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
294             System.out.println( "OK." );
295             succeeded++;
296         }
297         else {
298             System.out.println( "failed." );
299             failed++;
300         }
301         System.out.print( "Taxonomy code extraction: " );
302         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "SN extraction: " );
311         if ( Test.testExtractSNFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy extraction (general): " );
320         if ( Test.testTaxonomyExtraction() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Uri for Aptx web sequence accession: " );
329         if ( Test.testCreateUriForSeqWeb() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Basic node construction and parsing of NHX (node level): " );
338         if ( Test.testNHXNodeParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing iterating: " );
347         if ( Test.testNHParsingIter() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NH parsing: " );
356         if ( Test.testNHParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Conversion to NHX (node level): " );
365         if ( Test.testNHXconversion() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NHX parsing: " );
374         if ( Test.testNHXParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing with quotes: " );
383         if ( Test.testNHXParsingQuotes() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing (MrBayes): " );
392         if ( Test.testNHXParsingMB() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus characters parsing: " );
401         if ( Test.testNexusCharactersParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus tree parsing iterating: " );
410         if ( Test.testNexusTreeParsingIterating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus tree parsing: " );
419         if ( Test.testNexusTreeParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing (translating): " );
428         if ( Test.testNexusTreeParsingTranslating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus matrix parsing: " );
437         if ( Test.testNexusMatrixParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Basic phyloXML parsing: " );
446         if ( Test.testBasicPhyloXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic phyloXML parsing (validating against schema): " );
455         if ( testBasicPhyloXMLparsingValidating() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
464         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "phyloXML Distribution Element: " );
473         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Tol XML parsing: " );
482         if ( Test.testBasicTolXMLparsing() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Copying of node data: " );
491         if ( Test.testCopyOfNodeData() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tree copy: " );
500         if ( Test.testTreeCopy() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Basic tree methods: " );
509         if ( Test.testBasicTreeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree methods: " );
518         if ( Test.testTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Postorder Iterator: " );
527         if ( Test.testPostOrderIterator() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Preorder Iterator: " );
536         if ( Test.testPreOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Levelorder Iterator: " );
545         if ( Test.testLevelOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Re-id methods: " );
554         if ( Test.testReIdMethods() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Methods on last external nodes: " );
563         if ( Test.testLastExternalNodeMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on external nodes: " );
572         if ( Test.testExternalNodeRelatedMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Deletion of external nodes: " );
581         if ( Test.testDeletionOfExternalNodes() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Subtree deletion: " );
590         if ( Test.testSubtreeDeletion() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Phylogeny branch: " );
599         if ( Test.testPhylogenyBranch() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Rerooting: " );
608         if ( Test.testRerooting() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Mipoint rooting: " );
617         if ( Test.testMidpointrooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Node removal: " );
626         if ( Test.testNodeRemoval() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Support count: " );
635         if ( Test.testSupportCount() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support transfer: " );
644         if ( Test.testSupportTransfer() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Finding of LCA: " );
653         if ( Test.testGetLCA() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Finding of LCA 2: " );
662         if ( Test.testGetLCA2() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Calculation of distance between nodes: " );
671         if ( Test.testGetDistance() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Descriptive statistics: " );
680         if ( Test.testDescriptiveStatistics() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Data objects and methods: " );
689         if ( Test.testDataObjects() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Properties map: " );
698         if ( Test.testPropertiesMap() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "SDIse: " );
707         if ( Test.testSDIse() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIunrooted: " );
716         if ( Test.testSDIunrooted() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "GSDI: " );
725         if ( TestGSDI.test() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "RIO: " );
734         if ( TestRIO.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Phylogeny reconstruction:" );
743         System.out.println();
744         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "Analysis of domain architectures: " );
753         System.out.println();
754         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "GO: " );
763         System.out.println();
764         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Modeling tools: " );
773         if ( TestPccx.test() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Split Matrix strict: " );
782         if ( Test.testSplitStrict() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix: " );
791         if ( Test.testSplit() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Confidence Assessor: " );
800         if ( Test.testConfidenceAssessor() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Basic table: " );
809         if ( Test.testBasicTable() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "General table: " );
818         if ( Test.testGeneralTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Amino acid sequence: " );
827         if ( Test.testAminoAcidSequence() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General MSA parser: " );
836         if ( Test.testGeneralMsaParser() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Fasta parser for msa: " );
845         if ( Test.testFastaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Creation of balanced phylogeny: " );
854         if ( Test.testCreateBalancedPhylogeny() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Genbank accessor parsing: " );
863         if ( Test.testGenbankAccessorParsing() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         String path = "";
872         final String os = ForesterUtil.OS_NAME.toLowerCase();
873         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
874             path = "/usr/local/bin/mafft";
875         }
876         else if ( os.indexOf( "win" ) >= 0 ) {
877             path = "C:\\Program Files\\mafft-win\\mafft.bat";
878         }
879         else {
880             path = "mafft";
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/bin/mafft";
883             }
884             if ( !MsaInferrer.isInstalled( path ) ) {
885                 path = "/usr/local/bin/mafft";
886             }
887         }
888         if ( MsaInferrer.isInstalled( path ) ) {
889             System.out.print( "MAFFT (external program): " );
890             if ( Test.testMafft( path ) ) {
891                 System.out.println( "OK." );
892                 succeeded++;
893             }
894             else {
895                 System.out.println( "failed [will not count towards failed tests]" );
896             }
897         }
898         System.out.print( "Next nodes with collapsed: " );
899         if ( Test.testNextNodeWithCollapsing() ) {
900             System.out.println( "OK." );
901             succeeded++;
902         }
903         else {
904             System.out.println( "failed." );
905             failed++;
906         }
907         System.out.print( "Simple MSA quality: " );
908         if ( Test.testMsaQualityMethod() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Deleteable MSA: " );
917         if ( Test.testDeleteableMsa() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         System.out.print( "MSA entropy: " );
926         if ( Test.testMsaEntropy() ) {
927             System.out.println( "OK." );
928             succeeded++;
929         }
930         else {
931             System.out.println( "failed." );
932             failed++;
933         }
934         if ( PERFORM_DB_TESTS ) {
935             System.out.print( "Uniprot Entry Retrieval: " );
936             if ( Test.testUniprotEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Ebi Entry Retrieval: " );
945             if ( Test.testEbiEntryRetrieval() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953             System.out.print( "Sequence DB tools 2: " );
954             if ( testSequenceDbWsTools2() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961                 System.exit( -1 );
962             }
963             System.out.print( "Uniprot Taxonomy Search: " );
964             if ( Test.testUniprotTaxonomySearch() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972         }
973         if ( PERFORM_WEB_TREE_ACCESS ) {
974             System.out.print( "NHX parsing from URL: " );
975             if ( Test.testNHXparsingFromURL() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "NHX parsing from URL 2: " );
984             if ( Test.testNHXparsingFromURL2() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             System.out.print( "phyloXML parsing from URL: " );
993             if ( Test.testPhyloXMLparsingFromURL() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             System.out.print( "TreeBase acccess: " );
1002             if ( Test.testTreeBaseReading() ) {
1003                 System.out.println( "OK." );
1004                 succeeded++;
1005             }
1006             else {
1007                 System.out.println( "failed." );
1008                 failed++;
1009             }
1010             //
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             //
1021             System.out.print( "TreeFam access: " );
1022             if ( Test.testTreeFamReading() ) {
1023                 System.out.println( "OK." );
1024                 succeeded++;
1025             }
1026             else {
1027                 System.out.println( "failed." );
1028                 failed++;
1029             }
1030             //
1031             //
1032             System.out.print( "Pfam tree access: " );
1033             if ( Test.testPfamTreeReading() ) {
1034                 System.out.println( "OK." );
1035                 succeeded++;
1036             }
1037             else {
1038                 System.out.println( "failed." );
1039                 failed++;
1040             }
1041         }
1042         System.out.println();
1043         final Runtime rt = java.lang.Runtime.getRuntime();
1044         final long free_memory = rt.freeMemory() / 1000000;
1045         final long total_memory = rt.totalMemory() / 1000000;
1046         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1047                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1048         System.out.println();
1049         System.out.println( "Successful tests: " + succeeded );
1050         System.out.println( "Failed     tests: " + failed );
1051         System.out.println();
1052         if ( failed < 1 ) {
1053             System.out.println( "OK." );
1054         }
1055         else {
1056             System.out.println( "Not OK." );
1057         }
1058     }
1059
1060     public static boolean testEngulfingOverlapRemoval() {
1061         try {
1062             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1063             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1064             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1065             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1067             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1068             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1069             final List<Boolean> covered = new ArrayList<Boolean>();
1070             covered.add( true ); // 0
1071             covered.add( false ); // 1
1072             covered.add( true ); // 2
1073             covered.add( false ); // 3
1074             covered.add( true ); // 4
1075             covered.add( true ); // 5
1076             covered.add( false ); // 6
1077             covered.add( true ); // 7
1078             covered.add( true ); // 8
1079             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1086                 return false;
1087             }
1088             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1089                 return false;
1090             }
1091             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1092                 return false;
1093             }
1094             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1095                 return false;
1096             }
1097             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1098                 return false;
1099             }
1100             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1101             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1102             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1103             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1104             abc.addProteinDomain( a );
1105             abc.addProteinDomain( b );
1106             abc.addProteinDomain( c );
1107             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1108             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1109             if ( abc.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1113                 return false;
1114             }
1115             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1116                 return false;
1117             }
1118             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1119                 return false;
1120             }
1121             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1122                 return false;
1123             }
1124             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1126             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1127             final Protein def = new BasicProtein( "def", "nemve", 0 );
1128             def.addProteinDomain( d );
1129             def.addProteinDomain( e );
1130             def.addProteinDomain( f );
1131             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1132             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1133             if ( def.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1140                 return false;
1141             }
1142             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1146                 return false;
1147             }
1148             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1149                 return false;
1150             }
1151         }
1152         catch ( final Exception e ) {
1153             e.printStackTrace( System.out );
1154             return false;
1155         }
1156         return true;
1157     }
1158
1159     public static final boolean testNHXparsingFromURL2() {
1160         try {
1161             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1162             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1163                                                                       false,
1164                                                                       false,
1165                                                                       false,
1166                                                                       TAXONOMY_EXTRACTION.NO,
1167                                                                       false );
1168             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1169                 return false;
1170             }
1171             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1172                 System.out.println( phys[ 0 ].toNewHampshire() );
1173                 return false;
1174             }
1175             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1176                 System.out.println( phys[ 1 ].toNewHampshire() );
1177                 return false;
1178             }
1179             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1180                                                                        false,
1181                                                                        false,
1182                                                                        false,
1183                                                                        TAXONOMY_EXTRACTION.NO,
1184                                                                        false );
1185             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1186                 return false;
1187             }
1188             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1189                 System.out.println( phys2[ 0 ].toNewHampshire() );
1190                 return false;
1191             }
1192             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1193                 System.out.println( phys2[ 1 ].toNewHampshire() );
1194                 return false;
1195             }
1196             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1197                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1198             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1199                 return false;
1200             }
1201             if ( !phys3[ 0 ]
1202                     .toNewHampshire()
1203                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1204                 System.out.println( phys3[ 0 ].toNewHampshire() );
1205                 return false;
1206             }
1207             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1208                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1209             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1210                 return false;
1211             }
1212             if ( !phys4[ 0 ]
1213                     .toNewHampshire()
1214                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1215                 System.out.println( phys4[ 0 ].toNewHampshire() );
1216                 return false;
1217             }
1218         }
1219         catch ( final Exception e ) {
1220             e.printStackTrace();
1221             return false;
1222         }
1223         return true;
1224     }
1225
1226     public static final boolean testNHXparsingFromURL() {
1227         try {
1228             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1229             final URL u = new URL( s );
1230             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1231             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1232             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1233                 return false;
1234             }
1235             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1236                 System.out.println( phys[ 0 ].toNewHampshire() );
1237                 return false;
1238             }
1239             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1240                 System.out.println( phys[ 1 ].toNewHampshire() );
1241                 return false;
1242             }
1243             final URL u2 = new URL( s );
1244             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1245             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1246                 return false;
1247             }
1248             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1249                 System.out.println( phys2[ 0 ].toNewHampshire() );
1250                 return false;
1251             }
1252             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1253             final NHXParser p = new NHXParser();
1254             final URL u3 = new URL( s );
1255             p.setSource( u3 );
1256             if ( !p.hasNext() ) {
1257                 return false;
1258             }
1259             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1260                 return false;
1261             }
1262             if ( !p.hasNext() ) {
1263                 return false;
1264             }
1265             p.reset();
1266             if ( !p.hasNext() ) {
1267                 return false;
1268             }
1269             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1270                 return false;
1271             }
1272             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1273                 return false;
1274             }
1275             p.reset();
1276             if ( !p.hasNext() ) {
1277                 return false;
1278             }
1279             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1280                 return false;
1281             }
1282             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1283                 return false;
1284             }
1285         }
1286         catch ( final Exception e ) {
1287             System.out.println( e.toString() );
1288             e.printStackTrace();
1289             return false;
1290         }
1291         return true;
1292     }
1293
1294     public static boolean testOverlapRemoval() {
1295         try {
1296             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1297             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1298             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1299             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1300             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1301             final List<Boolean> covered = new ArrayList<Boolean>();
1302             covered.add( true ); // 0
1303             covered.add( false ); // 1
1304             covered.add( true ); // 2
1305             covered.add( false ); // 3
1306             covered.add( true ); // 4
1307             covered.add( true ); // 5
1308             covered.add( false ); // 6
1309             covered.add( true ); // 7
1310             covered.add( true ); // 8
1311             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1312                 return false;
1313             }
1314             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1315                 return false;
1316             }
1317             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1318                 return false;
1319             }
1320             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1321                 return false;
1322             }
1323             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1324                 return false;
1325             }
1326             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1327             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1328             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1329             ab.addProteinDomain( a );
1330             ab.addProteinDomain( b );
1331             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1332             if ( ab.getNumberOfProteinDomains() != 2 ) {
1333                 return false;
1334             }
1335             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1336                 return false;
1337             }
1338             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1339                 return false;
1340             }
1341             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1342             if ( ab.getNumberOfProteinDomains() != 2 ) {
1343                 return false;
1344             }
1345             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1346                 return false;
1347             }
1348             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1349             final Domain d = new BasicDomain( "d",
1350                                               ( short ) 10000,
1351                                               ( short ) 10500,
1352                                               ( short ) 1,
1353                                               ( short ) 1,
1354                                               0.0000001,
1355                                               1 );
1356             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1357             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1358             cde.addProteinDomain( c );
1359             cde.addProteinDomain( d );
1360             cde.addProteinDomain( e );
1361             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1362             if ( cde.getNumberOfProteinDomains() != 3 ) {
1363                 return false;
1364             }
1365             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1366                 return false;
1367             }
1368             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1369             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1370             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1371             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1372             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1373             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1374             fghi.addProteinDomain( f );
1375             fghi.addProteinDomain( g );
1376             fghi.addProteinDomain( h );
1377             fghi.addProteinDomain( i );
1378             fghi.addProteinDomain( i );
1379             fghi.addProteinDomain( i );
1380             fghi.addProteinDomain( i2 );
1381             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1382             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1383                 return false;
1384             }
1385             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1386                 return false;
1387             }
1388             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1389                 return false;
1390             }
1391             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1392             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1393                 return false;
1394             }
1395             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1396                 return false;
1397             }
1398             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1399             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1400             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1401             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1402             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1403             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1404             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1405             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1406             jklm.addProteinDomain( j );
1407             jklm.addProteinDomain( k );
1408             jklm.addProteinDomain( l );
1409             jklm.addProteinDomain( m );
1410             jklm.addProteinDomain( m0 );
1411             jklm.addProteinDomain( m1 );
1412             jklm.addProteinDomain( m2 );
1413             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1414             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1415                 return false;
1416             }
1417             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1418                 return false;
1419             }
1420             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1421                 return false;
1422             }
1423             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1424             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1425                 return false;
1426             }
1427             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1428                 return false;
1429             }
1430             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1431             final Protein od = new BasicProtein( "od", "varanus", 0 );
1432             od.addProteinDomain( only );
1433             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1434             if ( od.getNumberOfProteinDomains() != 1 ) {
1435                 return false;
1436             }
1437             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace( System.out );
1443             return false;
1444         }
1445         return true;
1446     }
1447
1448     public static final boolean testPfamTreeReading() {
1449         try {
1450             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1451             final NHXParser parser = new NHXParser();
1452             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1453             parser.setReplaceUnderscores( false );
1454             parser.setGuessRootedness( true );
1455             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1456             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1457             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1458                 return false;
1459             }
1460             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1461                 return false;
1462             }
1463         }
1464         catch ( final Exception e ) {
1465             e.printStackTrace();
1466         }
1467         return true;
1468     }
1469
1470     public static final boolean testPhyloXMLparsingFromURL() {
1471         try {
1472             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1473             final URL u = new URL( s );
1474             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1475             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1476             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1477                 return false;
1478             }
1479         }
1480         catch ( final Exception e ) {
1481             e.printStackTrace();
1482         }
1483         return true;
1484     }
1485
1486     public static final boolean testToLReading() {
1487         try {
1488             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1489             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1490             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1491             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1492                 return false;
1493             }
1494             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1495                 return false;
1496             }
1497             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1498                 return false;
1499             }
1500             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1501                 return false;
1502             }
1503         }
1504         catch ( final Exception e ) {
1505             e.printStackTrace();
1506         }
1507         return true;
1508     }
1509
1510     public static final boolean testTreeBaseReading() {
1511         try {
1512             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1513             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1514             parser.setReplaceUnderscores( true );
1515             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1516             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1517             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1518                 return false;
1519             }
1520             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1521             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1522             parser2.setReplaceUnderscores( true );
1523             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1524             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1525             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1526                 return false;
1527             }
1528         }
1529         catch ( final Exception e ) {
1530             e.printStackTrace();
1531         }
1532         return true;
1533     }
1534
1535     public static final boolean testTreeFamReading() {
1536         try {
1537             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1538             final NHXParser parser = new NHXParser();
1539             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1540             parser.setReplaceUnderscores( false );
1541             parser.setGuessRootedness( true );
1542             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1543             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1544             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1545                 return false;
1546             }
1547             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1548                 return false;
1549             }
1550         }
1551         catch ( final Exception e ) {
1552             e.printStackTrace();
1553         }
1554         return true;
1555     }
1556
1557     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1558         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1559         return p;
1560     }
1561
1562     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1563         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1564     }
1565
1566     private static boolean testAminoAcidSequence() {
1567         try {
1568             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1569             if ( aa1.getLength() != 13 ) {
1570                 return false;
1571             }
1572             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1573                 return false;
1574             }
1575             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1576                 return false;
1577             }
1578             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1579                 return false;
1580             }
1581             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1582             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1583                 return false;
1584             }
1585             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1586             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1587                 return false;
1588             }
1589             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1590             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1591                 return false;
1592             }
1593         }
1594         catch ( final Exception e ) {
1595             e.printStackTrace();
1596             return false;
1597         }
1598         return true;
1599     }
1600
1601     private static boolean testBasicDomain() {
1602         try {
1603             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1604             if ( !pd.getDomainId().equals( "id" ) ) {
1605                 return false;
1606             }
1607             if ( pd.getNumber() != 1 ) {
1608                 return false;
1609             }
1610             if ( pd.getTotalCount() != 4 ) {
1611                 return false;
1612             }
1613             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1614                 return false;
1615             }
1616             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1617             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1618             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1619             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1620             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1621             if ( !a1.equals( a1 ) ) {
1622                 return false;
1623             }
1624             if ( !a1.equals( a1_copy ) ) {
1625                 return false;
1626             }
1627             if ( !a1.equals( a1_equal ) ) {
1628                 return false;
1629             }
1630             if ( !a1.equals( a2 ) ) {
1631                 return false;
1632             }
1633             if ( a1.equals( a3 ) ) {
1634                 return false;
1635             }
1636             if ( a1.compareTo( a1 ) != 0 ) {
1637                 return false;
1638             }
1639             if ( a1.compareTo( a1_copy ) != 0 ) {
1640                 return false;
1641             }
1642             if ( a1.compareTo( a1_equal ) != 0 ) {
1643                 return false;
1644             }
1645             if ( a1.compareTo( a2 ) != 0 ) {
1646                 return false;
1647             }
1648             if ( a1.compareTo( a3 ) == 0 ) {
1649                 return false;
1650             }
1651         }
1652         catch ( final Exception e ) {
1653             e.printStackTrace( System.out );
1654             return false;
1655         }
1656         return true;
1657     }
1658
1659     private static boolean testBasicNodeMethods() {
1660         try {
1661             if ( PhylogenyNode.getNodeCount() != 0 ) {
1662                 return false;
1663             }
1664             final PhylogenyNode n1 = new PhylogenyNode();
1665             final PhylogenyNode n2 = PhylogenyNode
1666                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1667             final PhylogenyNode n3 = PhylogenyNode
1668                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1669             final PhylogenyNode n4 = PhylogenyNode
1670                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1671             if ( n1.isHasAssignedEvent() ) {
1672                 return false;
1673             }
1674             if ( PhylogenyNode.getNodeCount() != 4 ) {
1675                 return false;
1676             }
1677             if ( n3.getIndicator() != 0 ) {
1678                 return false;
1679             }
1680             if ( n3.getNumberOfExternalNodes() != 1 ) {
1681                 return false;
1682             }
1683             if ( !n3.isExternal() ) {
1684                 return false;
1685             }
1686             if ( !n3.isRoot() ) {
1687                 return false;
1688             }
1689             if ( !n4.getName().equals( "n4" ) ) {
1690                 return false;
1691             }
1692         }
1693         catch ( final Exception e ) {
1694             e.printStackTrace( System.out );
1695             return false;
1696         }
1697         return true;
1698     }
1699
1700     private static boolean testBasicPhyloXMLparsing() {
1701         try {
1702             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1703             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1704             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1705                                                               xml_parser );
1706             if ( xml_parser.getErrorCount() > 0 ) {
1707                 System.out.println( xml_parser.getErrorMessages().toString() );
1708                 return false;
1709             }
1710             if ( phylogenies_0.length != 4 ) {
1711                 return false;
1712             }
1713             final Phylogeny t1 = phylogenies_0[ 0 ];
1714             final Phylogeny t2 = phylogenies_0[ 1 ];
1715             final Phylogeny t3 = phylogenies_0[ 2 ];
1716             final Phylogeny t4 = phylogenies_0[ 3 ];
1717             if ( t1.getNumberOfExternalNodes() != 1 ) {
1718                 return false;
1719             }
1720             if ( !t1.isRooted() ) {
1721                 return false;
1722             }
1723             if ( t1.isRerootable() ) {
1724                 return false;
1725             }
1726             if ( !t1.getType().equals( "gene_tree" ) ) {
1727                 return false;
1728             }
1729             if ( t2.getNumberOfExternalNodes() != 2 ) {
1730                 return false;
1731             }
1732             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1733                 return false;
1734             }
1735             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1736                 return false;
1737             }
1738             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1739                 return false;
1740             }
1741             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1742                 return false;
1743             }
1744             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1745                 return false;
1746             }
1747             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1748                 return false;
1749             }
1750             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1751                     .startsWith( "actgtgggggt" ) ) {
1752                 return false;
1753             }
1754             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1755                     .startsWith( "ctgtgatgcat" ) ) {
1756                 return false;
1757             }
1758             if ( t3.getNumberOfExternalNodes() != 4 ) {
1759                 return false;
1760             }
1761             if ( !t1.getName().equals( "t1" ) ) {
1762                 return false;
1763             }
1764             if ( !t2.getName().equals( "t2" ) ) {
1765                 return false;
1766             }
1767             if ( !t3.getName().equals( "t3" ) ) {
1768                 return false;
1769             }
1770             if ( !t4.getName().equals( "t4" ) ) {
1771                 return false;
1772             }
1773             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1774                 return false;
1775             }
1776             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1777                 return false;
1778             }
1779             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1780                 return false;
1781             }
1782             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1783                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1784                 return false;
1785             }
1786             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1787                 return false;
1788             }
1789             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1790                 return false;
1791             }
1792             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1793                 return false;
1794             }
1795             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1796                     .equals( "apoptosis" ) ) {
1797                 return false;
1798             }
1799             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1800                     .equals( "GO:0006915" ) ) {
1801                 return false;
1802             }
1803             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1804                     .equals( "UniProtKB" ) ) {
1805                 return false;
1806             }
1807             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1808                     .equals( "experimental" ) ) {
1809                 return false;
1810             }
1811             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1812                     .equals( "function" ) ) {
1813                 return false;
1814             }
1815             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1816                     .getValue() != 1 ) {
1817                 return false;
1818             }
1819             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1820                     .getType().equals( "ml" ) ) {
1821                 return false;
1822             }
1823             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1824                     .equals( "apoptosis" ) ) {
1825                 return false;
1826             }
1827             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1828                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1829                 return false;
1830             }
1831             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1832                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1833                 return false;
1834             }
1835             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1836                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1837                 return false;
1838             }
1839             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1840                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1841                 return false;
1842             }
1843             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1844                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1845                 return false;
1846             }
1847             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1848                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1849                 return false;
1850             }
1851             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1852                     .equals( "GO:0005829" ) ) {
1853                 return false;
1854             }
1855             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1856                     .equals( "intracellular organelle" ) ) {
1857                 return false;
1858             }
1859             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1860                 return false;
1861             }
1862             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1863                     .equals( "UniProt link" ) ) ) {
1864                 return false;
1865             }
1866             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1867                 return false;
1868             }
1869             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1870             if ( x.size() != 4 ) {
1871                 return false;
1872             }
1873             int c = 0;
1874             for( final Accession acc : x ) {
1875                 if ( c == 0 ) {
1876                     if ( !acc.getSource().equals( "KEGG" ) ) {
1877                         return false;
1878                     }
1879                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1880                         return false;
1881                     }
1882                 }
1883                 c++;
1884             }
1885         }
1886         catch ( final Exception e ) {
1887             e.printStackTrace( System.out );
1888             return false;
1889         }
1890         return true;
1891     }
1892
1893     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1894         try {
1895             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1896             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1897             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1898                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1899             }
1900             else {
1901                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1902             }
1903             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1904                                                               xml_parser );
1905             if ( xml_parser.getErrorCount() > 0 ) {
1906                 System.out.println( xml_parser.getErrorMessages().toString() );
1907                 return false;
1908             }
1909             if ( phylogenies_0.length != 4 ) {
1910                 return false;
1911             }
1912             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1913             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1914             if ( phylogenies_t1.length != 1 ) {
1915                 return false;
1916             }
1917             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1918             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1919                 return false;
1920             }
1921             if ( !t1_rt.isRooted() ) {
1922                 return false;
1923             }
1924             if ( t1_rt.isRerootable() ) {
1925                 return false;
1926             }
1927             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1928                 return false;
1929             }
1930             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1931             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1932             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1933             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1934                 return false;
1935             }
1936             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1937                 return false;
1938             }
1939             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1940                 return false;
1941             }
1942             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1943                 return false;
1944             }
1945             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1946                     .startsWith( "actgtgggggt" ) ) {
1947                 return false;
1948             }
1949             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1950                     .startsWith( "ctgtgatgcat" ) ) {
1951                 return false;
1952             }
1953             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1954             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1955             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1956             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1957             if ( phylogenies_1.length != 1 ) {
1958                 return false;
1959             }
1960             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1961             if ( !t3_rt.getName().equals( "t3" ) ) {
1962                 return false;
1963             }
1964             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1974                 return false;
1975             }
1976             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1977                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1978                 return false;
1979             }
1980             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1981                 return false;
1982             }
1983             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1984                 return false;
1985             }
1986             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1987                     .equals( "UniProtKB" ) ) {
1988                 return false;
1989             }
1990             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1991                     .equals( "apoptosis" ) ) {
1992                 return false;
1993             }
1994             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1995                     .equals( "GO:0006915" ) ) {
1996                 return false;
1997             }
1998             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1999                     .equals( "UniProtKB" ) ) {
2000                 return false;
2001             }
2002             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2003                     .equals( "experimental" ) ) {
2004                 return false;
2005             }
2006             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2007                     .equals( "function" ) ) {
2008                 return false;
2009             }
2010             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2011                     .getValue() != 1 ) {
2012                 return false;
2013             }
2014             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2015                     .getType().equals( "ml" ) ) {
2016                 return false;
2017             }
2018             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2019                     .equals( "apoptosis" ) ) {
2020                 return false;
2021             }
2022             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2023                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2024                 return false;
2025             }
2026             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2027                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2028                 return false;
2029             }
2030             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2031                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2032                 return false;
2033             }
2034             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2035                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2036                 return false;
2037             }
2038             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2039                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2040                 return false;
2041             }
2042             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2043                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2044                 return false;
2045             }
2046             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2047                     .equals( "GO:0005829" ) ) {
2048                 return false;
2049             }
2050             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2051                     .equals( "intracellular organelle" ) ) {
2052                 return false;
2053             }
2054             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2055                 return false;
2056             }
2057             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2058                     .equals( "UniProt link" ) ) ) {
2059                 return false;
2060             }
2061             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2062                 return false;
2063             }
2064             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2065                 return false;
2066             }
2067             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2068                     .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." ) ) ) {
2069                 return false;
2070             }
2071             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2072                 return false;
2073             }
2074             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2075                 return false;
2076             }
2077             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2078                 return false;
2079             }
2080             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2081                 return false;
2082             }
2083             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2084                     .equals( "ncbi" ) ) {
2085                 return false;
2086             }
2087             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2088                 return false;
2089             }
2090             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2091                     .getName().equals( "B" ) ) {
2092                 return false;
2093             }
2094             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2095                     .getFrom() != 21 ) {
2096                 return false;
2097             }
2098             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2099                 return false;
2100             }
2101             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2102                     .getLength() != 24 ) {
2103                 return false;
2104             }
2105             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2106                     .getConfidence() != 0 ) {
2107                 return false;
2108             }
2109             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2110                     .equals( "pfam" ) ) {
2111                 return false;
2112             }
2113             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2114                 return false;
2115             }
2116             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2117                 return false;
2118             }
2119             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2120                 return false;
2121             }
2122             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2123                 return false;
2124             }
2125             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2126             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2127                 return false;
2128             }
2129             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2130                 return false;
2131             }
2132             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2133                 return false;
2134             }
2135             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2136                 return false;
2137             }
2138             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2139                 return false;
2140             }
2141             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2142                 return false;
2143             }
2144             if ( taxbb.getSynonyms().size() != 2 ) {
2145                 return false;
2146             }
2147             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2148                 return false;
2149             }
2150             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2151                 return false;
2152             }
2153             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2154                 return false;
2155             }
2156             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2157                 return false;
2158             }
2159             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2160                 return false;
2161             }
2162             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2163                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2164                 return false;
2165             }
2166             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2167                 return false;
2168             }
2169             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2170                 return false;
2171             }
2172             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2173                 return false;
2174             }
2175             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2176                 return false;
2177             }
2178             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2179                 return false;
2180             }
2181             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2182                 return false;
2183             }
2184             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2185                 return false;
2186             }
2187             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2188                 return false;
2189             }
2190             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2191                     .equalsIgnoreCase( "435" ) ) {
2192                 return false;
2193             }
2194             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2195                 return false;
2196             }
2197             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2198                     .equalsIgnoreCase( "443.7" ) ) {
2199                 return false;
2200             }
2201             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2202                 return false;
2203             }
2204             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2205                 return false;
2206             }
2207             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2208                     .equalsIgnoreCase( "433" ) ) {
2209                 return false;
2210             }
2211             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2212                     .getCrossReferences();
2213             if ( x.size() != 4 ) {
2214                 return false;
2215             }
2216             int c = 0;
2217             for( final Accession acc : x ) {
2218                 if ( c == 0 ) {
2219                     if ( !acc.getSource().equals( "KEGG" ) ) {
2220                         return false;
2221                     }
2222                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2223                         return false;
2224                     }
2225                 }
2226                 c++;
2227             }
2228         }
2229         catch ( final Exception e ) {
2230             e.printStackTrace( System.out );
2231             return false;
2232         }
2233         return true;
2234     }
2235
2236     private static boolean testBasicPhyloXMLparsingValidating() {
2237         try {
2238             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2239             PhyloXmlParser xml_parser = null;
2240             try {
2241                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2242             }
2243             catch ( final Exception e ) {
2244                 // Do nothing -- means were not running from jar.
2245             }
2246             if ( xml_parser == null ) {
2247                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2248                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2249                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2250                 }
2251                 else {
2252                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2253                 }
2254             }
2255             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2256                                                               xml_parser );
2257             if ( xml_parser.getErrorCount() > 0 ) {
2258                 System.out.println( xml_parser.getErrorMessages().toString() );
2259                 return false;
2260             }
2261             if ( phylogenies_0.length != 4 ) {
2262                 return false;
2263             }
2264             final Phylogeny t1 = phylogenies_0[ 0 ];
2265             final Phylogeny t2 = phylogenies_0[ 1 ];
2266             final Phylogeny t3 = phylogenies_0[ 2 ];
2267             final Phylogeny t4 = phylogenies_0[ 3 ];
2268             if ( !t1.getName().equals( "t1" ) ) {
2269                 return false;
2270             }
2271             if ( !t2.getName().equals( "t2" ) ) {
2272                 return false;
2273             }
2274             if ( !t3.getName().equals( "t3" ) ) {
2275                 return false;
2276             }
2277             if ( !t4.getName().equals( "t4" ) ) {
2278                 return false;
2279             }
2280             if ( t1.getNumberOfExternalNodes() != 1 ) {
2281                 return false;
2282             }
2283             if ( t2.getNumberOfExternalNodes() != 2 ) {
2284                 return false;
2285             }
2286             if ( t3.getNumberOfExternalNodes() != 4 ) {
2287                 return false;
2288             }
2289             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2290             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2291             if ( xml_parser.getErrorCount() > 0 ) {
2292                 System.out.println( "errors:" );
2293                 System.out.println( xml_parser.getErrorMessages().toString() );
2294                 return false;
2295             }
2296             if ( phylogenies_1.length != 4 ) {
2297                 return false;
2298             }
2299             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2300                                                               xml_parser );
2301             if ( xml_parser.getErrorCount() > 0 ) {
2302                 System.out.println( "errors:" );
2303                 System.out.println( xml_parser.getErrorMessages().toString() );
2304                 return false;
2305             }
2306             if ( phylogenies_2.length != 1 ) {
2307                 return false;
2308             }
2309             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2310                 return false;
2311             }
2312             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2313                                                               xml_parser );
2314             if ( xml_parser.getErrorCount() > 0 ) {
2315                 System.out.println( xml_parser.getErrorMessages().toString() );
2316                 return false;
2317             }
2318             if ( phylogenies_3.length != 2 ) {
2319                 return false;
2320             }
2321             final Phylogeny a = phylogenies_3[ 0 ];
2322             if ( !a.getName().equals( "tree 4" ) ) {
2323                 return false;
2324             }
2325             if ( a.getNumberOfExternalNodes() != 3 ) {
2326                 return false;
2327             }
2328             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2329                 return false;
2330             }
2331             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2332                 return false;
2333             }
2334             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2335                                                               xml_parser );
2336             if ( xml_parser.getErrorCount() > 0 ) {
2337                 System.out.println( xml_parser.getErrorMessages().toString() );
2338                 return false;
2339             }
2340             if ( phylogenies_4.length != 1 ) {
2341                 return false;
2342             }
2343             final Phylogeny s = phylogenies_4[ 0 ];
2344             if ( s.getNumberOfExternalNodes() != 6 ) {
2345                 return false;
2346             }
2347             s.getNode( "first" );
2348             s.getNode( "<>" );
2349             s.getNode( "\"<a'b&c'd\">\"" );
2350             s.getNode( "'''\"" );
2351             s.getNode( "\"\"\"" );
2352             s.getNode( "dick & doof" );
2353         }
2354         catch ( final Exception e ) {
2355             e.printStackTrace( System.out );
2356             return false;
2357         }
2358         return true;
2359     }
2360
2361     private static boolean testBasicProtein() {
2362         try {
2363             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2364             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             p0.addProteinDomain( y );
2372             p0.addProteinDomain( e );
2373             p0.addProteinDomain( b );
2374             p0.addProteinDomain( c );
2375             p0.addProteinDomain( d );
2376             p0.addProteinDomain( a );
2377             p0.addProteinDomain( x );
2378             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2379                 return false;
2380             }
2381             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2382                 return false;
2383             }
2384             //
2385             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2386             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2387             aa0.addProteinDomain( a1 );
2388             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2389                 return false;
2390             }
2391             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2392                 return false;
2393             }
2394             //
2395             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2396             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2397             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2398             aa1.addProteinDomain( a11 );
2399             aa1.addProteinDomain( a12 );
2400             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2401                 return false;
2402             }
2403             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2404                 return false;
2405             }
2406             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2407             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2408                 return false;
2409             }
2410             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2411                 return false;
2412             }
2413             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2414                 return false;
2415             }
2416             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2417             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2418                 return false;
2419             }
2420             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2421                 return false;
2422             }
2423             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2424                 return false;
2425             }
2426             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2427                 return false;
2428             }
2429             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2430             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2431                 return false;
2432             }
2433             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2434                 return false;
2435             }
2436             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2437                 return false;
2438             }
2439             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2440                 return false;
2441             }
2442             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2443             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2444                 return false;
2445             }
2446             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2447                 return false;
2448             }
2449             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2450                 return false;
2451             }
2452             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2453                 return false;
2454             }
2455             //
2456             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2457             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2458             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2459             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2460             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2461             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2462             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2463             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2464             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2465             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2466             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2467             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2468             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2469             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2470             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2471             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2472             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2473             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2474             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2475             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2476             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2477             p00.addProteinDomain( y0 );
2478             p00.addProteinDomain( e0 );
2479             p00.addProteinDomain( b0 );
2480             p00.addProteinDomain( c0 );
2481             p00.addProteinDomain( d0 );
2482             p00.addProteinDomain( a0 );
2483             p00.addProteinDomain( x0 );
2484             p00.addProteinDomain( y1 );
2485             p00.addProteinDomain( y2 );
2486             p00.addProteinDomain( y3 );
2487             p00.addProteinDomain( e1 );
2488             p00.addProteinDomain( e2 );
2489             p00.addProteinDomain( e3 );
2490             p00.addProteinDomain( e4 );
2491             p00.addProteinDomain( e5 );
2492             p00.addProteinDomain( z0 );
2493             p00.addProteinDomain( z1 );
2494             p00.addProteinDomain( z2 );
2495             p00.addProteinDomain( zz0 );
2496             p00.addProteinDomain( zz1 );
2497             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2498                 return false;
2499             }
2500             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2501                 return false;
2502             }
2503             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2504                 return false;
2505             }
2506             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2507                 return false;
2508             }
2509             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" ) ) {
2510                 return false;
2511             }
2512             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2513             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2514             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2515             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2516             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2517             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2518             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2519             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2520             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2521             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2522             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2523             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2524             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2525             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2526             p.addProteinDomain( B15 );
2527             p.addProteinDomain( C50 );
2528             p.addProteinDomain( A60 );
2529             p.addProteinDomain( A30 );
2530             p.addProteinDomain( C70 );
2531             p.addProteinDomain( B35 );
2532             p.addProteinDomain( B40 );
2533             p.addProteinDomain( A0 );
2534             p.addProteinDomain( A10 );
2535             p.addProteinDomain( A20 );
2536             p.addProteinDomain( B25 );
2537             p.addProteinDomain( D80 );
2538             List<String> domains_ids = new ArrayList<String>();
2539             domains_ids.add( "A" );
2540             domains_ids.add( "B" );
2541             domains_ids.add( "C" );
2542             if ( !p.contains( domains_ids, false ) ) {
2543                 return false;
2544             }
2545             if ( !p.contains( domains_ids, true ) ) {
2546                 return false;
2547             }
2548             domains_ids.add( "X" );
2549             if ( p.contains( domains_ids, false ) ) {
2550                 return false;
2551             }
2552             if ( p.contains( domains_ids, true ) ) {
2553                 return false;
2554             }
2555             domains_ids = new ArrayList<String>();
2556             domains_ids.add( "A" );
2557             domains_ids.add( "C" );
2558             domains_ids.add( "D" );
2559             if ( !p.contains( domains_ids, false ) ) {
2560                 return false;
2561             }
2562             if ( !p.contains( domains_ids, true ) ) {
2563                 return false;
2564             }
2565             domains_ids = new ArrayList<String>();
2566             domains_ids.add( "A" );
2567             domains_ids.add( "D" );
2568             domains_ids.add( "C" );
2569             if ( !p.contains( domains_ids, false ) ) {
2570                 return false;
2571             }
2572             if ( p.contains( domains_ids, true ) ) {
2573                 return false;
2574             }
2575             domains_ids = new ArrayList<String>();
2576             domains_ids.add( "A" );
2577             domains_ids.add( "A" );
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( "A" );
2589             domains_ids.add( "B" );
2590             domains_ids.add( "B" );
2591             if ( !p.contains( domains_ids, false ) ) {
2592                 return false;
2593             }
2594             if ( !p.contains( domains_ids, true ) ) {
2595                 return false;
2596             }
2597             domains_ids = new ArrayList<String>();
2598             domains_ids.add( "A" );
2599             domains_ids.add( "A" );
2600             domains_ids.add( "B" );
2601             domains_ids.add( "A" );
2602             domains_ids.add( "B" );
2603             domains_ids.add( "B" );
2604             domains_ids.add( "A" );
2605             domains_ids.add( "B" );
2606             domains_ids.add( "C" );
2607             domains_ids.add( "A" );
2608             domains_ids.add( "C" );
2609             domains_ids.add( "D" );
2610             if ( !p.contains( domains_ids, false ) ) {
2611                 return false;
2612             }
2613             if ( p.contains( domains_ids, true ) ) {
2614                 return false;
2615             }
2616         }
2617         catch ( final Exception e ) {
2618             e.printStackTrace( System.out );
2619             return false;
2620         }
2621         return true;
2622     }
2623
2624     private static boolean testBasicTable() {
2625         try {
2626             final BasicTable<String> t0 = new BasicTable<String>();
2627             if ( t0.getNumberOfColumns() != 0 ) {
2628                 return false;
2629             }
2630             if ( t0.getNumberOfRows() != 0 ) {
2631                 return false;
2632             }
2633             t0.setValue( 3, 2, "23" );
2634             t0.setValue( 10, 1, "error" );
2635             t0.setValue( 10, 1, "110" );
2636             t0.setValue( 9, 1, "19" );
2637             t0.setValue( 1, 10, "101" );
2638             t0.setValue( 10, 10, "1010" );
2639             t0.setValue( 100, 10, "10100" );
2640             t0.setValue( 0, 0, "00" );
2641             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2642                 return false;
2643             }
2644             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2645                 return false;
2646             }
2647             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2648                 return false;
2649             }
2650             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2651                 return false;
2652             }
2653             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2654                 return false;
2655             }
2656             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2657                 return false;
2658             }
2659             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2660                 return false;
2661             }
2662             if ( t0.getNumberOfColumns() != 101 ) {
2663                 return false;
2664             }
2665             if ( t0.getNumberOfRows() != 11 ) {
2666                 return false;
2667             }
2668             if ( t0.getValueAsString( 49, 4 ) != null ) {
2669                 return false;
2670             }
2671             final String l = ForesterUtil.getLineSeparator();
2672             final StringBuffer source = new StringBuffer();
2673             source.append( "" + l );
2674             source.append( "# 1 1 1 1 1 1 1 1" + l );
2675             source.append( " 00 01 02 03" + l );
2676             source.append( "   10 11 12 13  " + l );
2677             source.append( "20 21 22 23 " + l );
2678             source.append( "    30  31    32 33" + l );
2679             source.append( "40 41 42 43" + l );
2680             source.append( "  # 1 1 1 1 1 " + l );
2681             source.append( "50 51 52 53 54" + l );
2682             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2683             if ( t1.getNumberOfColumns() != 5 ) {
2684                 return false;
2685             }
2686             if ( t1.getNumberOfRows() != 6 ) {
2687                 return false;
2688             }
2689             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2690                 return false;
2691             }
2692             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2693                 return false;
2694             }
2695             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2696                 return false;
2697             }
2698             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2699                 return false;
2700             }
2701             final StringBuffer source1 = new StringBuffer();
2702             source1.append( "" + l );
2703             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2704             source1.append( " 00; 01 ;02;03" + l );
2705             source1.append( "   10; 11; 12; 13  " + l );
2706             source1.append( "20; 21; 22; 23 " + l );
2707             source1.append( "    30;  31;    32; 33" + l );
2708             source1.append( "40;41;42;43" + l );
2709             source1.append( "  # 1 1 1 1 1 " + l );
2710             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2711             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2712             if ( t2.getNumberOfColumns() != 5 ) {
2713                 return false;
2714             }
2715             if ( t2.getNumberOfRows() != 6 ) {
2716                 return false;
2717             }
2718             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2719                 return false;
2720             }
2721             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2722                 return false;
2723             }
2724             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2725                 return false;
2726             }
2727             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2728                 return false;
2729             }
2730             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2731                 return false;
2732             }
2733             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2734                 return false;
2735             }
2736             final StringBuffer source2 = new StringBuffer();
2737             source2.append( "" + l );
2738             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2739             source2.append( " 00; 01 ;02;03" + l );
2740             source2.append( "   10; 11; 12; 13  " + l );
2741             source2.append( "20; 21; 22; 23 " + l );
2742             source2.append( "                     " + l );
2743             source2.append( "    30;  31;    32; 33" + l );
2744             source2.append( "40;41;42;43" + l );
2745             source2.append( "  comment: 1 1 1 1 1 " + l );
2746             source2.append( ";;;50  ;   52; 53;;54   " + l );
2747             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2748                                                                         ';',
2749                                                                         false,
2750                                                                         false,
2751                                                                         "comment:",
2752                                                                         false );
2753             if ( tl.size() != 2 ) {
2754                 return false;
2755             }
2756             final BasicTable<String> t3 = tl.get( 0 );
2757             final BasicTable<String> t4 = tl.get( 1 );
2758             if ( t3.getNumberOfColumns() != 4 ) {
2759                 return false;
2760             }
2761             if ( t3.getNumberOfRows() != 3 ) {
2762                 return false;
2763             }
2764             if ( t4.getNumberOfColumns() != 4 ) {
2765                 return false;
2766             }
2767             if ( t4.getNumberOfRows() != 3 ) {
2768                 return false;
2769             }
2770             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2771                 return false;
2772             }
2773             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2774                 return false;
2775             }
2776         }
2777         catch ( final Exception e ) {
2778             e.printStackTrace( System.out );
2779             return false;
2780         }
2781         return true;
2782     }
2783
2784     private static boolean testBasicTolXMLparsing() {
2785         try {
2786             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2787             final TolParser parser = new TolParser();
2788             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2789             if ( parser.getErrorCount() > 0 ) {
2790                 System.out.println( parser.getErrorMessages().toString() );
2791                 return false;
2792             }
2793             if ( phylogenies_0.length != 1 ) {
2794                 return false;
2795             }
2796             final Phylogeny t1 = phylogenies_0[ 0 ];
2797             if ( t1.getNumberOfExternalNodes() != 5 ) {
2798                 return false;
2799             }
2800             if ( !t1.isRooted() ) {
2801                 return false;
2802             }
2803             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2804                 return false;
2805             }
2806             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2807                 return false;
2808             }
2809             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2810                 return false;
2811             }
2812             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2813                 return false;
2814             }
2815             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2816             if ( parser.getErrorCount() > 0 ) {
2817                 System.out.println( parser.getErrorMessages().toString() );
2818                 return false;
2819             }
2820             if ( phylogenies_1.length != 1 ) {
2821                 return false;
2822             }
2823             final Phylogeny t2 = phylogenies_1[ 0 ];
2824             if ( t2.getNumberOfExternalNodes() != 664 ) {
2825                 return false;
2826             }
2827             if ( !t2.isRooted() ) {
2828                 return false;
2829             }
2830             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2831                 return false;
2832             }
2833             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2834                 return false;
2835             }
2836             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2837                 return false;
2838             }
2839             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2840                 return false;
2841             }
2842             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2843                 return false;
2844             }
2845             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2846                     .equals( "Aquifex" ) ) {
2847                 return false;
2848             }
2849             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2850             if ( parser.getErrorCount() > 0 ) {
2851                 System.out.println( parser.getErrorMessages().toString() );
2852                 return false;
2853             }
2854             if ( phylogenies_2.length != 1 ) {
2855                 return false;
2856             }
2857             final Phylogeny t3 = phylogenies_2[ 0 ];
2858             if ( t3.getNumberOfExternalNodes() != 184 ) {
2859                 return false;
2860             }
2861             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2862                 return false;
2863             }
2864             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2865                 return false;
2866             }
2867             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2868                 return false;
2869             }
2870             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2871             if ( parser.getErrorCount() > 0 ) {
2872                 System.out.println( parser.getErrorMessages().toString() );
2873                 return false;
2874             }
2875             if ( phylogenies_3.length != 1 ) {
2876                 return false;
2877             }
2878             final Phylogeny t4 = phylogenies_3[ 0 ];
2879             if ( t4.getNumberOfExternalNodes() != 1 ) {
2880                 return false;
2881             }
2882             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2883                 return false;
2884             }
2885             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2886                 return false;
2887             }
2888             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2889                 return false;
2890             }
2891             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2892             if ( parser.getErrorCount() > 0 ) {
2893                 System.out.println( parser.getErrorMessages().toString() );
2894                 return false;
2895             }
2896             if ( phylogenies_4.length != 1 ) {
2897                 return false;
2898             }
2899             final Phylogeny t5 = phylogenies_4[ 0 ];
2900             if ( t5.getNumberOfExternalNodes() != 13 ) {
2901                 return false;
2902             }
2903             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2904                 return false;
2905             }
2906             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2907                 return false;
2908             }
2909             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2910                 return false;
2911             }
2912         }
2913         catch ( final Exception e ) {
2914             e.printStackTrace( System.out );
2915             return false;
2916         }
2917         return true;
2918     }
2919
2920     private static boolean testBasicTreeMethods() {
2921         try {
2922             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2923             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2924             if ( t2.getNumberOfExternalNodes() != 4 ) {
2925                 return false;
2926             }
2927             if ( t2.getHeight() != 8.5 ) {
2928                 return false;
2929             }
2930             if ( !t2.isCompletelyBinary() ) {
2931                 return false;
2932             }
2933             if ( t2.isEmpty() ) {
2934                 return false;
2935             }
2936             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2937             if ( t3.getNumberOfExternalNodes() != 5 ) {
2938                 return false;
2939             }
2940             if ( t3.getHeight() != 11 ) {
2941                 return false;
2942             }
2943             if ( t3.isCompletelyBinary() ) {
2944                 return false;
2945             }
2946             final PhylogenyNode n = t3.getNode( "ABC" );
2947             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 ];
2948             if ( t4.getNumberOfExternalNodes() != 9 ) {
2949                 return false;
2950             }
2951             if ( t4.getHeight() != 11 ) {
2952                 return false;
2953             }
2954             if ( t4.isCompletelyBinary() ) {
2955                 return false;
2956             }
2957             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)" );
2958             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2959             if ( t5.getNumberOfExternalNodes() != 8 ) {
2960                 return false;
2961             }
2962             if ( t5.getHeight() != 15 ) {
2963                 return false;
2964             }
2965             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)" );
2966             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2967             if ( t6.getHeight() != 15 ) {
2968                 return false;
2969             }
2970             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)" );
2971             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2972             if ( t7.getHeight() != 15 ) {
2973                 return false;
2974             }
2975             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)" );
2976             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2977             if ( t8.getNumberOfExternalNodes() != 10 ) {
2978                 return false;
2979             }
2980             if ( t8.getHeight() != 15 ) {
2981                 return false;
2982             }
2983             final char[] a9 = new char[] { 'a' };
2984             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2985             if ( t9.getHeight() != 0 ) {
2986                 return false;
2987             }
2988             final char[] a10 = new char[] { 'a', ':', '6' };
2989             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2990             if ( t10.getHeight() != 6 ) {
2991                 return false;
2992             }
2993         }
2994         catch ( final Exception e ) {
2995             e.printStackTrace( System.out );
2996             return false;
2997         }
2998         return true;
2999     }
3000
3001     private static boolean testConfidenceAssessor() {
3002         try {
3003             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3004             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3005             final Phylogeny[] ev0 = factory
3006                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3007                              new NHXParser() );
3008             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3009             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3010                 return false;
3011             }
3012             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3013                 return false;
3014             }
3015             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3016             final Phylogeny[] ev1 = factory
3017                     .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)));",
3018                              new NHXParser() );
3019             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3020             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3021                 return false;
3022             }
3023             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3024                 return false;
3025             }
3026             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3027             final Phylogeny[] ev_b = factory
3028                     .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",
3029                              new NHXParser() );
3030             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3031             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3032                 return false;
3033             }
3034             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3035                 return false;
3036             }
3037             //
3038             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3039             final Phylogeny[] ev1x = factory
3040                     .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)));",
3041                              new NHXParser() );
3042             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3043             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3044                 return false;
3045             }
3046             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3047                 return false;
3048             }
3049             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3050             final Phylogeny[] ev_bx = factory
3051                     .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",
3052                              new NHXParser() );
3053             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3054             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3055                 return false;
3056             }
3057             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3058                 return false;
3059             }
3060             final Phylogeny[] t2 = factory
3061                     .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);",
3062                              new NHXParser() );
3063             final Phylogeny[] ev2 = factory
3064                     .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);",
3065                              new NHXParser() );
3066             for( final Phylogeny target : t2 ) {
3067                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3068             }
3069             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3070                                                  new NHXParser() )[ 0 ];
3071             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3072             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3073             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3074                 return false;
3075             }
3076             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3077                 return false;
3078             }
3079             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3080                 return false;
3081             }
3082         }
3083         catch ( final Exception e ) {
3084             e.printStackTrace();
3085             return false;
3086         }
3087         return true;
3088     }
3089
3090     private static boolean testCopyOfNodeData() {
3091         try {
3092             final PhylogenyNode n1 = PhylogenyNode
3093                     .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]" );
3094             final PhylogenyNode n2 = n1.copyNodeData();
3095             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3096                 return false;
3097             }
3098         }
3099         catch ( final Exception e ) {
3100             e.printStackTrace();
3101             return false;
3102         }
3103         return true;
3104     }
3105
3106     private static boolean testCreateBalancedPhylogeny() {
3107         try {
3108             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3109             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3110                 return false;
3111             }
3112             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3113                 return false;
3114             }
3115             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3116             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3117                 return false;
3118             }
3119             if ( p1.getNumberOfExternalNodes() != 100 ) {
3120                 return false;
3121             }
3122         }
3123         catch ( final Exception e ) {
3124             e.printStackTrace();
3125             return false;
3126         }
3127         return true;
3128     }
3129
3130     private static boolean testCreateUriForSeqWeb() {
3131         try {
3132             final PhylogenyNode n = new PhylogenyNode();
3133             n.setName( "tr|B3RJ64" );
3134             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3135                 return false;
3136             }
3137             n.setName( "B0LM41_HUMAN" );
3138             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3139                 return false;
3140             }
3141             n.setName( "NP_001025424" );
3142             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3143                 return false;
3144             }
3145             n.setName( "_NM_001030253-" );
3146             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3147                 return false;
3148             }
3149             n.setName( "XM_002122186" );
3150             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3151                 return false;
3152             }
3153             n.setName( "dgh_AAA34956_gdg" );
3154             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3155                 return false;
3156             }
3157             n.setName( "AAA34956" );
3158             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3159                 return false;
3160             }
3161             n.setName( "GI:394892" );
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( "gi_394892" );
3167             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3168                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3169                 return false;
3170             }
3171             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3172             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3173                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3174                 return false;
3175             }
3176             n.setName( "P12345" );
3177             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3178                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3179                 return false;
3180             }
3181             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3182             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3183                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3184                 return false;
3185             }
3186         }
3187         catch ( final Exception e ) {
3188             e.printStackTrace( System.out );
3189             return false;
3190         }
3191         return true;
3192     }
3193
3194     private static boolean testDataObjects() {
3195         try {
3196             final Confidence s0 = new Confidence();
3197             final Confidence s1 = new Confidence();
3198             if ( !s0.isEqual( s1 ) ) {
3199                 return false;
3200             }
3201             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3202             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3203             if ( s2.isEqual( s1 ) ) {
3204                 return false;
3205             }
3206             if ( !s2.isEqual( s3 ) ) {
3207                 return false;
3208             }
3209             final Confidence s4 = ( Confidence ) s3.copy();
3210             if ( !s4.isEqual( s3 ) ) {
3211                 return false;
3212             }
3213             s3.asSimpleText();
3214             s3.asText();
3215             // Taxonomy
3216             // ----------
3217             final Taxonomy t1 = new Taxonomy();
3218             final Taxonomy t2 = new Taxonomy();
3219             final Taxonomy t3 = new Taxonomy();
3220             final Taxonomy t4 = new Taxonomy();
3221             final Taxonomy t5 = new Taxonomy();
3222             t1.setIdentifier( new Identifier( "ecoli" ) );
3223             t1.setTaxonomyCode( "ECOLI" );
3224             t1.setScientificName( "E. coli" );
3225             t1.setCommonName( "coli" );
3226             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3227             if ( !t1.isEqual( t0 ) ) {
3228                 return false;
3229             }
3230             t2.setIdentifier( new Identifier( "ecoli" ) );
3231             t2.setTaxonomyCode( "OTHER" );
3232             t2.setScientificName( "what" );
3233             t2.setCommonName( "something" );
3234             if ( !t1.isEqual( t2 ) ) {
3235                 return false;
3236             }
3237             t2.setIdentifier( new Identifier( "nemve" ) );
3238             if ( t1.isEqual( t2 ) ) {
3239                 return false;
3240             }
3241             t1.setIdentifier( null );
3242             t3.setTaxonomyCode( "ECOLI" );
3243             t3.setScientificName( "what" );
3244             t3.setCommonName( "something" );
3245             if ( !t1.isEqual( t3 ) ) {
3246                 return false;
3247             }
3248             t1.setIdentifier( null );
3249             t1.setTaxonomyCode( "" );
3250             t4.setScientificName( "E. ColI" );
3251             t4.setCommonName( "something" );
3252             if ( !t1.isEqual( t4 ) ) {
3253                 return false;
3254             }
3255             t4.setScientificName( "B. subtilis" );
3256             t4.setCommonName( "something" );
3257             if ( t1.isEqual( t4 ) ) {
3258                 return false;
3259             }
3260             t1.setIdentifier( null );
3261             t1.setTaxonomyCode( "" );
3262             t1.setScientificName( "" );
3263             t5.setCommonName( "COLI" );
3264             if ( !t1.isEqual( t5 ) ) {
3265                 return false;
3266             }
3267             t5.setCommonName( "vibrio" );
3268             if ( t1.isEqual( t5 ) ) {
3269                 return false;
3270             }
3271             // Identifier
3272             // ----------
3273             final Identifier id0 = new Identifier( "123", "pfam" );
3274             final Identifier id1 = ( Identifier ) id0.copy();
3275             if ( !id1.isEqual( id1 ) ) {
3276                 return false;
3277             }
3278             if ( !id1.isEqual( id0 ) ) {
3279                 return false;
3280             }
3281             if ( !id0.isEqual( id1 ) ) {
3282                 return false;
3283             }
3284             id1.asSimpleText();
3285             id1.asText();
3286             // ProteinDomain
3287             // ---------------
3288             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3289             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3290             if ( !pd1.isEqual( pd1 ) ) {
3291                 return false;
3292             }
3293             if ( !pd1.isEqual( pd0 ) ) {
3294                 return false;
3295             }
3296             pd1.asSimpleText();
3297             pd1.asText();
3298             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3299             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3300             if ( !pd3.isEqual( pd3 ) ) {
3301                 return false;
3302             }
3303             if ( !pd2.isEqual( pd3 ) ) {
3304                 return false;
3305             }
3306             if ( !pd0.isEqual( pd3 ) ) {
3307                 return false;
3308             }
3309             pd3.asSimpleText();
3310             pd3.asText();
3311             // DomainArchitecture
3312             // ------------------
3313             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3314             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3315             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3316             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3317             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3318             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3319             domains0.add( d2 );
3320             domains0.add( d0 );
3321             domains0.add( d3 );
3322             domains0.add( d1 );
3323             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3324             if ( ds0.getNumberOfDomains() != 4 ) {
3325                 return false;
3326             }
3327             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3328             if ( !ds0.isEqual( ds0 ) ) {
3329                 return false;
3330             }
3331             if ( !ds0.isEqual( ds1 ) ) {
3332                 return false;
3333             }
3334             if ( ds1.getNumberOfDomains() != 4 ) {
3335                 return false;
3336             }
3337             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3338             domains1.add( d1 );
3339             domains1.add( d2 );
3340             domains1.add( d4 );
3341             domains1.add( d0 );
3342             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3343             if ( ds0.isEqual( ds2 ) ) {
3344                 return false;
3345             }
3346             ds1.asSimpleText();
3347             ds1.asText();
3348             ds1.toNHX();
3349             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3350             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3351                 System.out.println( ds3.toNHX() );
3352                 return false;
3353             }
3354             if ( ds3.getNumberOfDomains() != 3 ) {
3355                 return false;
3356             }
3357             // Event
3358             // -----
3359             final Event e1 = new Event( Event.EventType.fusion );
3360             if ( e1.isDuplication() ) {
3361                 return false;
3362             }
3363             if ( !e1.isFusion() ) {
3364                 return false;
3365             }
3366             if ( !e1.asText().toString().equals( "fusion" ) ) {
3367                 return false;
3368             }
3369             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3370                 return false;
3371             }
3372             final Event e11 = new Event( Event.EventType.fusion );
3373             if ( !e11.isEqual( e1 ) ) {
3374                 return false;
3375             }
3376             if ( !e11.toNHX().toString().equals( "" ) ) {
3377                 return false;
3378             }
3379             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3380             if ( e2.isDuplication() ) {
3381                 return false;
3382             }
3383             if ( !e2.isSpeciationOrDuplication() ) {
3384                 return false;
3385             }
3386             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3387                 return false;
3388             }
3389             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3390                 return false;
3391             }
3392             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3393                 return false;
3394             }
3395             if ( e11.isEqual( e2 ) ) {
3396                 return false;
3397             }
3398             final Event e2c = ( Event ) e2.copy();
3399             if ( !e2c.isEqual( e2 ) ) {
3400                 return false;
3401             }
3402             Event e3 = new Event( 1, 2, 3 );
3403             if ( e3.isDuplication() ) {
3404                 return false;
3405             }
3406             if ( e3.isSpeciation() ) {
3407                 return false;
3408             }
3409             if ( e3.isGeneLoss() ) {
3410                 return false;
3411             }
3412             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3413                 return false;
3414             }
3415             final Event e3c = ( Event ) e3.copy();
3416             final Event e3cc = ( Event ) e3c.copy();
3417             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3418                 return false;
3419             }
3420             e3 = null;
3421             if ( !e3c.isEqual( e3cc ) ) {
3422                 return false;
3423             }
3424             Event e4 = new Event( 1, 2, 3 );
3425             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3426                 return false;
3427             }
3428             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3429                 return false;
3430             }
3431             final Event e4c = ( Event ) e4.copy();
3432             e4 = null;
3433             final Event e4cc = ( Event ) e4c.copy();
3434             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3435                 return false;
3436             }
3437             if ( !e4c.isEqual( e4cc ) ) {
3438                 return false;
3439             }
3440             final Event e5 = new Event();
3441             if ( !e5.isUnassigned() ) {
3442                 return false;
3443             }
3444             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3445                 return false;
3446             }
3447             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3448                 return false;
3449             }
3450             final Event e6 = new Event( 1, 0, 0 );
3451             if ( !e6.asText().toString().equals( "duplication" ) ) {
3452                 return false;
3453             }
3454             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3455                 return false;
3456             }
3457             final Event e7 = new Event( 0, 1, 0 );
3458             if ( !e7.asText().toString().equals( "speciation" ) ) {
3459                 return false;
3460             }
3461             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3462                 return false;
3463             }
3464             final Event e8 = new Event( 0, 0, 1 );
3465             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3466                 return false;
3467             }
3468             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3469                 return false;
3470             }
3471         }
3472         catch ( final Exception e ) {
3473             e.printStackTrace( System.out );
3474             return false;
3475         }
3476         return true;
3477     }
3478
3479     private static boolean testDeletionOfExternalNodes() {
3480         try {
3481             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3482             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3483             final PhylogenyWriter w = new PhylogenyWriter();
3484             if ( t0.isEmpty() ) {
3485                 return false;
3486             }
3487             if ( t0.getNumberOfExternalNodes() != 1 ) {
3488                 return false;
3489             }
3490             t0.deleteSubtree( t0.getNode( "A" ), false );
3491             if ( t0.getNumberOfExternalNodes() != 0 ) {
3492                 return false;
3493             }
3494             if ( !t0.isEmpty() ) {
3495                 return false;
3496             }
3497             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3498             if ( t1.getNumberOfExternalNodes() != 2 ) {
3499                 return false;
3500             }
3501             t1.deleteSubtree( t1.getNode( "A" ), false );
3502             if ( t1.getNumberOfExternalNodes() != 1 ) {
3503                 return false;
3504             }
3505             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3506                 return false;
3507             }
3508             t1.deleteSubtree( t1.getNode( "B" ), false );
3509             if ( t1.getNumberOfExternalNodes() != 1 ) {
3510                 return false;
3511             }
3512             t1.deleteSubtree( t1.getNode( "r" ), false );
3513             if ( !t1.isEmpty() ) {
3514                 return false;
3515             }
3516             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3517             if ( t2.getNumberOfExternalNodes() != 3 ) {
3518                 return false;
3519             }
3520             t2.deleteSubtree( t2.getNode( "B" ), false );
3521             if ( t2.getNumberOfExternalNodes() != 2 ) {
3522                 return false;
3523             }
3524             t2.toNewHampshireX();
3525             PhylogenyNode n = t2.getNode( "A" );
3526             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3527                 return false;
3528             }
3529             t2.deleteSubtree( t2.getNode( "A" ), false );
3530             if ( t2.getNumberOfExternalNodes() != 2 ) {
3531                 return false;
3532             }
3533             t2.deleteSubtree( t2.getNode( "C" ), true );
3534             if ( t2.getNumberOfExternalNodes() != 1 ) {
3535                 return false;
3536             }
3537             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3538             if ( t3.getNumberOfExternalNodes() != 4 ) {
3539                 return false;
3540             }
3541             t3.deleteSubtree( t3.getNode( "B" ), true );
3542             if ( t3.getNumberOfExternalNodes() != 3 ) {
3543                 return false;
3544             }
3545             n = t3.getNode( "A" );
3546             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3547                 return false;
3548             }
3549             n = n.getNextExternalNode();
3550             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3551                 return false;
3552             }
3553             t3.deleteSubtree( t3.getNode( "A" ), true );
3554             if ( t3.getNumberOfExternalNodes() != 2 ) {
3555                 return false;
3556             }
3557             n = t3.getNode( "C" );
3558             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3559                 return false;
3560             }
3561             t3.deleteSubtree( t3.getNode( "C" ), true );
3562             if ( t3.getNumberOfExternalNodes() != 1 ) {
3563                 return false;
3564             }
3565             t3.deleteSubtree( t3.getNode( "D" ), true );
3566             if ( t3.getNumberOfExternalNodes() != 0 ) {
3567                 return false;
3568             }
3569             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3570             if ( t4.getNumberOfExternalNodes() != 6 ) {
3571                 return false;
3572             }
3573             t4.deleteSubtree( t4.getNode( "B2" ), true );
3574             if ( t4.getNumberOfExternalNodes() != 5 ) {
3575                 return false;
3576             }
3577             String s = w.toNewHampshire( t4, true ).toString();
3578             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3579                 return false;
3580             }
3581             t4.deleteSubtree( t4.getNode( "B11" ), true );
3582             if ( t4.getNumberOfExternalNodes() != 4 ) {
3583                 return false;
3584             }
3585             t4.deleteSubtree( t4.getNode( "C" ), true );
3586             if ( t4.getNumberOfExternalNodes() != 3 ) {
3587                 return false;
3588             }
3589             n = t4.getNode( "A" );
3590             n = n.getNextExternalNode();
3591             if ( !n.getName().equals( "B12" ) ) {
3592                 return false;
3593             }
3594             n = n.getNextExternalNode();
3595             if ( !n.getName().equals( "D" ) ) {
3596                 return false;
3597             }
3598             s = w.toNewHampshire( t4, true ).toString();
3599             if ( !s.equals( "((A,B12),D);" ) ) {
3600                 return false;
3601             }
3602             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3603             t5.deleteSubtree( t5.getNode( "A" ), true );
3604             if ( t5.getNumberOfExternalNodes() != 5 ) {
3605                 return false;
3606             }
3607             s = w.toNewHampshire( t5, true ).toString();
3608             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3609                 return false;
3610             }
3611             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3612             t6.deleteSubtree( t6.getNode( "B11" ), true );
3613             if ( t6.getNumberOfExternalNodes() != 5 ) {
3614                 return false;
3615             }
3616             s = w.toNewHampshire( t6, false ).toString();
3617             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3618                 return false;
3619             }
3620             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3621             t7.deleteSubtree( t7.getNode( "B12" ), true );
3622             if ( t7.getNumberOfExternalNodes() != 5 ) {
3623                 return false;
3624             }
3625             s = w.toNewHampshire( t7, true ).toString();
3626             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3627                 return false;
3628             }
3629             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3630             t8.deleteSubtree( t8.getNode( "B2" ), true );
3631             if ( t8.getNumberOfExternalNodes() != 5 ) {
3632                 return false;
3633             }
3634             s = w.toNewHampshire( t8, false ).toString();
3635             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3636                 return false;
3637             }
3638             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3639             t9.deleteSubtree( t9.getNode( "C" ), true );
3640             if ( t9.getNumberOfExternalNodes() != 5 ) {
3641                 return false;
3642             }
3643             s = w.toNewHampshire( t9, true ).toString();
3644             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3645                 return false;
3646             }
3647             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3648             t10.deleteSubtree( t10.getNode( "D" ), true );
3649             if ( t10.getNumberOfExternalNodes() != 5 ) {
3650                 return false;
3651             }
3652             s = w.toNewHampshire( t10, true ).toString();
3653             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3654                 return false;
3655             }
3656             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3657             t11.deleteSubtree( t11.getNode( "A" ), true );
3658             if ( t11.getNumberOfExternalNodes() != 2 ) {
3659                 return false;
3660             }
3661             s = w.toNewHampshire( t11, true ).toString();
3662             if ( !s.equals( "(B,C);" ) ) {
3663                 return false;
3664             }
3665             t11.deleteSubtree( t11.getNode( "C" ), true );
3666             if ( t11.getNumberOfExternalNodes() != 1 ) {
3667                 return false;
3668             }
3669             s = w.toNewHampshire( t11, false ).toString();
3670             if ( !s.equals( "B;" ) ) {
3671                 return false;
3672             }
3673             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3674             t12.deleteSubtree( t12.getNode( "B2" ), true );
3675             if ( t12.getNumberOfExternalNodes() != 8 ) {
3676                 return false;
3677             }
3678             s = w.toNewHampshire( t12, true ).toString();
3679             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3680                 return false;
3681             }
3682             t12.deleteSubtree( t12.getNode( "B3" ), true );
3683             if ( t12.getNumberOfExternalNodes() != 7 ) {
3684                 return false;
3685             }
3686             s = w.toNewHampshire( t12, true ).toString();
3687             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3688                 return false;
3689             }
3690             t12.deleteSubtree( t12.getNode( "C3" ), true );
3691             if ( t12.getNumberOfExternalNodes() != 6 ) {
3692                 return false;
3693             }
3694             s = w.toNewHampshire( t12, true ).toString();
3695             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3696                 return false;
3697             }
3698             t12.deleteSubtree( t12.getNode( "A1" ), true );
3699             if ( t12.getNumberOfExternalNodes() != 5 ) {
3700                 return false;
3701             }
3702             s = w.toNewHampshire( t12, true ).toString();
3703             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3704                 return false;
3705             }
3706             t12.deleteSubtree( t12.getNode( "B1" ), true );
3707             if ( t12.getNumberOfExternalNodes() != 4 ) {
3708                 return false;
3709             }
3710             s = w.toNewHampshire( t12, true ).toString();
3711             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3712                 return false;
3713             }
3714             t12.deleteSubtree( t12.getNode( "A3" ), true );
3715             if ( t12.getNumberOfExternalNodes() != 3 ) {
3716                 return false;
3717             }
3718             s = w.toNewHampshire( t12, true ).toString();
3719             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3720                 return false;
3721             }
3722             t12.deleteSubtree( t12.getNode( "A2" ), true );
3723             if ( t12.getNumberOfExternalNodes() != 2 ) {
3724                 return false;
3725             }
3726             s = w.toNewHampshire( t12, true ).toString();
3727             if ( !s.equals( "(C1,C2);" ) ) {
3728                 return false;
3729             }
3730             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3731             t13.deleteSubtree( t13.getNode( "D" ), true );
3732             if ( t13.getNumberOfExternalNodes() != 4 ) {
3733                 return false;
3734             }
3735             s = w.toNewHampshire( t13, true ).toString();
3736             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3737                 return false;
3738             }
3739             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3740             t14.deleteSubtree( t14.getNode( "E" ), true );
3741             if ( t14.getNumberOfExternalNodes() != 5 ) {
3742                 return false;
3743             }
3744             s = w.toNewHampshire( t14, true ).toString();
3745             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3746                 return false;
3747             }
3748             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3749             t15.deleteSubtree( t15.getNode( "B2" ), true );
3750             if ( t15.getNumberOfExternalNodes() != 11 ) {
3751                 return false;
3752             }
3753             t15.deleteSubtree( t15.getNode( "B1" ), true );
3754             if ( t15.getNumberOfExternalNodes() != 10 ) {
3755                 return false;
3756             }
3757             t15.deleteSubtree( t15.getNode( "B3" ), true );
3758             if ( t15.getNumberOfExternalNodes() != 9 ) {
3759                 return false;
3760             }
3761             t15.deleteSubtree( t15.getNode( "B4" ), true );
3762             if ( t15.getNumberOfExternalNodes() != 8 ) {
3763                 return false;
3764             }
3765             t15.deleteSubtree( t15.getNode( "A1" ), true );
3766             if ( t15.getNumberOfExternalNodes() != 7 ) {
3767                 return false;
3768             }
3769             t15.deleteSubtree( t15.getNode( "C4" ), true );
3770             if ( t15.getNumberOfExternalNodes() != 6 ) {
3771                 return false;
3772             }
3773         }
3774         catch ( final Exception e ) {
3775             e.printStackTrace( System.out );
3776             return false;
3777         }
3778         return true;
3779     }
3780
3781     private static boolean testDescriptiveStatistics() {
3782         try {
3783             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3784             dss1.addValue( 82 );
3785             dss1.addValue( 78 );
3786             dss1.addValue( 70 );
3787             dss1.addValue( 58 );
3788             dss1.addValue( 42 );
3789             if ( dss1.getN() != 5 ) {
3790                 return false;
3791             }
3792             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3793                 return false;
3794             }
3795             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3796                 return false;
3797             }
3798             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3799                 return false;
3800             }
3801             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3802                 return false;
3803             }
3804             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3805                 return false;
3806             }
3807             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3808                 return false;
3809             }
3810             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3811                 return false;
3812             }
3813             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3814                 return false;
3815             }
3816             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3817                 return false;
3818             }
3819             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3820                 return false;
3821             }
3822             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3823                 return false;
3824             }
3825             dss1.addValue( 123 );
3826             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3827                 return false;
3828             }
3829             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3830                 return false;
3831             }
3832             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3833                 return false;
3834             }
3835             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3836             dss2.addValue( -1.85 );
3837             dss2.addValue( 57.5 );
3838             dss2.addValue( 92.78 );
3839             dss2.addValue( 57.78 );
3840             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3841                 return false;
3842             }
3843             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3844                 return false;
3845             }
3846             final double[] a = dss2.getDataAsDoubleArray();
3847             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3848                 return false;
3849             }
3850             dss2.addValue( -100 );
3851             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3852                 return false;
3853             }
3854             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3855                 return false;
3856             }
3857             final double[] ds = new double[ 14 ];
3858             ds[ 0 ] = 34;
3859             ds[ 1 ] = 23;
3860             ds[ 2 ] = 1;
3861             ds[ 3 ] = 32;
3862             ds[ 4 ] = 11;
3863             ds[ 5 ] = 2;
3864             ds[ 6 ] = 12;
3865             ds[ 7 ] = 33;
3866             ds[ 8 ] = 13;
3867             ds[ 9 ] = 22;
3868             ds[ 10 ] = 21;
3869             ds[ 11 ] = 35;
3870             ds[ 12 ] = 24;
3871             ds[ 13 ] = 31;
3872             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3873             if ( bins.length != 4 ) {
3874                 return false;
3875             }
3876             if ( bins[ 0 ] != 2 ) {
3877                 return false;
3878             }
3879             if ( bins[ 1 ] != 3 ) {
3880                 return false;
3881             }
3882             if ( bins[ 2 ] != 4 ) {
3883                 return false;
3884             }
3885             if ( bins[ 3 ] != 5 ) {
3886                 return false;
3887             }
3888             final double[] ds1 = new double[ 9 ];
3889             ds1[ 0 ] = 10.0;
3890             ds1[ 1 ] = 19.0;
3891             ds1[ 2 ] = 9.999;
3892             ds1[ 3 ] = 0.0;
3893             ds1[ 4 ] = 39.9;
3894             ds1[ 5 ] = 39.999;
3895             ds1[ 6 ] = 30.0;
3896             ds1[ 7 ] = 19.999;
3897             ds1[ 8 ] = 30.1;
3898             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3899             if ( bins1.length != 4 ) {
3900                 return false;
3901             }
3902             if ( bins1[ 0 ] != 2 ) {
3903                 return false;
3904             }
3905             if ( bins1[ 1 ] != 3 ) {
3906                 return false;
3907             }
3908             if ( bins1[ 2 ] != 0 ) {
3909                 return false;
3910             }
3911             if ( bins1[ 3 ] != 4 ) {
3912                 return false;
3913             }
3914             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3915             if ( bins1_1.length != 3 ) {
3916                 return false;
3917             }
3918             if ( bins1_1[ 0 ] != 3 ) {
3919                 return false;
3920             }
3921             if ( bins1_1[ 1 ] != 2 ) {
3922                 return false;
3923             }
3924             if ( bins1_1[ 2 ] != 4 ) {
3925                 return false;
3926             }
3927             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3928             if ( bins1_2.length != 3 ) {
3929                 return false;
3930             }
3931             if ( bins1_2[ 0 ] != 2 ) {
3932                 return false;
3933             }
3934             if ( bins1_2[ 1 ] != 2 ) {
3935                 return false;
3936             }
3937             if ( bins1_2[ 2 ] != 2 ) {
3938                 return false;
3939             }
3940             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3941             dss3.addValue( 1 );
3942             dss3.addValue( 1 );
3943             dss3.addValue( 1 );
3944             dss3.addValue( 2 );
3945             dss3.addValue( 3 );
3946             dss3.addValue( 4 );
3947             dss3.addValue( 5 );
3948             dss3.addValue( 5 );
3949             dss3.addValue( 5 );
3950             dss3.addValue( 6 );
3951             dss3.addValue( 7 );
3952             dss3.addValue( 8 );
3953             dss3.addValue( 9 );
3954             dss3.addValue( 10 );
3955             dss3.addValue( 10 );
3956             dss3.addValue( 10 );
3957             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3958             histo.toStringBuffer( 10, '=', 40, 5 );
3959             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3960         }
3961         catch ( final Exception e ) {
3962             e.printStackTrace( System.out );
3963             return false;
3964         }
3965         return true;
3966     }
3967
3968     private static boolean testDir( final String file ) {
3969         try {
3970             final File f = new File( file );
3971             if ( !f.exists() ) {
3972                 return false;
3973             }
3974             if ( !f.isDirectory() ) {
3975                 return false;
3976             }
3977             if ( !f.canRead() ) {
3978                 return false;
3979             }
3980         }
3981         catch ( final Exception e ) {
3982             return false;
3983         }
3984         return true;
3985     }
3986
3987     private static boolean testEbiEntryRetrieval() {
3988         try {
3989             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3990             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3991                 System.out.println( entry.getAccession() );
3992                 return false;
3993             }
3994             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3995                 System.out.println( entry.getTaxonomyScientificName() );
3996                 return false;
3997             }
3998             if ( !entry.getSequenceName()
3999                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4000                 System.out.println( entry.getSequenceName() );
4001                 return false;
4002             }
4003             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4004                 System.out.println( entry.getGeneName() );
4005                 return false;
4006             }
4007             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4008                 System.out.println( entry.getTaxonomyIdentifier() );
4009                 return false;
4010             }
4011             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4012                 System.out.println( entry.getAnnotations().first().getRefValue() );
4013                 return false;
4014             }
4015             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4016                 System.out.println( entry.getAnnotations().first().getRefSource() );
4017                 return false;
4018             }
4019             if ( entry.getCrossReferences().size() != 5 ) {
4020                 return false;
4021             }
4022             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4023             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4024                 return false;
4025             }
4026             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4027                 System.out.println( entry1.getTaxonomyScientificName() );
4028                 return false;
4029             }
4030             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4031                 System.out.println( entry1.getSequenceName() );
4032                 return false;
4033             }
4034             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4035                 System.out.println( entry1.getTaxonomyIdentifier() );
4036                 return false;
4037             }
4038             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4039                 System.out.println( entry1.getGeneName() );
4040                 return false;
4041             }
4042             if ( entry1.getCrossReferences().size() != 6 ) {
4043                 return false;
4044             }
4045             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4046             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4047                 return false;
4048             }
4049             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4050                 System.out.println( entry2.getTaxonomyScientificName() );
4051                 return false;
4052             }
4053             if ( !entry2.getSequenceName()
4054                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4055                 System.out.println( entry2.getSequenceName() );
4056                 return false;
4057             }
4058             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4059                 System.out.println( entry2.getTaxonomyIdentifier() );
4060                 return false;
4061             }
4062             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4063                 System.out.println( entry2.getGeneName() );
4064                 return false;
4065             }
4066             if ( entry2.getCrossReferences().size() != 3 ) {
4067                 return false;
4068             }
4069             //
4070             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4071             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4072                 return false;
4073             }
4074             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4075                 System.out.println( entry3.getTaxonomyScientificName() );
4076                 return false;
4077             }
4078             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4079                 System.out.println( entry3.getSequenceName() );
4080                 return false;
4081             }
4082             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4083                 System.out.println( entry3.getTaxonomyIdentifier() );
4084                 return false;
4085             }
4086             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4087                 System.out.println( entry3.getSequenceSymbol() );
4088                 return false;
4089             }
4090             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4091                 return false;
4092             }
4093             if ( entry3.getCrossReferences().size() < 7 ) {
4094                 return false;
4095             }
4096             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4097             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4098                 return false;
4099             }
4100             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4101                 System.out.println( entry4.getTaxonomyScientificName() );
4102                 return false;
4103             }
4104             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4105                 System.out.println( entry4.getSequenceName() );
4106                 return false;
4107             }
4108             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4109                 System.out.println( entry4.getTaxonomyIdentifier() );
4110                 return false;
4111             }
4112             if ( !entry4.getGeneName().equals( "ras" ) ) {
4113                 System.out.println( entry4.getGeneName() );
4114                 return false;
4115             }
4116             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4117             //     System.out.println( entry4.getChromosome() );
4118             //     return false;
4119             // }
4120             // if ( !entry4.getMap().equals( "ras" ) ) {
4121             //     System.out.println( entry4.getMap() );
4122             //     return false;
4123             // }
4124             //TODO FIXME gi...
4125             //
4126             //TODO fails:
4127             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4128             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4129             //                return false;
4130             //            }
4131             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4132             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4133                 return false;
4134             }
4135             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4136                 System.out.println( entry5.getTaxonomyScientificName() );
4137                 return false;
4138             }
4139             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4140                 System.out.println( entry5.getSequenceName() );
4141                 return false;
4142             }
4143             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4144                 System.out.println( entry5.getTaxonomyIdentifier() );
4145                 return false;
4146             }
4147         }
4148         catch ( final IOException e ) {
4149             System.out.println();
4150             System.out.println( "the following might be due to absence internet connection:" );
4151             e.printStackTrace( System.out );
4152             return true;
4153         }
4154         catch ( final Exception e ) {
4155             e.printStackTrace();
4156             return false;
4157         }
4158         return true;
4159     }
4160
4161     private static boolean testExternalNodeRelatedMethods() {
4162         try {
4163             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4164             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4165             PhylogenyNode n = t1.getNode( "A" );
4166             n = n.getNextExternalNode();
4167             if ( !n.getName().equals( "B" ) ) {
4168                 return false;
4169             }
4170             n = n.getNextExternalNode();
4171             if ( !n.getName().equals( "C" ) ) {
4172                 return false;
4173             }
4174             n = n.getNextExternalNode();
4175             if ( !n.getName().equals( "D" ) ) {
4176                 return false;
4177             }
4178             n = t1.getNode( "B" );
4179             while ( !n.isLastExternalNode() ) {
4180                 n = n.getNextExternalNode();
4181             }
4182             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4183             n = t2.getNode( "A" );
4184             n = n.getNextExternalNode();
4185             if ( !n.getName().equals( "B" ) ) {
4186                 return false;
4187             }
4188             n = n.getNextExternalNode();
4189             if ( !n.getName().equals( "C" ) ) {
4190                 return false;
4191             }
4192             n = n.getNextExternalNode();
4193             if ( !n.getName().equals( "D" ) ) {
4194                 return false;
4195             }
4196             n = t2.getNode( "B" );
4197             while ( !n.isLastExternalNode() ) {
4198                 n = n.getNextExternalNode();
4199             }
4200             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4201             n = t3.getNode( "A" );
4202             n = n.getNextExternalNode();
4203             if ( !n.getName().equals( "B" ) ) {
4204                 return false;
4205             }
4206             n = n.getNextExternalNode();
4207             if ( !n.getName().equals( "C" ) ) {
4208                 return false;
4209             }
4210             n = n.getNextExternalNode();
4211             if ( !n.getName().equals( "D" ) ) {
4212                 return false;
4213             }
4214             n = n.getNextExternalNode();
4215             if ( !n.getName().equals( "E" ) ) {
4216                 return false;
4217             }
4218             n = n.getNextExternalNode();
4219             if ( !n.getName().equals( "F" ) ) {
4220                 return false;
4221             }
4222             n = n.getNextExternalNode();
4223             if ( !n.getName().equals( "G" ) ) {
4224                 return false;
4225             }
4226             n = n.getNextExternalNode();
4227             if ( !n.getName().equals( "H" ) ) {
4228                 return false;
4229             }
4230             n = t3.getNode( "B" );
4231             while ( !n.isLastExternalNode() ) {
4232                 n = n.getNextExternalNode();
4233             }
4234             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4235             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4236                 final PhylogenyNode node = iter.next();
4237             }
4238             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4239             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4240                 final PhylogenyNode node = iter.next();
4241             }
4242             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4243             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4244             if ( !iter.next().getName().equals( "A" ) ) {
4245                 return false;
4246             }
4247             if ( !iter.next().getName().equals( "B" ) ) {
4248                 return false;
4249             }
4250             if ( !iter.next().getName().equals( "C" ) ) {
4251                 return false;
4252             }
4253             if ( !iter.next().getName().equals( "D" ) ) {
4254                 return false;
4255             }
4256             if ( !iter.next().getName().equals( "E" ) ) {
4257                 return false;
4258             }
4259             if ( !iter.next().getName().equals( "F" ) ) {
4260                 return false;
4261             }
4262             if ( iter.hasNext() ) {
4263                 return false;
4264             }
4265         }
4266         catch ( final Exception e ) {
4267             e.printStackTrace( System.out );
4268             return false;
4269         }
4270         return true;
4271     }
4272
4273     private static boolean testExtractSNFromNodeName() {
4274         try {
4275             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4276                 return false;
4277             }
4278             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4279                 return false;
4280             }
4281             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4282                 return false;
4283             }
4284             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4285                     .equals( "Mus musculus musculus" ) ) {
4286                 return false;
4287             }
4288             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4289                     .equals( "Mus musculus musculus" ) ) {
4290                 return false;
4291             }
4292             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4293                     .equals( "Mus musculus musculus" ) ) {
4294                 return false;
4295             }
4296             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4297                     .equals( "Mus musculus musculus" ) ) {
4298                 return false;
4299             }
4300             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4301                 return false;
4302             }
4303             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4304                     .equals( "Mus musculus musculus" ) ) {
4305                 return false;
4306             }
4307             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4308                     .equals( "Mus musculus musculus" ) ) {
4309                 return false;
4310             }
4311             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4312                 return false;
4313             }
4314             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4315                 return false;
4316             }
4317             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4318                 return false;
4319             }
4320             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4321                 return false;
4322             }
4323             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4324                     .equals( "Mus musculus musculus" ) ) {
4325                 return false;
4326             }
4327             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4328                 return false;
4329             }
4330             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4331                 return false;
4332             }
4333             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4334                 return false;
4335             }
4336             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4337                 return false;
4338             }
4339             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4340                 return false;
4341             }
4342             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4343                 return false;
4344             }
4345             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4346                 return false;
4347             }
4348             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4349                 return false;
4350             }
4351             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4352                     .equals( "Mus musculus" ) ) {
4353                 return false;
4354             }
4355             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4356                     .equals( "Mus musculus" ) ) {
4357                 return false;
4358             }
4359             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4363                     .equals( "Mus musculus musculus" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4367                     .equals( "Mus musculus musculus" ) ) {
4368                 return false;
4369             }
4370             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4371                     .equals( "Mus musculus musculus" ) ) {
4372                 return false;
4373             }
4374             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4375                 return false;
4376             }
4377             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4378                     .equals( "Pilostyles mexicana" ) ) {
4379                 return false;
4380             }
4381             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4382                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4383                 return false;
4384             }
4385             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4386                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4390                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4391                 return false;
4392             }
4393             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4394                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4395                 return false;
4396             }
4397             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4398                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4402                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4403                 return false;
4404             }
4405             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4406                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4410                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4414                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4418                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4422                     .equals( "Escherichia coli (strain K12)" ) ) {
4423                 return false;
4424             }
4425             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4426                     .equals( "Escherichia coli (strain K12)" ) ) {
4427                 return false;
4428             }
4429             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4430                     .equals( "Escherichia coli (str. K12)" ) ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4434                     .equals( "Escherichia coli (str. K12)" ) ) {
4435                 return false;
4436             }
4437             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4438                     .equals( "Escherichia coli (str. K12)" ) ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4442                     .equals( "Escherichia coli (var. K12)" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4446                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4447                 return false;
4448             }
4449             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4450                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4451                 return false;
4452             }
4453             if ( !ParserUtils
4454                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4455                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4459                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4460                 return false;
4461             }
4462             if ( !ParserUtils
4463                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4464                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4465                 return false;
4466             }
4467             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4468                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4469                 return false;
4470             }
4471             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4472                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4473                 return false;
4474             }
4475             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4476                 return false;
4477             }
4478             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4479                 return false;
4480             }
4481             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4485                     .equals( "Macrocera sp." ) ) {
4486                 return false;
4487             }
4488             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4489                 return false;
4490             }
4491             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4492                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4493                 return false;
4494             }
4495             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4496                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4500                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4501                 return false;
4502             }
4503             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4504                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4505                 return false;
4506             }
4507         }
4508         catch ( final Exception e ) {
4509             e.printStackTrace( System.out );
4510             return false;
4511         }
4512         return true;
4513     }
4514
4515     private static boolean testExtractTaxonomyDataFromNodeName() {
4516         try {
4517             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4518             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4519                 return false;
4520             }
4521             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4522             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4523                 return false;
4524             }
4525             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4526             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4527                 return false;
4528             }
4529             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4530             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4531                 return false;
4532             }
4533             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4534             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4535                 return false;
4536             }
4537             n = new PhylogenyNode( "HNRPR_HUMAN" );
4538             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4539                 return false;
4540             }
4541             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4542             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4543                 return false;
4544             }
4545         }
4546         catch ( final Exception e ) {
4547             e.printStackTrace( System.out );
4548             return false;
4549         }
4550         return true;
4551     }
4552
4553     private static boolean testExtractTaxonomyCodeFromNodeName() {
4554         try {
4555             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4556                 return false;
4557             }
4558             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4559                     .equals( "SOYBN" ) ) {
4560                 return false;
4561             }
4562             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4563                     .equals( "ARATH" ) ) {
4564                 return false;
4565             }
4566             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4567                     .equals( "ARATH" ) ) {
4568                 return false;
4569             }
4570             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4571                 return false;
4572             }
4573             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4574                 return false;
4575             }
4576             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4577                 return false;
4578             }
4579             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4580                     .equals( "SOYBN" ) ) {
4581                 return false;
4582             }
4583             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4584                     .equals( "SOYBN" ) ) {
4585                 return false;
4586             }
4587             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4588                     .equals( "SOYBN" ) ) {
4589                 return false;
4590             }
4591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4592                     .equals( "SOYBN" ) ) {
4593                 return false;
4594             }
4595             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4596                     .equals( "SOYBN" ) ) {
4597                 return false;
4598             }
4599             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4600                     .equals( "SOYBN" ) ) {
4601                 return false;
4602             }
4603             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4604                     .equals( "SOYBN" ) ) {
4605                 return false;
4606             }
4607             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4608                     .equals( "SOYBN" ) ) {
4609                 return false;
4610             }
4611             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4612                 return false;
4613             }
4614             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4615                     .equals( "SOYBN" ) ) {
4616                 return false;
4617             }
4618             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4619                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4620                 return false;
4621             }
4622             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4623                     .equals( "9YX45" ) ) {
4624                 return false;
4625             }
4626             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4627                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4628                     .equals( "MOUSE" ) ) {
4629                 return false;
4630             }
4631             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4632                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4633                     .equals( "MOUSE" ) ) {
4634                 return false;
4635             }
4636             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4637                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4638                     .equals( "MOUSE" ) ) {
4639                 return false;
4640             }
4641             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4642                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4643                 return false;
4644             }
4645             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4646                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4647                 return false;
4648             }
4649             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4650                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4651                 return false;
4652             }
4653             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4654                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4655                 return false;
4656             }
4657             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4658                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4659                 return false;
4660             }
4661             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4662                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4663                 return false;
4664             }
4665             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4666                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4667                 return false;
4668             }
4669             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4670                     .equals( "RAT" ) ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4674                     .equals( "PIG" ) ) {
4675                 return false;
4676             }
4677             if ( !ParserUtils
4678                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4679                     .equals( "MOUSE" ) ) {
4680                 return false;
4681             }
4682             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4683                     .equals( "MOUSE" ) ) {
4684                 return false;
4685             }
4686             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4687                 return false;
4688             }
4689         }
4690         catch ( final Exception e ) {
4691             e.printStackTrace( System.out );
4692             return false;
4693         }
4694         return true;
4695     }
4696
4697     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4698         try {
4699             PhylogenyNode n = new PhylogenyNode();
4700             n.setName( "tr|B3RJ64" );
4701             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4702                 return false;
4703             }
4704             n.setName( "tr.B3RJ64" );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4706                 return false;
4707             }
4708             n.setName( "tr=B3RJ64" );
4709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4710                 return false;
4711             }
4712             n.setName( "tr-B3RJ64" );
4713             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4714                 return false;
4715             }
4716             n.setName( "tr/B3RJ64" );
4717             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4718                 return false;
4719             }
4720             n.setName( "tr\\B3RJ64" );
4721             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4722                 return false;
4723             }
4724             n.setName( "tr_B3RJ64" );
4725             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4726                 return false;
4727             }
4728             n.setName( " tr|B3RJ64 " );
4729             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4730                 return false;
4731             }
4732             n.setName( "-tr|B3RJ64-" );
4733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4734                 return false;
4735             }
4736             n.setName( "-tr=B3RJ64-" );
4737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4738                 return false;
4739             }
4740             n.setName( "_tr=B3RJ64_" );
4741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4742                 return false;
4743             }
4744             n.setName( " tr_tr|B3RJ64_sp|123 " );
4745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4746                 return false;
4747             }
4748             n.setName( "B3RJ64" );
4749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4750                 return false;
4751             }
4752             n.setName( "sp|B3RJ64" );
4753             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4754                 return false;
4755             }
4756             n.setName( "sp|B3RJ64C" );
4757             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4758                 return false;
4759             }
4760             n.setName( "sp B3RJ64" );
4761             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4762                 return false;
4763             }
4764             n.setName( "sp|B3RJ6X" );
4765             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4766                 return false;
4767             }
4768             n.setName( "sp|B3RJ6" );
4769             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4770                 return false;
4771             }
4772             n.setName( "K1PYK7_CRAGI" );
4773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4774                 return false;
4775             }
4776             n.setName( "K1PYK7_PEA" );
4777             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4778                 return false;
4779             }
4780             n.setName( "K1PYK7_RAT" );
4781             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4782                 return false;
4783             }
4784             n.setName( "K1PYK7_PIG" );
4785             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4786                 return false;
4787             }
4788             n.setName( "~K1PYK7_PIG~" );
4789             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4790                 return false;
4791             }
4792             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4793             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4794                 return false;
4795             }
4796             n.setName( "K1PYKX_CRAGI" );
4797             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4798                 return false;
4799             }
4800             n.setName( "XXXXX_CRAGI" );
4801             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4802                 return false;
4803             }
4804             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4805             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4806                 return false;
4807             }
4808             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4809             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4810                 return false;
4811             }
4812             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4813             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4814                 return false;
4815             }
4816             n = new PhylogenyNode();
4817             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4818             seq.setSymbol( "K1PYK7_CRAGI" );
4819             n.getNodeData().addSequence( seq );
4820             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4821                 return false;
4822             }
4823             seq.setSymbol( "tr|B3RJ64" );
4824             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4825                 return false;
4826             }
4827             n = new PhylogenyNode();
4828             seq = new org.forester.phylogeny.data.Sequence();
4829             seq.setName( "K1PYK7_CRAGI" );
4830             n.getNodeData().addSequence( seq );
4831             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4832                 return false;
4833             }
4834             seq.setName( "tr|B3RJ64" );
4835             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4836                 return false;
4837             }
4838             n = new PhylogenyNode();
4839             seq = new org.forester.phylogeny.data.Sequence();
4840             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4841             n.getNodeData().addSequence( seq );
4842             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4843                 return false;
4844             }
4845             n = new PhylogenyNode();
4846             seq = new org.forester.phylogeny.data.Sequence();
4847             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4848             n.getNodeData().addSequence( seq );
4849             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4850                 return false;
4851             }
4852             //
4853             n = new PhylogenyNode();
4854             n.setName( "ACP19736" );
4855             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4856                 return false;
4857             }
4858             n = new PhylogenyNode();
4859             n.setName( "|ACP19736|" );
4860             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4861                 return false;
4862             }
4863         }
4864         catch ( final Exception e ) {
4865             e.printStackTrace( System.out );
4866             return false;
4867         }
4868         return true;
4869     }
4870
4871     private static boolean testFastaParser() {
4872         try {
4873             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4874                 return false;
4875             }
4876             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4877                 return false;
4878             }
4879             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4880             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4881                 return false;
4882             }
4883             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4884                 return false;
4885             }
4886             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4887                 return false;
4888             }
4889             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4890                 return false;
4891             }
4892             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4893                 return false;
4894             }
4895             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4896                 return false;
4897             }
4898         }
4899         catch ( final Exception e ) {
4900             e.printStackTrace();
4901             return false;
4902         }
4903         return true;
4904     }
4905
4906     private static boolean testGenbankAccessorParsing() {
4907         //The format for GenBank Accession numbers are:
4908         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4909         //Protein:    3 letters + 5 numerals
4910         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4911         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4912             return false;
4913         }
4914         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4915             return false;
4916         }
4917         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4918             return false;
4919         }
4920         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4921             return false;
4922         }
4923         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4924             return false;
4925         }
4926         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4927             return false;
4928         }
4929         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4930             return false;
4931         }
4932         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4933             return false;
4934         }
4935         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4936             return false;
4937         }
4938         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4939             return false;
4940         }
4941         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4942             return false;
4943         }
4944         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4945             return false;
4946         }
4947         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4948             return false;
4949         }
4950         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4951             return false;
4952         }
4953         return true;
4954     }
4955
4956     private static boolean testGeneralMsaParser() {
4957         try {
4958             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4959             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4960             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4961             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4962             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4963             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4964             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4965             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4966             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4967                 return false;
4968             }
4969             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4970                 return false;
4971             }
4972             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4973                 return false;
4974             }
4975             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4976                 return false;
4977             }
4978             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4979                 return false;
4980             }
4981             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4982                 return false;
4983             }
4984             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4985                 return false;
4986             }
4987             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4988                 return false;
4989             }
4990             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4991                 return false;
4992             }
4993             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4994                 return false;
4995             }
4996             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4997                 return false;
4998             }
4999             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5000                 return false;
5001             }
5002             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5003             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5004                 return false;
5005             }
5006             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5007                 return false;
5008             }
5009             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5010                 return false;
5011             }
5012             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5013             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5014                 return false;
5015             }
5016             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5017                 return false;
5018             }
5019             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5020                 return false;
5021             }
5022             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5023             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5024                 return false;
5025             }
5026             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5027                 return false;
5028             }
5029             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5030                 return false;
5031             }
5032         }
5033         catch ( final Exception e ) {
5034             e.printStackTrace();
5035             return false;
5036         }
5037         return true;
5038     }
5039
5040     private static boolean testGeneralTable() {
5041         try {
5042             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5043             t0.setValue( 3, 2, "23" );
5044             t0.setValue( 10, 1, "error" );
5045             t0.setValue( 10, 1, "110" );
5046             t0.setValue( 9, 1, "19" );
5047             t0.setValue( 1, 10, "101" );
5048             t0.setValue( 10, 10, "1010" );
5049             t0.setValue( 100, 10, "10100" );
5050             t0.setValue( 0, 0, "00" );
5051             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5052                 return false;
5053             }
5054             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5055                 return false;
5056             }
5057             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5058                 return false;
5059             }
5060             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5061                 return false;
5062             }
5063             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5064                 return false;
5065             }
5066             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5067                 return false;
5068             }
5069             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5070                 return false;
5071             }
5072             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5073                 return false;
5074             }
5075             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5076                 return false;
5077             }
5078             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5079             t1.setValue( "3", "2", "23" );
5080             t1.setValue( "10", "1", "error" );
5081             t1.setValue( "10", "1", "110" );
5082             t1.setValue( "9", "1", "19" );
5083             t1.setValue( "1", "10", "101" );
5084             t1.setValue( "10", "10", "1010" );
5085             t1.setValue( "100", "10", "10100" );
5086             t1.setValue( "0", "0", "00" );
5087             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5088             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5089                 return false;
5090             }
5091             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5092                 return false;
5093             }
5094             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5095                 return false;
5096             }
5097             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5098                 return false;
5099             }
5100             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5101                 return false;
5102             }
5103             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5104                 return false;
5105             }
5106             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5107                 return false;
5108             }
5109             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5110                 return false;
5111             }
5112             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5113                 return false;
5114             }
5115             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5116                 return false;
5117             }
5118         }
5119         catch ( final Exception e ) {
5120             e.printStackTrace( System.out );
5121             return false;
5122         }
5123         return true;
5124     }
5125
5126     private static boolean testGetDistance() {
5127         try {
5128             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5129             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",
5130                                                  new NHXParser() )[ 0 ];
5131             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5132                 return false;
5133             }
5134             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5135                 return false;
5136             }
5137             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5138                 return false;
5139             }
5140             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5141                 return false;
5142             }
5143             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5144                 return false;
5145             }
5146             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5147                 return false;
5148             }
5149             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5150                 return false;
5151             }
5152             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5153                 return false;
5154             }
5155             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5156                 return false;
5157             }
5158             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5159                 return false;
5160             }
5161             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5162                 return false;
5163             }
5164             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5165                 return false;
5166             }
5167             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5168                 return false;
5169             }
5170             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5171                 return false;
5172             }
5173             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5174                 return false;
5175             }
5176             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5177                 return false;
5178             }
5179             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5180                 return false;
5181             }
5182             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5183                 return false;
5184             }
5185             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5186                 return false;
5187             }
5188             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5189                 return false;
5190             }
5191             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5192                 return false;
5193             }
5194             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5195                 return false;
5196             }
5197             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5198                 return false;
5199             }
5200             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5201                 return false;
5202             }
5203             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5204                 return false;
5205             }
5206             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5207                 return false;
5208             }
5209             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5210                 return false;
5211             }
5212             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5213                 return false;
5214             }
5215             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5216                 return false;
5217             }
5218             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5219                 return false;
5220             }
5221             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5222                 return false;
5223             }
5224             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",
5225                                                  new NHXParser() )[ 0 ];
5226             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5227                 return false;
5228             }
5229             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5230                 return false;
5231             }
5232             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5233                 return false;
5234             }
5235             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5236                 return false;
5237             }
5238             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5239                 return false;
5240             }
5241             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5242                 return false;
5243             }
5244             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5245                 return false;
5246             }
5247             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5248                 return false;
5249             }
5250             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5251                 return false;
5252             }
5253             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5254                 return false;
5255             }
5256             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5257                 return false;
5258             }
5259         }
5260         catch ( final Exception e ) {
5261             e.printStackTrace( System.out );
5262             return false;
5263         }
5264         return true;
5265     }
5266
5267     private static boolean testGetLCA() {
5268         try {
5269             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5270             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5271                                                  new NHXParser() )[ 0 ];
5272             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5273             if ( !A.getName().equals( "A" ) ) {
5274                 return false;
5275             }
5276             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5277             if ( !gh.getName().equals( "gh" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5281             if ( !ab.getName().equals( "ab" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5285             if ( !ab2.getName().equals( "ab" ) ) {
5286                 return false;
5287             }
5288             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5289             if ( !gh2.getName().equals( "gh" ) ) {
5290                 return false;
5291             }
5292             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5293             if ( !gh3.getName().equals( "gh" ) ) {
5294                 return false;
5295             }
5296             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5297             if ( !abc.getName().equals( "abc" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5301             if ( !abc2.getName().equals( "abc" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5305             if ( !abcd.getName().equals( "abcd" ) ) {
5306                 return false;
5307             }
5308             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5309             if ( !abcd2.getName().equals( "abcd" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5313             if ( !abcdef.getName().equals( "abcdef" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5317             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5321             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5322                 return false;
5323             }
5324             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5325             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5326                 return false;
5327             }
5328             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5329             if ( !abcde.getName().equals( "abcde" ) ) {
5330                 return false;
5331             }
5332             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5333             if ( !abcde2.getName().equals( "abcde" ) ) {
5334                 return false;
5335             }
5336             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5337             if ( !r.getName().equals( "abcdefgh" ) ) {
5338                 return false;
5339             }
5340             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5341             if ( !r2.getName().equals( "abcdefgh" ) ) {
5342                 return false;
5343             }
5344             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5345             if ( !r3.getName().equals( "abcdefgh" ) ) {
5346                 return false;
5347             }
5348             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5349             if ( !abcde3.getName().equals( "abcde" ) ) {
5350                 return false;
5351             }
5352             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5353             if ( !abcde4.getName().equals( "abcde" ) ) {
5354                 return false;
5355             }
5356             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5357             if ( !ab3.getName().equals( "ab" ) ) {
5358                 return false;
5359             }
5360             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5361             if ( !ab4.getName().equals( "ab" ) ) {
5362                 return false;
5363             }
5364             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5365             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5366             if ( !cd.getName().equals( "cd" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5370             if ( !cd2.getName().equals( "cd" ) ) {
5371                 return false;
5372             }
5373             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5374             if ( !cde.getName().equals( "cde" ) ) {
5375                 return false;
5376             }
5377             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5378             if ( !cde2.getName().equals( "cde" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5382             if ( !cdef.getName().equals( "cdef" ) ) {
5383                 return false;
5384             }
5385             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5386             if ( !cdef2.getName().equals( "cdef" ) ) {
5387                 return false;
5388             }
5389             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5390             if ( !cdef3.getName().equals( "cdef" ) ) {
5391                 return false;
5392             }
5393             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5394             if ( !rt.getName().equals( "r" ) ) {
5395                 return false;
5396             }
5397             final Phylogeny p3 = factory
5398                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5399                              new NHXParser() )[ 0 ];
5400             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5401             if ( !bc_3.getName().equals( "bc" ) ) {
5402                 return false;
5403             }
5404             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5405             if ( !ac_3.getName().equals( "abc" ) ) {
5406                 return false;
5407             }
5408             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5409             if ( !ad_3.getName().equals( "abcde" ) ) {
5410                 return false;
5411             }
5412             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5413             if ( !af_3.getName().equals( "abcdef" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5417             if ( !ag_3.getName().equals( "" ) ) {
5418                 return false;
5419             }
5420             if ( !ag_3.isRoot() ) {
5421                 return false;
5422             }
5423             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5424             if ( !al_3.getName().equals( "" ) ) {
5425                 return false;
5426             }
5427             if ( !al_3.isRoot() ) {
5428                 return false;
5429             }
5430             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5431             if ( !kl_3.getName().equals( "" ) ) {
5432                 return false;
5433             }
5434             if ( !kl_3.isRoot() ) {
5435                 return false;
5436             }
5437             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5438             if ( !fl_3.getName().equals( "" ) ) {
5439                 return false;
5440             }
5441             if ( !fl_3.isRoot() ) {
5442                 return false;
5443             }
5444             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5445             if ( !gk_3.getName().equals( "ghijk" ) ) {
5446                 return false;
5447             }
5448             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5449             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5450             if ( !r_4.getName().equals( "r" ) ) {
5451                 return false;
5452             }
5453             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5454             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5455             if ( !r_5.getName().equals( "root" ) ) {
5456                 return false;
5457             }
5458             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5459             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5460             if ( !r_6.getName().equals( "rot" ) ) {
5461                 return false;
5462             }
5463             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5464             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5465             if ( !r_7.getName().equals( "rott" ) ) {
5466                 return false;
5467             }
5468         }
5469         catch ( final Exception e ) {
5470             e.printStackTrace( System.out );
5471             return false;
5472         }
5473         return true;
5474     }
5475
5476     private static boolean testGetLCA2() {
5477         try {
5478             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5479             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5480             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5481             PhylogenyMethods.preOrderReId( p_a );
5482             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5483                                                                                               p_a.getNode( "a" ) );
5484             if ( !p_a_1.getName().equals( "a" ) ) {
5485                 return false;
5486             }
5487             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5488             PhylogenyMethods.preOrderReId( p_b );
5489             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5490                                                                                               p_b.getNode( "a" ) );
5491             if ( !p_b_1.getName().equals( "b" ) ) {
5492                 return false;
5493             }
5494             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5495                                                                                               p_b.getNode( "b" ) );
5496             if ( !p_b_2.getName().equals( "b" ) ) {
5497                 return false;
5498             }
5499             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5500             PhylogenyMethods.preOrderReId( p_c );
5501             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5502                                                                                               p_c.getNode( "a" ) );
5503             if ( !p_c_1.getName().equals( "b" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5507                                                                                               p_c.getNode( "c" ) );
5508             if ( !p_c_2.getName().equals( "c" ) ) {
5509                 System.out.println( p_c_2.getName() );
5510                 System.exit( -1 );
5511                 return false;
5512             }
5513             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5514                                                                                               p_c.getNode( "b" ) );
5515             if ( !p_c_3.getName().equals( "b" ) ) {
5516                 return false;
5517             }
5518             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5519                                                                                               p_c.getNode( "a" ) );
5520             if ( !p_c_4.getName().equals( "c" ) ) {
5521                 return false;
5522             }
5523             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5524                                                  new NHXParser() )[ 0 ];
5525             PhylogenyMethods.preOrderReId( p1 );
5526             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5527                                                                                           p1.getNode( "A" ) );
5528             if ( !A.getName().equals( "A" ) ) {
5529                 return false;
5530             }
5531             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5532                                                                                            p1.getNode( "gh" ) );
5533             if ( !gh.getName().equals( "gh" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5537                                                                                            p1.getNode( "B" ) );
5538             if ( !ab.getName().equals( "ab" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5542                                                                                             p1.getNode( "A" ) );
5543             if ( !ab2.getName().equals( "ab" ) ) {
5544                 return false;
5545             }
5546             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5547                                                                                             p1.getNode( "G" ) );
5548             if ( !gh2.getName().equals( "gh" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5552                                                                                             p1.getNode( "H" ) );
5553             if ( !gh3.getName().equals( "gh" ) ) {
5554                 return false;
5555             }
5556             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5557                                                                                             p1.getNode( "A" ) );
5558             if ( !abc.getName().equals( "abc" ) ) {
5559                 return false;
5560             }
5561             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5562                                                                                              p1.getNode( "C" ) );
5563             if ( !abc2.getName().equals( "abc" ) ) {
5564                 return false;
5565             }
5566             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5567                                                                                              p1.getNode( "D" ) );
5568             if ( !abcd.getName().equals( "abcd" ) ) {
5569                 return false;
5570             }
5571             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5572                                                                                               p1.getNode( "A" ) );
5573             if ( !abcd2.getName().equals( "abcd" ) ) {
5574                 return false;
5575             }
5576             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5577                                                                                                p1.getNode( "F" ) );
5578             if ( !abcdef.getName().equals( "abcdef" ) ) {
5579                 return false;
5580             }
5581             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5582                                                                                                 p1.getNode( "A" ) );
5583             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5584                 return false;
5585             }
5586             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5587                                                                                                 p1.getNode( "F" ) );
5588             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5589                 return false;
5590             }
5591             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5592                                                                                                 p1.getNode( "ab" ) );
5593             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5594                 return false;
5595             }
5596             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5597                                                                                               p1.getNode( "E" ) );
5598             if ( !abcde.getName().equals( "abcde" ) ) {
5599                 return false;
5600             }
5601             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5602                                                                                                p1.getNode( "A" ) );
5603             if ( !abcde2.getName().equals( "abcde" ) ) {
5604                 return false;
5605             }
5606             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5607                                                                                           p1.getNode( "abcdefgh" ) );
5608             if ( !r.getName().equals( "abcdefgh" ) ) {
5609                 return false;
5610             }
5611             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5612                                                                                            p1.getNode( "H" ) );
5613             if ( !r2.getName().equals( "abcdefgh" ) ) {
5614                 return false;
5615             }
5616             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5617                                                                                            p1.getNode( "A" ) );
5618             if ( !r3.getName().equals( "abcdefgh" ) ) {
5619                 return false;
5620             }
5621             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5622                                                                                                p1.getNode( "abcde" ) );
5623             if ( !abcde3.getName().equals( "abcde" ) ) {
5624                 return false;
5625             }
5626             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5627                                                                                                p1.getNode( "E" ) );
5628             if ( !abcde4.getName().equals( "abcde" ) ) {
5629                 return false;
5630             }
5631             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5632                                                                                             p1.getNode( "B" ) );
5633             if ( !ab3.getName().equals( "ab" ) ) {
5634                 return false;
5635             }
5636             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5637                                                                                             p1.getNode( "ab" ) );
5638             if ( !ab4.getName().equals( "ab" ) ) {
5639                 return false;
5640             }
5641             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5642             PhylogenyMethods.preOrderReId( p2 );
5643             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5644                                                                                            p2.getNode( "d" ) );
5645             if ( !cd.getName().equals( "cd" ) ) {
5646                 return false;
5647             }
5648             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5649                                                                                             p2.getNode( "c" ) );
5650             if ( !cd2.getName().equals( "cd" ) ) {
5651                 return false;
5652             }
5653             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5654                                                                                             p2.getNode( "e" ) );
5655             if ( !cde.getName().equals( "cde" ) ) {
5656                 return false;
5657             }
5658             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5659                                                                                              p2.getNode( "c" ) );
5660             if ( !cde2.getName().equals( "cde" ) ) {
5661                 return false;
5662             }
5663             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5664                                                                                              p2.getNode( "f" ) );
5665             if ( !cdef.getName().equals( "cdef" ) ) {
5666                 return false;
5667             }
5668             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5669                                                                                               p2.getNode( "f" ) );
5670             if ( !cdef2.getName().equals( "cdef" ) ) {
5671                 return false;
5672             }
5673             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5674                                                                                               p2.getNode( "d" ) );
5675             if ( !cdef3.getName().equals( "cdef" ) ) {
5676                 return false;
5677             }
5678             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5679                                                                                            p2.getNode( "a" ) );
5680             if ( !rt.getName().equals( "r" ) ) {
5681                 return false;
5682             }
5683             final Phylogeny p3 = factory
5684                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5685                              new NHXParser() )[ 0 ];
5686             PhylogenyMethods.preOrderReId( p3 );
5687             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5688                                                                                              p3.getNode( "c" ) );
5689             if ( !bc_3.getName().equals( "bc" ) ) {
5690                 return false;
5691             }
5692             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5693                                                                                              p3.getNode( "c" ) );
5694             if ( !ac_3.getName().equals( "abc" ) ) {
5695                 return false;
5696             }
5697             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5698                                                                                              p3.getNode( "d" ) );
5699             if ( !ad_3.getName().equals( "abcde" ) ) {
5700                 return false;
5701             }
5702             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5703                                                                                              p3.getNode( "f" ) );
5704             if ( !af_3.getName().equals( "abcdef" ) ) {
5705                 return false;
5706             }
5707             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5708                                                                                              p3.getNode( "g" ) );
5709             if ( !ag_3.getName().equals( "" ) ) {
5710                 return false;
5711             }
5712             if ( !ag_3.isRoot() ) {
5713                 return false;
5714             }
5715             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5716                                                                                              p3.getNode( "l" ) );
5717             if ( !al_3.getName().equals( "" ) ) {
5718                 return false;
5719             }
5720             if ( !al_3.isRoot() ) {
5721                 return false;
5722             }
5723             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5724                                                                                              p3.getNode( "l" ) );
5725             if ( !kl_3.getName().equals( "" ) ) {
5726                 return false;
5727             }
5728             if ( !kl_3.isRoot() ) {
5729                 return false;
5730             }
5731             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5732                                                                                              p3.getNode( "l" ) );
5733             if ( !fl_3.getName().equals( "" ) ) {
5734                 return false;
5735             }
5736             if ( !fl_3.isRoot() ) {
5737                 return false;
5738             }
5739             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5740                                                                                              p3.getNode( "k" ) );
5741             if ( !gk_3.getName().equals( "ghijk" ) ) {
5742                 return false;
5743             }
5744             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5745             PhylogenyMethods.preOrderReId( p4 );
5746             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5747                                                                                             p4.getNode( "c" ) );
5748             if ( !r_4.getName().equals( "r" ) ) {
5749                 return false;
5750             }
5751             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5752             PhylogenyMethods.preOrderReId( p5 );
5753             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5754                                                                                             p5.getNode( "c" ) );
5755             if ( !r_5.getName().equals( "root" ) ) {
5756                 return false;
5757             }
5758             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5759             PhylogenyMethods.preOrderReId( p6 );
5760             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5761                                                                                             p6.getNode( "a" ) );
5762             if ( !r_6.getName().equals( "rot" ) ) {
5763                 return false;
5764             }
5765             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5766             PhylogenyMethods.preOrderReId( p7 );
5767             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5768                                                                                             p7.getNode( "e" ) );
5769             if ( !r_7.getName().equals( "rott" ) ) {
5770                 return false;
5771             }
5772             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5773                                                                                              p7.getNode( "a" ) );
5774             if ( !r_71.getName().equals( "rott" ) ) {
5775                 return false;
5776             }
5777             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5778                                                                                              p7.getNode( "rott" ) );
5779             if ( !r_72.getName().equals( "rott" ) ) {
5780                 return false;
5781             }
5782             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5783                                                                                              p7.getNode( "a" ) );
5784             if ( !r_73.getName().equals( "rott" ) ) {
5785                 return false;
5786             }
5787             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5788                                                                                              p7.getNode( "rott" ) );
5789             if ( !r_74.getName().equals( "rott" ) ) {
5790                 return false;
5791             }
5792             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5793                                                                                              p7.getNode( "e" ) );
5794             if ( !r_75.getName().equals( "e" ) ) {
5795                 return false;
5796             }
5797         }
5798         catch ( final Exception e ) {
5799             e.printStackTrace( System.out );
5800             return false;
5801         }
5802         return true;
5803     }
5804
5805     private static boolean testHmmscanOutputParser() {
5806         final String test_dir = Test.PATH_TO_TEST_DATA;
5807         try {
5808             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5809                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5810             parser1.parse();
5811             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5812                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5813             final List<Protein> proteins = parser2.parse();
5814             if ( parser2.getProteinsEncountered() != 4 ) {
5815                 return false;
5816             }
5817             if ( proteins.size() != 4 ) {
5818                 return false;
5819             }
5820             if ( parser2.getDomainsEncountered() != 69 ) {
5821                 return false;
5822             }
5823             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5824                 return false;
5825             }
5826             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5827                 return false;
5828             }
5829             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5830                 return false;
5831             }
5832             final Protein p1 = proteins.get( 0 );
5833             if ( p1.getNumberOfProteinDomains() != 15 ) {
5834                 return false;
5835             }
5836             if ( p1.getLength() != 850 ) {
5837                 return false;
5838             }
5839             final Protein p2 = proteins.get( 1 );
5840             if ( p2.getNumberOfProteinDomains() != 51 ) {
5841                 return false;
5842             }
5843             if ( p2.getLength() != 1291 ) {
5844                 return false;
5845             }
5846             final Protein p3 = proteins.get( 2 );
5847             if ( p3.getNumberOfProteinDomains() != 2 ) {
5848                 return false;
5849             }
5850             final Protein p4 = proteins.get( 3 );
5851             if ( p4.getNumberOfProteinDomains() != 1 ) {
5852                 return false;
5853             }
5854             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5855                 return false;
5856             }
5857             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5858                 return false;
5859             }
5860             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5861                 return false;
5862             }
5863             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5864                 return false;
5865             }
5866             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5867                 return false;
5868             }
5869             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5870                 return false;
5871             }
5872             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5873                 return false;
5874             }
5875         }
5876         catch ( final Exception e ) {
5877             e.printStackTrace( System.out );
5878             return false;
5879         }
5880         return true;
5881     }
5882
5883     private static boolean testLastExternalNodeMethods() {
5884         try {
5885             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5886             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5887             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5888             final PhylogenyNode n1 = t0.getNode( "A" );
5889             if ( n1.isLastExternalNode() ) {
5890                 return false;
5891             }
5892             final PhylogenyNode n2 = t0.getNode( "B" );
5893             if ( n2.isLastExternalNode() ) {
5894                 return false;
5895             }
5896             final PhylogenyNode n3 = t0.getNode( "C" );
5897             if ( n3.isLastExternalNode() ) {
5898                 return false;
5899             }
5900             final PhylogenyNode n4 = t0.getNode( "D" );
5901             if ( !n4.isLastExternalNode() ) {
5902                 return false;
5903             }
5904         }
5905         catch ( final Exception e ) {
5906             e.printStackTrace( System.out );
5907             return false;
5908         }
5909         return true;
5910     }
5911
5912     private static boolean testLevelOrderIterator() {
5913         try {
5914             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5915             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5916             PhylogenyNodeIterator it0;
5917             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5918                 it0.next();
5919             }
5920             for( it0.reset(); it0.hasNext(); ) {
5921                 it0.next();
5922             }
5923             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5924             if ( !it.next().getName().equals( "r" ) ) {
5925                 return false;
5926             }
5927             if ( !it.next().getName().equals( "ab" ) ) {
5928                 return false;
5929             }
5930             if ( !it.next().getName().equals( "cd" ) ) {
5931                 return false;
5932             }
5933             if ( !it.next().getName().equals( "A" ) ) {
5934                 return false;
5935             }
5936             if ( !it.next().getName().equals( "B" ) ) {
5937                 return false;
5938             }
5939             if ( !it.next().getName().equals( "C" ) ) {
5940                 return false;
5941             }
5942             if ( !it.next().getName().equals( "D" ) ) {
5943                 return false;
5944             }
5945             if ( it.hasNext() ) {
5946                 return false;
5947             }
5948             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",
5949                                                  new NHXParser() )[ 0 ];
5950             PhylogenyNodeIterator it2;
5951             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5952                 it2.next();
5953             }
5954             for( it2.reset(); it2.hasNext(); ) {
5955                 it2.next();
5956             }
5957             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5958             if ( !it3.next().getName().equals( "r" ) ) {
5959                 return false;
5960             }
5961             if ( !it3.next().getName().equals( "abc" ) ) {
5962                 return false;
5963             }
5964             if ( !it3.next().getName().equals( "defg" ) ) {
5965                 return false;
5966             }
5967             if ( !it3.next().getName().equals( "A" ) ) {
5968                 return false;
5969             }
5970             if ( !it3.next().getName().equals( "B" ) ) {
5971                 return false;
5972             }
5973             if ( !it3.next().getName().equals( "C" ) ) {
5974                 return false;
5975             }
5976             if ( !it3.next().getName().equals( "D" ) ) {
5977                 return false;
5978             }
5979             if ( !it3.next().getName().equals( "E" ) ) {
5980                 return false;
5981             }
5982             if ( !it3.next().getName().equals( "F" ) ) {
5983                 return false;
5984             }
5985             if ( !it3.next().getName().equals( "G" ) ) {
5986                 return false;
5987             }
5988             if ( !it3.next().getName().equals( "1" ) ) {
5989                 return false;
5990             }
5991             if ( !it3.next().getName().equals( "2" ) ) {
5992                 return false;
5993             }
5994             if ( !it3.next().getName().equals( "3" ) ) {
5995                 return false;
5996             }
5997             if ( !it3.next().getName().equals( "4" ) ) {
5998                 return false;
5999             }
6000             if ( !it3.next().getName().equals( "5" ) ) {
6001                 return false;
6002             }
6003             if ( !it3.next().getName().equals( "6" ) ) {
6004                 return false;
6005             }
6006             if ( !it3.next().getName().equals( "f1" ) ) {
6007                 return false;
6008             }
6009             if ( !it3.next().getName().equals( "f2" ) ) {
6010                 return false;
6011             }
6012             if ( !it3.next().getName().equals( "f3" ) ) {
6013                 return false;
6014             }
6015             if ( !it3.next().getName().equals( "a" ) ) {
6016                 return false;
6017             }
6018             if ( !it3.next().getName().equals( "b" ) ) {
6019                 return false;
6020             }
6021             if ( !it3.next().getName().equals( "f21" ) ) {
6022                 return false;
6023             }
6024             if ( !it3.next().getName().equals( "X" ) ) {
6025                 return false;
6026             }
6027             if ( !it3.next().getName().equals( "Y" ) ) {
6028                 return false;
6029             }
6030             if ( !it3.next().getName().equals( "Z" ) ) {
6031                 return false;
6032             }
6033             if ( it3.hasNext() ) {
6034                 return false;
6035             }
6036             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6037             PhylogenyNodeIterator it4;
6038             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6039                 it4.next();
6040             }
6041             for( it4.reset(); it4.hasNext(); ) {
6042                 it4.next();
6043             }
6044             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6045             if ( !it5.next().getName().equals( "r" ) ) {
6046                 return false;
6047             }
6048             if ( !it5.next().getName().equals( "A" ) ) {
6049                 return false;
6050             }
6051             if ( !it5.next().getName().equals( "B" ) ) {
6052                 return false;
6053             }
6054             if ( !it5.next().getName().equals( "C" ) ) {
6055                 return false;
6056             }
6057             if ( !it5.next().getName().equals( "D" ) ) {
6058                 return false;
6059             }
6060             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6061             PhylogenyNodeIterator it6;
6062             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6063                 it6.next();
6064             }
6065             for( it6.reset(); it6.hasNext(); ) {
6066                 it6.next();
6067             }
6068             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6069             if ( !it7.next().getName().equals( "A" ) ) {
6070                 return false;
6071             }
6072             if ( it.hasNext() ) {
6073                 return false;
6074             }
6075         }
6076         catch ( final Exception e ) {
6077             e.printStackTrace( System.out );
6078             return false;
6079         }
6080         return true;
6081     }
6082
6083     private static boolean testMafft( final String path ) {
6084         try {
6085             final List<String> opts = new ArrayList<String>();
6086             opts.add( "--maxiterate" );
6087             opts.add( "1000" );
6088             opts.add( "--localpair" );
6089             opts.add( "--quiet" );
6090             Msa msa = null;
6091             final MsaInferrer mafft = Mafft.createInstance( path );
6092             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6093             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6094                 return false;
6095             }
6096             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6097                 return false;
6098             }
6099         }
6100         catch ( final Exception e ) {
6101             e.printStackTrace( System.out );
6102             return false;
6103         }
6104         return true;
6105     }
6106
6107     private static boolean testMidpointrooting() {
6108         try {
6109             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6110             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6111             PhylogenyMethods.midpointRoot( t0 );
6112             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6113                 return false;
6114             }
6115             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6116                 return false;
6117             }
6118             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6119                            1 ) ) {
6120                 return false;
6121             }
6122             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",
6123                                                  new NHXParser() )[ 0 ];
6124             if ( !t1.isRooted() ) {
6125                 return false;
6126             }
6127             PhylogenyMethods.midpointRoot( t1 );
6128             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6129                 return false;
6130             }
6131             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6132                 return false;
6133             }
6134             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6135                 return false;
6136             }
6137             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6138                 return false;
6139             }
6140             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6141                 return false;
6142             }
6143             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6144                 return false;
6145             }
6146             t1.reRoot( t1.getNode( "A" ) );
6147             PhylogenyMethods.midpointRoot( t1 );
6148             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6149                 return false;
6150             }
6151             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6152                 return false;
6153             }
6154             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6155                 return false;
6156             }
6157             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6158                 return false;
6159             }
6160             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6161                 System.exit( -1 );
6162                 return false;
6163             }
6164             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6165                 return false;
6166             }
6167         }
6168         catch ( final Exception e ) {
6169             e.printStackTrace( System.out );
6170             return false;
6171         }
6172         return true;
6173     }
6174
6175     private static boolean testMsaQualityMethod() {
6176         try {
6177             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6178             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6179             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6180             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6181             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6182             l.add( s0 );
6183             l.add( s1 );
6184             l.add( s2 );
6185             l.add( s3 );
6186             final Msa msa = BasicMsa.createInstance( l );
6187             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6188                 return false;
6189             }
6190             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6191                 return false;
6192             }
6193             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6194                 return false;
6195             }
6196             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6197                 return false;
6198             }
6199             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6200                 return false;
6201             }
6202             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6203                 return false;
6204             }
6205             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6206                 return false;
6207             }
6208         }
6209         catch ( final Exception e ) {
6210             e.printStackTrace( System.out );
6211             return false;
6212         }
6213         return true;
6214     }
6215
6216     private static boolean testMsaEntropy() {
6217         try {
6218             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6219             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6220             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6221             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6222             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6223             l.add( s0 );
6224             l.add( s1 );
6225             l.add( s2 );
6226             l.add( s3 );
6227             final Msa msa = BasicMsa.createInstance( l );
6228             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6229             //FIXME
6230             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6231             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6232             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6233             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6234             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6235             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6236             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6237             //            System.out.println();
6238             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6239             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6240             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6241             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6242             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6243             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6244             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6245             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6246             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6247             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6248             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6249             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6250             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6251             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6252             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6253             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6254             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6255             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6256             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6257             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6258             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6259             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6260             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6261             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6262             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6263             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6264             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6265             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6266             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6267             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6268             final Msa msa2 = BasicMsa.createInstance( l2 );
6269             //            System.out.println();
6270             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6271             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6272             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6273         }
6274         catch ( final Exception e ) {
6275             e.printStackTrace( System.out );
6276             return false;
6277         }
6278         return true;
6279     }
6280
6281     private static boolean testDeleteableMsa() {
6282         try {
6283             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6284             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6285             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6286             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6287             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6288             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6289             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6290             l0.add( s0 );
6291             l0.add( s1 );
6292             l0.add( s2 );
6293             l0.add( s3 );
6294             l0.add( s4 );
6295             l0.add( s5 );
6296             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6297             dmsa0.deleteRow( "b", false );
6298             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6299                 return false;
6300             }
6301             dmsa0.deleteRow( "e", false );
6302             dmsa0.deleteRow( "a", false );
6303             dmsa0.deleteRow( "f", false );
6304             if ( dmsa0.getLength() != 4 ) {
6305                 return false;
6306             }
6307             if ( dmsa0.getNumberOfSequences() != 2 ) {
6308                 return false;
6309             }
6310             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6311                 return false;
6312             }
6313             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6314                 return false;
6315             }
6316             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6317                 return false;
6318             }
6319             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6320                 return false;
6321             }
6322             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6323                 return false;
6324             }
6325             dmsa0.deleteRow( "c", false );
6326             dmsa0.deleteRow( "d", false );
6327             if ( dmsa0.getNumberOfSequences() != 0 ) {
6328                 return false;
6329             }
6330             //
6331             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6332             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6333             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6334             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6335             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6336             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6337             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6338             l1.add( s_0 );
6339             l1.add( s_1 );
6340             l1.add( s_2 );
6341             l1.add( s_3 );
6342             l1.add( s_4 );
6343             l1.add( s_5 );
6344             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6345             dmsa1.deleteGapOnlyColumns();
6346             dmsa1.deleteRow( "a", false );
6347             dmsa1.deleteRow( "f", false );
6348             dmsa1.deleteRow( "d", false );
6349             dmsa1.deleteGapOnlyColumns();
6350             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6351                 return false;
6352             }
6353             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6354                 return false;
6355             }
6356             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6357                 return false;
6358             }
6359             dmsa1.deleteRow( "c", false );
6360             dmsa1.deleteGapOnlyColumns();
6361             final Writer w0 = new StringWriter();
6362             dmsa1.write( w0, MSA_FORMAT.FASTA );
6363             final Writer w1 = new StringWriter();
6364             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6365             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6366                 return false;
6367             }
6368             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6369                 return false;
6370             }
6371             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6372             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6373             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6374             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6375             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6376             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6377             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6378             l2.add( s__0 );
6379             l2.add( s__1 );
6380             l2.add( s__2 );
6381             l2.add( s__3 );
6382             l2.add( s__4 );
6383             l2.add( s__5 );
6384             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6385             dmsa2.deleteGapColumns( 0.5 );
6386             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6387                 return false;
6388             }
6389             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6390                 return false;
6391             }
6392             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6393                 return false;
6394             }
6395             dmsa2.deleteGapColumns( 0.2 );
6396             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6397                 return false;
6398             }
6399             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6400                 return false;
6401             }
6402             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6403                 return false;
6404             }
6405             dmsa2.deleteGapColumns( 0 );
6406             dmsa2.deleteRow( "a", false );
6407             dmsa2.deleteRow( "b", false );
6408             dmsa2.deleteRow( "f", false );
6409             dmsa2.deleteRow( "e", false );
6410             dmsa2.setIdentifier( 0, "new_c" );
6411             dmsa2.setIdentifier( 1, "new_d" );
6412             dmsa2.setResidueAt( 0, 0, 'x' );
6413             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6414             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6415                 return false;
6416             }
6417             final Writer w = new StringWriter();
6418             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6419             final String phylip = w.toString();
6420             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6421                 System.out.println( phylip );
6422                 return false;
6423             }
6424             final Writer w2 = new StringWriter();
6425             dmsa2.write( w2, MSA_FORMAT.FASTA );
6426             final String fasta = w2.toString();
6427             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6428                 System.out.println( fasta );
6429                 return false;
6430             }
6431         }
6432         catch ( final Exception e ) {
6433             e.printStackTrace( System.out );
6434             return false;
6435         }
6436         return true;
6437     }
6438
6439     private static boolean testNextNodeWithCollapsing() {
6440         try {
6441             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6442             PhylogenyNode n;
6443             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6444             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6445             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6446             t0.getNode( "cd" ).setCollapse( true );
6447             t0.getNode( "cde" ).setCollapse( true );
6448             n = t0.getFirstExternalNode();
6449             while ( n != null ) {
6450                 ext.add( n );
6451                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6452             }
6453             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6454                 return false;
6455             }
6456             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6457                 return false;
6458             }
6459             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6460                 return false;
6461             }
6462             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6463                 return false;
6464             }
6465             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6466                 return false;
6467             }
6468             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6469                 return false;
6470             }
6471             ext.clear();
6472             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6473             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6474             t1.getNode( "ab" ).setCollapse( true );
6475             t1.getNode( "cd" ).setCollapse( true );
6476             t1.getNode( "cde" ).setCollapse( true );
6477             n = t1.getNode( "ab" );
6478             ext = new ArrayList<PhylogenyNode>();
6479             while ( n != null ) {
6480                 ext.add( n );
6481                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6482             }
6483             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6490                 return false;
6491             }
6492             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6493                 return false;
6494             }
6495             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6496                 return false;
6497             }
6498             ext.clear();
6499             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6500             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6501             t2.getNode( "ab" ).setCollapse( true );
6502             t2.getNode( "cd" ).setCollapse( true );
6503             t2.getNode( "cde" ).setCollapse( true );
6504             t2.getNode( "c" ).setCollapse( true );
6505             t2.getNode( "d" ).setCollapse( true );
6506             t2.getNode( "e" ).setCollapse( true );
6507             t2.getNode( "gh" ).setCollapse( true );
6508             n = t2.getNode( "ab" );
6509             ext = new ArrayList<PhylogenyNode>();
6510             while ( n != null ) {
6511                 ext.add( n );
6512                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6513             }
6514             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6515                 return false;
6516             }
6517             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6518                 return false;
6519             }
6520             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6521                 return false;
6522             }
6523             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6524                 return false;
6525             }
6526             ext.clear();
6527             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6528             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6529             t3.getNode( "ab" ).setCollapse( true );
6530             t3.getNode( "cd" ).setCollapse( true );
6531             t3.getNode( "cde" ).setCollapse( true );
6532             t3.getNode( "c" ).setCollapse( true );
6533             t3.getNode( "d" ).setCollapse( true );
6534             t3.getNode( "e" ).setCollapse( true );
6535             t3.getNode( "gh" ).setCollapse( true );
6536             t3.getNode( "fgh" ).setCollapse( true );
6537             n = t3.getNode( "ab" );
6538             ext = new ArrayList<PhylogenyNode>();
6539             while ( n != null ) {
6540                 ext.add( n );
6541                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6542             }
6543             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6544                 return false;
6545             }
6546             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6547                 return false;
6548             }
6549             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6550                 return false;
6551             }
6552             ext.clear();
6553             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6554             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6555             t4.getNode( "ab" ).setCollapse( true );
6556             t4.getNode( "cd" ).setCollapse( true );
6557             t4.getNode( "cde" ).setCollapse( true );
6558             t4.getNode( "c" ).setCollapse( true );
6559             t4.getNode( "d" ).setCollapse( true );
6560             t4.getNode( "e" ).setCollapse( true );
6561             t4.getNode( "gh" ).setCollapse( true );
6562             t4.getNode( "fgh" ).setCollapse( true );
6563             t4.getNode( "abcdefgh" ).setCollapse( true );
6564             n = t4.getNode( "abcdefgh" );
6565             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6566                 return false;
6567             }
6568             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6569             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6570             ext.clear();
6571             n = t5.getFirstExternalNode();
6572             while ( n != null ) {
6573                 ext.add( n );
6574                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6575             }
6576             if ( ext.size() != 8 ) {
6577                 return false;
6578             }
6579             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6595                 return false;
6596             }
6597             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6598                 return false;
6599             }
6600             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6601                 return false;
6602             }
6603             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6604             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6605             ext.clear();
6606             t6.getNode( "ab" ).setCollapse( true );
6607             n = t6.getNode( "ab" );
6608             while ( n != null ) {
6609                 ext.add( n );
6610                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6611             }
6612             if ( ext.size() != 7 ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6628                 return false;
6629             }
6630             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6631                 return false;
6632             }
6633             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6634                 return false;
6635             }
6636             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6637             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6638             ext.clear();
6639             t7.getNode( "cd" ).setCollapse( true );
6640             n = t7.getNode( "a" );
6641             while ( n != null ) {
6642                 ext.add( n );
6643                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6644             }
6645             if ( ext.size() != 7 ) {
6646                 return false;
6647             }
6648             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6661                 return false;
6662             }
6663             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6664                 return false;
6665             }
6666             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6667                 return false;
6668             }
6669             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6670             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6671             ext.clear();
6672             t8.getNode( "cd" ).setCollapse( true );
6673             t8.getNode( "c" ).setCollapse( true );
6674             t8.getNode( "d" ).setCollapse( true );
6675             n = t8.getNode( "a" );
6676             while ( n != null ) {
6677                 ext.add( n );
6678                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6679             }
6680             if ( ext.size() != 7 ) {
6681                 return false;
6682             }
6683             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6684                 return false;
6685             }
6686             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6687                 return false;
6688             }
6689             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6690                 System.out.println( "2 fail" );
6691                 return false;
6692             }
6693             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6694                 return false;
6695             }
6696             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6697                 return false;
6698             }
6699             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6700                 return false;
6701             }
6702             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6703                 return false;
6704             }
6705             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6706             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6707             ext.clear();
6708             t9.getNode( "gh" ).setCollapse( true );
6709             n = t9.getNode( "a" );
6710             while ( n != null ) {
6711                 ext.add( n );
6712                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6713             }
6714             if ( ext.size() != 7 ) {
6715                 return false;
6716             }
6717             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6724                 return false;
6725             }
6726             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6727                 return false;
6728             }
6729             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6730                 return false;
6731             }
6732             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6733                 return false;
6734             }
6735             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6736                 return false;
6737             }
6738             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6739             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6740             ext.clear();
6741             t10.getNode( "gh" ).setCollapse( true );
6742             t10.getNode( "g" ).setCollapse( true );
6743             t10.getNode( "h" ).setCollapse( true );
6744             n = t10.getNode( "a" );
6745             while ( n != null ) {
6746                 ext.add( n );
6747                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6748             }
6749             if ( ext.size() != 7 ) {
6750                 return false;
6751             }
6752             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6753                 return false;
6754             }
6755             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6756                 return false;
6757             }
6758             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6759                 return false;
6760             }
6761             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6762                 return false;
6763             }
6764             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6765                 return false;
6766             }
6767             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6768                 return false;
6769             }
6770             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6771                 return false;
6772             }
6773             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6774             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6775             ext.clear();
6776             t11.getNode( "gh" ).setCollapse( true );
6777             t11.getNode( "fgh" ).setCollapse( true );
6778             n = t11.getNode( "a" );
6779             while ( n != null ) {
6780                 ext.add( n );
6781                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6782             }
6783             if ( ext.size() != 6 ) {
6784                 return false;
6785             }
6786             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6796                 return false;
6797             }
6798             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6799                 return false;
6800             }
6801             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6802                 return false;
6803             }
6804             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6805             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6806             ext.clear();
6807             t12.getNode( "gh" ).setCollapse( true );
6808             t12.getNode( "fgh" ).setCollapse( true );
6809             t12.getNode( "g" ).setCollapse( true );
6810             t12.getNode( "h" ).setCollapse( true );
6811             t12.getNode( "f" ).setCollapse( true );
6812             n = t12.getNode( "a" );
6813             while ( n != null ) {
6814                 ext.add( n );
6815                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6816             }
6817             if ( ext.size() != 6 ) {
6818                 return false;
6819             }
6820             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6821                 return false;
6822             }
6823             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6824                 return false;
6825             }
6826             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6827                 return false;
6828             }
6829             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6830                 return false;
6831             }
6832             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6833                 return false;
6834             }
6835             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6836                 return false;
6837             }
6838             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6839             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6840             ext.clear();
6841             t13.getNode( "ab" ).setCollapse( true );
6842             t13.getNode( "b" ).setCollapse( true );
6843             t13.getNode( "fgh" ).setCollapse( true );
6844             t13.getNode( "gh" ).setCollapse( true );
6845             n = t13.getNode( "ab" );
6846             while ( n != null ) {
6847                 ext.add( n );
6848                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6849             }
6850             if ( ext.size() != 5 ) {
6851                 return false;
6852             }
6853             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6857                 return false;
6858             }
6859             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6860                 return false;
6861             }
6862             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6863                 return false;
6864             }
6865             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6866                 return false;
6867             }
6868             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6869             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6870             ext.clear();
6871             t14.getNode( "ab" ).setCollapse( true );
6872             t14.getNode( "a" ).setCollapse( true );
6873             t14.getNode( "fgh" ).setCollapse( true );
6874             t14.getNode( "gh" ).setCollapse( true );
6875             n = t14.getNode( "ab" );
6876             while ( n != null ) {
6877                 ext.add( n );
6878                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6879             }
6880             if ( ext.size() != 5 ) {
6881                 return false;
6882             }
6883             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6887                 return false;
6888             }
6889             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6890                 return false;
6891             }
6892             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6893                 return false;
6894             }
6895             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6896                 return false;
6897             }
6898             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" );
6899             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6900             ext.clear();
6901             t15.getNode( "ab" ).setCollapse( true );
6902             t15.getNode( "a" ).setCollapse( true );
6903             t15.getNode( "fgh" ).setCollapse( true );
6904             t15.getNode( "gh" ).setCollapse( true );
6905             n = t15.getNode( "ab" );
6906             while ( n != null ) {
6907                 ext.add( n );
6908                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6909             }
6910             if ( ext.size() != 6 ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6920                 return false;
6921             }
6922             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6923                 return false;
6924             }
6925             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6926                 return false;
6927             }
6928             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6929                 return false;
6930             }
6931             //
6932             //
6933             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" );
6934             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6935             ext.clear();
6936             t16.getNode( "ab" ).setCollapse( true );
6937             t16.getNode( "a" ).setCollapse( true );
6938             t16.getNode( "fgh" ).setCollapse( true );
6939             t16.getNode( "gh" ).setCollapse( true );
6940             t16.getNode( "cd" ).setCollapse( true );
6941             t16.getNode( "cde" ).setCollapse( true );
6942             t16.getNode( "d" ).setCollapse( true );
6943             t16.getNode( "x" ).setCollapse( true );
6944             n = t16.getNode( "ab" );
6945             while ( n != null ) {
6946                 ext.add( n );
6947                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6948             }
6949             if ( ext.size() != 4 ) {
6950                 return false;
6951             }
6952             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6953                 return false;
6954             }
6955             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6956                 return false;
6957             }
6958             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6959                 return false;
6960             }
6961             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6962                 return false;
6963             }
6964         }
6965         catch ( final Exception e ) {
6966             e.printStackTrace( System.out );
6967             return false;
6968         }
6969         return true;
6970     }
6971
6972     private static boolean testNexusCharactersParsing() {
6973         try {
6974             final NexusCharactersParser parser = new NexusCharactersParser();
6975             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6976             parser.parse();
6977             String[] labels = parser.getCharStateLabels();
6978             if ( labels.length != 7 ) {
6979                 return false;
6980             }
6981             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6982                 return false;
6983             }
6984             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6985                 return false;
6986             }
6987             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6988                 return false;
6989             }
6990             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6991                 return false;
6992             }
6993             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6994                 return false;
6995             }
6996             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6997                 return false;
6998             }
6999             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7000                 return false;
7001             }
7002             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7003             parser.parse();
7004             labels = parser.getCharStateLabels();
7005             if ( labels.length != 7 ) {
7006                 return false;
7007             }
7008             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7009                 return false;
7010             }
7011             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7012                 return false;
7013             }
7014             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7015                 return false;
7016             }
7017             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7018                 return false;
7019             }
7020             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7021                 return false;
7022             }
7023             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7024                 return false;
7025             }
7026             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7027                 return false;
7028             }
7029         }
7030         catch ( final Exception e ) {
7031             e.printStackTrace( System.out );
7032             return false;
7033         }
7034         return true;
7035     }
7036
7037     private static boolean testNexusMatrixParsing() {
7038         try {
7039             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7040             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7041             parser.parse();
7042             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7043             if ( m.getNumberOfCharacters() != 9 ) {
7044                 return false;
7045             }
7046             if ( m.getNumberOfIdentifiers() != 5 ) {
7047                 return false;
7048             }
7049             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7050                 return false;
7051             }
7052             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7053                 return false;
7054             }
7055             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7056                 return false;
7057             }
7058             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7059                 return false;
7060             }
7061             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7062                 return false;
7063             }
7064             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7065                 return false;
7066             }
7067             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7068                 return false;
7069             }
7070             //            if ( labels.length != 7 ) {
7071             //                return false;
7072             //            }
7073             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7074             //                return false;
7075             //            }
7076             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7077             //                return false;
7078             //            }
7079             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7080             //                return false;
7081             //            }
7082             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7083             //                return false;
7084             //            }
7085             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7086             //                return false;
7087             //            }
7088             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7089             //                return false;
7090             //            }
7091             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7092             //                return false;
7093             //            }
7094             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7095             //            parser.parse();
7096             //            labels = parser.getCharStateLabels();
7097             //            if ( labels.length != 7 ) {
7098             //                return false;
7099             //            }
7100             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7104             //                return false;
7105             //            }
7106             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7107             //                return false;
7108             //            }
7109             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7110             //                return false;
7111             //            }
7112             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7113             //                return false;
7114             //            }
7115             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7116             //                return false;
7117             //            }
7118             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7119             //                return false;
7120             //            }
7121         }
7122         catch ( final Exception e ) {
7123             e.printStackTrace( System.out );
7124             return false;
7125         }
7126         return true;
7127     }
7128
7129     private static boolean testNexusTreeParsing() {
7130         try {
7131             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7132             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7133             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7134             if ( phylogenies.length != 1 ) {
7135                 return false;
7136             }
7137             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7138                 return false;
7139             }
7140             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7141                 return false;
7142             }
7143             phylogenies = null;
7144             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7145             if ( phylogenies.length != 1 ) {
7146                 return false;
7147             }
7148             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7149                 return false;
7150             }
7151             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7152                 return false;
7153             }
7154             phylogenies = null;
7155             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7156             if ( phylogenies.length != 1 ) {
7157                 return false;
7158             }
7159             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7160                 return false;
7161             }
7162             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7163                 return false;
7164             }
7165             if ( phylogenies[ 0 ].isRooted() ) {
7166                 return false;
7167             }
7168             phylogenies = null;
7169             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7170             if ( phylogenies.length != 18 ) {
7171                 return false;
7172             }
7173             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7174                 return false;
7175             }
7176             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7177                 return false;
7178             }
7179             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7180                 return false;
7181             }
7182             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7183                 return false;
7184             }
7185             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7186                 return false;
7187             }
7188             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7189                 return false;
7190             }
7191             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7192                 return false;
7193             }
7194             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7195                 return false;
7196             }
7197             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7198                 return false;
7199             }
7200             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7201                 return false;
7202             }
7203             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7204                 return false;
7205             }
7206             if ( phylogenies[ 8 ].isRooted() ) {
7207                 return false;
7208             }
7209             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7210                 return false;
7211             }
7212             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7213                 return false;
7214             }
7215             if ( !phylogenies[ 9 ].isRooted() ) {
7216                 return false;
7217             }
7218             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7219                 return false;
7220             }
7221             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 10 ].isRooted() ) {
7225                 return false;
7226             }
7227             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7228                 return false;
7229             }
7230             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7231                 return false;
7232             }
7233             if ( phylogenies[ 11 ].isRooted() ) {
7234                 return false;
7235             }
7236             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7237                 return false;
7238             }
7239             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 12 ].isRooted() ) {
7243                 return false;
7244             }
7245             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7246                 return false;
7247             }
7248             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7249                 return false;
7250             }
7251             if ( !phylogenies[ 13 ].isRooted() ) {
7252                 return false;
7253             }
7254             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7255                 return false;
7256             }
7257             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7258                 return false;
7259             }
7260             if ( !phylogenies[ 14 ].isRooted() ) {
7261                 return false;
7262             }
7263             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7264                 return false;
7265             }
7266             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7267                 return false;
7268             }
7269             if ( phylogenies[ 15 ].isRooted() ) {
7270                 return false;
7271             }
7272             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7273                 return false;
7274             }
7275             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7276                 return false;
7277             }
7278             if ( !phylogenies[ 16 ].isRooted() ) {
7279                 return false;
7280             }
7281             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7282                 return false;
7283             }
7284             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7285                 return false;
7286             }
7287             if ( phylogenies[ 17 ].isRooted() ) {
7288                 return false;
7289             }
7290             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7291                 return false;
7292             }
7293             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7294             phylogenies = null;
7295             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7296             if ( phylogenies.length != 9 ) {
7297                 return false;
7298             }
7299             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7300                     .getDistanceToParent() ) ) {
7301                 return false;
7302             }
7303             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7304                     .getDistanceToParent() ) ) {
7305                 return false;
7306             }
7307             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7308                 return false;
7309             }
7310             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7311                 return false;
7312             }
7313             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7314                 return false;
7315             }
7316             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7317                 return false;
7318             }
7319             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7320                 return false;
7321             }
7322         }
7323         catch ( final Exception e ) {
7324             e.printStackTrace( System.out );
7325             return false;
7326         }
7327         return true;
7328     }
7329
7330     private static boolean testNexusTreeParsingIterating() {
7331         try {
7332             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7333             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7334             if ( !p.hasNext() ) {
7335                 return false;
7336             }
7337             Phylogeny phy = p.next();
7338             if ( phy == null ) {
7339                 return false;
7340             }
7341             if ( phy.getNumberOfExternalNodes() != 25 ) {
7342                 return false;
7343             }
7344             if ( !phy.getName().equals( "" ) ) {
7345                 return false;
7346             }
7347             if ( p.hasNext() ) {
7348                 return false;
7349             }
7350             phy = p.next();
7351             if ( phy != null ) {
7352                 return false;
7353             }
7354             p.reset();
7355             if ( !p.hasNext() ) {
7356                 return false;
7357             }
7358             phy = p.next();
7359             if ( phy == null ) {
7360                 return false;
7361             }
7362             if ( phy.getNumberOfExternalNodes() != 25 ) {
7363                 return false;
7364             }
7365             if ( !phy.getName().equals( "" ) ) {
7366                 return false;
7367             }
7368             if ( p.hasNext() ) {
7369                 return false;
7370             }
7371             phy = p.next();
7372             if ( phy != null ) {
7373                 return false;
7374             }
7375             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7376             if ( !p.hasNext() ) {
7377                 return false;
7378             }
7379             phy = p.next();
7380             if ( phy == null ) {
7381                 return false;
7382             }
7383             if ( phy.getNumberOfExternalNodes() != 10 ) {
7384                 return false;
7385             }
7386             if ( !phy.getName().equals( "name" ) ) {
7387                 return false;
7388             }
7389             if ( p.hasNext() ) {
7390                 return false;
7391             }
7392             phy = p.next();
7393             if ( phy != null ) {
7394                 return false;
7395             }
7396             p.reset();
7397             if ( !p.hasNext() ) {
7398                 return false;
7399             }
7400             phy = p.next();
7401             if ( phy == null ) {
7402                 return false;
7403             }
7404             if ( phy.getNumberOfExternalNodes() != 10 ) {
7405                 return false;
7406             }
7407             if ( !phy.getName().equals( "name" ) ) {
7408                 return false;
7409             }
7410             if ( p.hasNext() ) {
7411                 return false;
7412             }
7413             phy = p.next();
7414             if ( phy != null ) {
7415                 return false;
7416             }
7417             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7418             if ( !p.hasNext() ) {
7419                 return false;
7420             }
7421             phy = p.next();
7422             if ( phy == null ) {
7423                 return false;
7424             }
7425             if ( phy.getNumberOfExternalNodes() != 3 ) {
7426                 return false;
7427             }
7428             if ( !phy.getName().equals( "" ) ) {
7429                 return false;
7430             }
7431             if ( phy.isRooted() ) {
7432                 return false;
7433             }
7434             if ( p.hasNext() ) {
7435                 return false;
7436             }
7437             phy = p.next();
7438             if ( phy != null ) {
7439                 return false;
7440             }
7441             //
7442             p.reset();
7443             if ( !p.hasNext() ) {
7444                 return false;
7445             }
7446             phy = p.next();
7447             if ( phy == null ) {
7448                 return false;
7449             }
7450             if ( phy.getNumberOfExternalNodes() != 3 ) {
7451                 return false;
7452             }
7453             if ( !phy.getName().equals( "" ) ) {
7454                 return false;
7455             }
7456             if ( p.hasNext() ) {
7457                 return false;
7458             }
7459             phy = p.next();
7460             if ( phy != null ) {
7461                 return false;
7462             }
7463             //
7464             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7465             if ( !p.hasNext() ) {
7466                 return false;
7467             }
7468             //0
7469             phy = p.next();
7470             if ( phy == null ) {
7471                 return false;
7472             }
7473             if ( phy.getNumberOfExternalNodes() != 10 ) {
7474                 return false;
7475             }
7476             if ( !phy.getName().equals( "tree 0" ) ) {
7477                 return false;
7478             }
7479             //1
7480             if ( !p.hasNext() ) {
7481                 return false;
7482             }
7483             phy = p.next();
7484             if ( phy == null ) {
7485                 return false;
7486             }
7487             if ( phy.getNumberOfExternalNodes() != 10 ) {
7488                 return false;
7489             }
7490             if ( !phy.getName().equals( "tree 1" ) ) {
7491                 return false;
7492             }
7493             //2
7494             if ( !p.hasNext() ) {
7495                 return false;
7496             }
7497             phy = p.next();
7498             if ( phy == null ) {
7499                 return false;
7500             }
7501             if ( phy.getNumberOfExternalNodes() != 3 ) {
7502                 System.out.println( phy.toString() );
7503                 return false;
7504             }
7505             if ( !phy.getName().equals( "" ) ) {
7506                 return false;
7507             }
7508             if ( phy.isRooted() ) {
7509                 return false;
7510             }
7511             //3
7512             if ( !p.hasNext() ) {
7513                 return false;
7514             }
7515             phy = p.next();
7516             if ( phy == null ) {
7517                 return false;
7518             }
7519             if ( phy.getNumberOfExternalNodes() != 4 ) {
7520                 return false;
7521             }
7522             if ( !phy.getName().equals( "" ) ) {
7523                 return false;
7524             }
7525             if ( !phy.isRooted() ) {
7526                 return false;
7527             }
7528             //4
7529             if ( !p.hasNext() ) {
7530                 return false;
7531             }
7532             phy = p.next();
7533             if ( phy == null ) {
7534                 return false;
7535             }
7536             if ( phy.getNumberOfExternalNodes() != 5 ) {
7537                 System.out.println( phy.getNumberOfExternalNodes() );
7538                 return false;
7539             }
7540             if ( !phy.getName().equals( "" ) ) {
7541                 return false;
7542             }
7543             if ( !phy.isRooted() ) {
7544                 return false;
7545             }
7546             //5
7547             if ( !p.hasNext() ) {
7548                 return false;
7549             }
7550             phy = p.next();
7551             if ( phy == null ) {
7552                 return false;
7553             }
7554             if ( phy.getNumberOfExternalNodes() != 3 ) {
7555                 return false;
7556             }
7557             if ( !phy.getName().equals( "" ) ) {
7558                 return false;
7559             }
7560             if ( phy.isRooted() ) {
7561                 return false;
7562             }
7563             //6
7564             if ( !p.hasNext() ) {
7565                 return false;
7566             }
7567             phy = p.next();
7568             if ( phy == null ) {
7569                 return false;
7570             }
7571             if ( phy.getNumberOfExternalNodes() != 2 ) {
7572                 return false;
7573             }
7574             if ( !phy.getName().equals( "" ) ) {
7575                 return false;
7576             }
7577             if ( !phy.isRooted() ) {
7578                 return false;
7579             }
7580             //7
7581             if ( !p.hasNext() ) {
7582                 return false;
7583             }
7584             phy = p.next();
7585             if ( phy.getNumberOfExternalNodes() != 3 ) {
7586                 return false;
7587             }
7588             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7589                 return false;
7590             }
7591             if ( !phy.isRooted() ) {
7592                 return false;
7593             }
7594             //8
7595             if ( !p.hasNext() ) {
7596                 return false;
7597             }
7598             phy = p.next();
7599             if ( phy.getNumberOfExternalNodes() != 3 ) {
7600                 return false;
7601             }
7602             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7603                 return false;
7604             }
7605             if ( !phy.getName().equals( "tree 8" ) ) {
7606                 return false;
7607             }
7608             //9
7609             if ( !p.hasNext() ) {
7610                 return false;
7611             }
7612             phy = p.next();
7613             if ( phy.getNumberOfExternalNodes() != 3 ) {
7614                 return false;
7615             }
7616             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7617                 return false;
7618             }
7619             if ( !phy.getName().equals( "tree 9" ) ) {
7620                 return false;
7621             }
7622             //10
7623             if ( !p.hasNext() ) {
7624                 return false;
7625             }
7626             phy = p.next();
7627             if ( phy.getNumberOfExternalNodes() != 3 ) {
7628                 return false;
7629             }
7630             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7631                 return false;
7632             }
7633             if ( !phy.getName().equals( "tree 10" ) ) {
7634                 return false;
7635             }
7636             if ( !phy.isRooted() ) {
7637                 return false;
7638             }
7639             //11
7640             if ( !p.hasNext() ) {
7641                 return false;
7642             }
7643             phy = p.next();
7644             if ( phy.getNumberOfExternalNodes() != 3 ) {
7645                 return false;
7646             }
7647             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7648                 return false;
7649             }
7650             if ( !phy.getName().equals( "tree 11" ) ) {
7651                 return false;
7652             }
7653             if ( phy.isRooted() ) {
7654                 return false;
7655             }
7656             //12
7657             if ( !p.hasNext() ) {
7658                 return false;
7659             }
7660             phy = p.next();
7661             if ( phy.getNumberOfExternalNodes() != 3 ) {
7662                 return false;
7663             }
7664             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7665                 return false;
7666             }
7667             if ( !phy.getName().equals( "tree 12" ) ) {
7668                 return false;
7669             }
7670             if ( !phy.isRooted() ) {
7671                 return false;
7672             }
7673             //13
7674             if ( !p.hasNext() ) {
7675                 return false;
7676             }
7677             phy = p.next();
7678             if ( phy.getNumberOfExternalNodes() != 3 ) {
7679                 return false;
7680             }
7681             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7682                 return false;
7683             }
7684             if ( !phy.getName().equals( "tree 13" ) ) {
7685                 return false;
7686             }
7687             if ( !phy.isRooted() ) {
7688                 return false;
7689             }
7690             //14
7691             if ( !p.hasNext() ) {
7692                 return false;
7693             }
7694             phy = p.next();
7695             if ( phy.getNumberOfExternalNodes() != 10 ) {
7696                 System.out.println( phy.getNumberOfExternalNodes() );
7697                 return false;
7698             }
7699             if ( !phy
7700                     .toNewHampshire()
7701                     .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;" ) ) {
7702                 System.out.println( phy.toNewHampshire() );
7703                 return false;
7704             }
7705             if ( !phy.getName().equals( "tree 14" ) ) {
7706                 return false;
7707             }
7708             if ( !phy.isRooted() ) {
7709                 return false;
7710             }
7711             //15
7712             if ( !p.hasNext() ) {
7713                 return false;
7714             }
7715             phy = p.next();
7716             if ( phy.getNumberOfExternalNodes() != 10 ) {
7717                 System.out.println( phy.getNumberOfExternalNodes() );
7718                 return false;
7719             }
7720             if ( !phy
7721                     .toNewHampshire()
7722                     .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;" ) ) {
7723                 System.out.println( phy.toNewHampshire() );
7724                 return false;
7725             }
7726             if ( !phy.getName().equals( "tree 15" ) ) {
7727                 return false;
7728             }
7729             if ( phy.isRooted() ) {
7730                 return false;
7731             }
7732             //16
7733             if ( !p.hasNext() ) {
7734                 return false;
7735             }
7736             phy = p.next();
7737             if ( phy.getNumberOfExternalNodes() != 10 ) {
7738                 System.out.println( phy.getNumberOfExternalNodes() );
7739                 return false;
7740             }
7741             if ( !phy
7742                     .toNewHampshire()
7743                     .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;" ) ) {
7744                 System.out.println( phy.toNewHampshire() );
7745                 return false;
7746             }
7747             if ( !phy.getName().equals( "tree 16" ) ) {
7748                 return false;
7749             }
7750             if ( !phy.isRooted() ) {
7751                 return false;
7752             }
7753             //17
7754             if ( !p.hasNext() ) {
7755                 return false;
7756             }
7757             phy = p.next();
7758             if ( phy.getNumberOfExternalNodes() != 10 ) {
7759                 System.out.println( phy.getNumberOfExternalNodes() );
7760                 return false;
7761             }
7762             if ( !phy
7763                     .toNewHampshire()
7764                     .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;" ) ) {
7765                 System.out.println( phy.toNewHampshire() );
7766                 return false;
7767             }
7768             if ( !phy.getName().equals( "tree 17" ) ) {
7769                 return false;
7770             }
7771             if ( phy.isRooted() ) {
7772                 return false;
7773             }
7774             //
7775             if ( p.hasNext() ) {
7776                 return false;
7777             }
7778             phy = p.next();
7779             if ( phy != null ) {
7780                 return false;
7781             }
7782             p.reset();
7783             //0
7784             if ( !p.hasNext() ) {
7785                 return false;
7786             }
7787             phy = p.next();
7788             if ( phy == null ) {
7789                 return false;
7790             }
7791             if ( phy.getNumberOfExternalNodes() != 10 ) {
7792                 return false;
7793             }
7794             if ( !phy.getName().equals( "tree 0" ) ) {
7795                 return false;
7796             }
7797             //1
7798             if ( !p.hasNext() ) {
7799                 return false;
7800             }
7801             phy = p.next();
7802             if ( phy == null ) {
7803                 return false;
7804             }
7805             if ( phy.getNumberOfExternalNodes() != 10 ) {
7806                 return false;
7807             }
7808             if ( !phy.getName().equals( "tree 1" ) ) {
7809                 return false;
7810             }
7811             //2
7812             if ( !p.hasNext() ) {
7813                 return false;
7814             }
7815             phy = p.next();
7816             if ( phy == null ) {
7817                 return false;
7818             }
7819             if ( phy.getNumberOfExternalNodes() != 3 ) {
7820                 return false;
7821             }
7822             if ( !phy.getName().equals( "" ) ) {
7823                 return false;
7824             }
7825             if ( phy.isRooted() ) {
7826                 return false;
7827             }
7828             //3
7829             if ( !p.hasNext() ) {
7830                 return false;
7831             }
7832             phy = p.next();
7833             if ( phy == null ) {
7834                 return false;
7835             }
7836             if ( phy.getNumberOfExternalNodes() != 4 ) {
7837                 return false;
7838             }
7839             if ( !phy.getName().equals( "" ) ) {
7840                 return false;
7841             }
7842             if ( !phy.isRooted() ) {
7843                 return false;
7844             }
7845             //4
7846             if ( !p.hasNext() ) {
7847                 return false;
7848             }
7849             phy = p.next();
7850             if ( phy == null ) {
7851                 return false;
7852             }
7853             if ( phy.getNumberOfExternalNodes() != 5 ) {
7854                 System.out.println( phy.getNumberOfExternalNodes() );
7855                 return false;
7856             }
7857             if ( !phy.getName().equals( "" ) ) {
7858                 return false;
7859             }
7860             if ( !phy.isRooted() ) {
7861                 return false;
7862             }
7863             //5
7864             if ( !p.hasNext() ) {
7865                 return false;
7866             }
7867             phy = p.next();
7868             if ( phy == null ) {
7869                 return false;
7870             }
7871             if ( phy.getNumberOfExternalNodes() != 3 ) {
7872                 return false;
7873             }
7874             if ( !phy.getName().equals( "" ) ) {
7875                 return false;
7876             }
7877             if ( phy.isRooted() ) {
7878                 return false;
7879             }
7880             //
7881             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7882             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7883             // 0
7884             if ( !p2.hasNext() ) {
7885                 return false;
7886             }
7887             phy = p2.next();
7888             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7889                 return false;
7890             }
7891             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7892                 return false;
7893             }
7894             // 1
7895             if ( !p2.hasNext() ) {
7896                 return false;
7897             }
7898             phy = p2.next();
7899             // 2
7900             if ( !p2.hasNext() ) {
7901                 return false;
7902             }
7903             phy = p2.next();
7904             // 3
7905             if ( !p2.hasNext() ) {
7906                 return false;
7907             }
7908             phy = p2.next();
7909             // 4
7910             if ( !p2.hasNext() ) {
7911                 return false;
7912             }
7913             phy = p2.next();
7914             // 5
7915             if ( !p2.hasNext() ) {
7916                 return false;
7917             }
7918             phy = p2.next();
7919             // 6
7920             if ( !p2.hasNext() ) {
7921                 return false;
7922             }
7923             phy = p2.next();
7924             // 7
7925             if ( !p2.hasNext() ) {
7926                 return false;
7927             }
7928             phy = p2.next();
7929             // 8
7930             if ( !p2.hasNext() ) {
7931                 return false;
7932             }
7933             phy = p2.next();
7934             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7935                 return false;
7936             }
7937             if ( p2.hasNext() ) {
7938                 return false;
7939             }
7940             phy = p2.next();
7941             if ( phy != null ) {
7942                 return false;
7943             }
7944             // 0
7945             p2.reset();
7946             if ( !p2.hasNext() ) {
7947                 return false;
7948             }
7949             phy = p2.next();
7950             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7951                 return false;
7952             }
7953             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7954                 return false;
7955             }
7956         }
7957         catch ( final Exception e ) {
7958             e.printStackTrace( System.out );
7959             return false;
7960         }
7961         return true;
7962     }
7963
7964     private static boolean testNexusTreeParsingTranslating() {
7965         try {
7966             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7967             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7968             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7969             if ( phylogenies.length != 1 ) {
7970                 return false;
7971             }
7972             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7973                 return false;
7974             }
7975             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7976                 return false;
7977             }
7978             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7979                 return false;
7980             }
7981             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7982                 return false;
7983             }
7984             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7985                     .equals( "Aranaeus" ) ) {
7986                 return false;
7987             }
7988             phylogenies = null;
7989             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7990             if ( phylogenies.length != 3 ) {
7991                 return false;
7992             }
7993             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7994                 return false;
7995             }
7996             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7997                 return false;
7998             }
7999             if ( phylogenies[ 0 ].isRooted() ) {
8000                 return false;
8001             }
8002             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8003                 return false;
8004             }
8005             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8006                 return false;
8007             }
8008             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8009                     .equals( "Aranaeus" ) ) {
8010                 return false;
8011             }
8012             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8013                 return false;
8014             }
8015             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8016                 return false;
8017             }
8018             if ( phylogenies[ 1 ].isRooted() ) {
8019                 return false;
8020             }
8021             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8022                 return false;
8023             }
8024             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8025                 return false;
8026             }
8027             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8028                     .equals( "Aranaeus" ) ) {
8029                 return false;
8030             }
8031             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8032                 return false;
8033             }
8034             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8035                 return false;
8036             }
8037             if ( !phylogenies[ 2 ].isRooted() ) {
8038                 return false;
8039             }
8040             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8041                 return false;
8042             }
8043             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8044                 return false;
8045             }
8046             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8047                     .equals( "Aranaeus" ) ) {
8048                 return false;
8049             }
8050             phylogenies = null;
8051             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8052             if ( phylogenies.length != 3 ) {
8053                 return false;
8054             }
8055             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8056                 return false;
8057             }
8058             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8059                 return false;
8060             }
8061             if ( phylogenies[ 0 ].isRooted() ) {
8062                 return false;
8063             }
8064             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8065                 return false;
8066             }
8067             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8068                 return false;
8069             }
8070             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8071                     .equals( "Aranaeus" ) ) {
8072                 return false;
8073             }
8074             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8075                 return false;
8076             }
8077             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8078                 return false;
8079             }
8080             if ( phylogenies[ 1 ].isRooted() ) {
8081                 return false;
8082             }
8083             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8084                 return false;
8085             }
8086             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8087                 return false;
8088             }
8089             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8090                     .equals( "Aranaeus" ) ) {
8091                 return false;
8092             }
8093             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8094                 return false;
8095             }
8096             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8097                 return false;
8098             }
8099             if ( !phylogenies[ 2 ].isRooted() ) {
8100                 return false;
8101             }
8102             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8103                 return false;
8104             }
8105             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8106                 return false;
8107             }
8108             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8109                     .equals( "Aranaeus" ) ) {
8110                 return false;
8111             }
8112             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8113             if ( phylogenies.length != 3 ) {
8114                 return false;
8115             }
8116             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8117                            0.00100049 ) ) {
8118                 return false;
8119             }
8120         }
8121         catch ( final Exception e ) {
8122             e.printStackTrace( System.out );
8123             return false;
8124         }
8125         return true;
8126     }
8127
8128     private static boolean testNHParsing() {
8129         try {
8130             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8131             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8132             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8133                 return false;
8134             }
8135             final NHXParser nhxp = new NHXParser();
8136             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8137             nhxp.setReplaceUnderscores( true );
8138             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8139             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8140                 return false;
8141             }
8142             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8143                 return false;
8144             }
8145             final Phylogeny p1b = factory
8146                     .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 ",
8147                              new NHXParser() )[ 0 ];
8148             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8149                 return false;
8150             }
8151             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8152                 return false;
8153             }
8154             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8155             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8156             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8157             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8158             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8159             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8160             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8161             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8162             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8163             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8164             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8165                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8166                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8167                                                     new NHXParser() );
8168             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8169                 return false;
8170             }
8171             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8172                 return false;
8173             }
8174             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8175                 return false;
8176             }
8177             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8178                 return false;
8179             }
8180             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8181             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8182             final String p16_S = "((A,B),C)";
8183             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8184             if ( p16.length != 1 ) {
8185                 return false;
8186             }
8187             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8188                 return false;
8189             }
8190             final String p17_S = "(C,(A,B))";
8191             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8192             if ( p17.length != 1 ) {
8193                 return false;
8194             }
8195             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8196                 return false;
8197             }
8198             final String p18_S = "((A,B),(C,D))";
8199             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8200             if ( p18.length != 1 ) {
8201                 return false;
8202             }
8203             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8204                 return false;
8205             }
8206             final String p19_S = "(((A,B),C),D)";
8207             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8208             if ( p19.length != 1 ) {
8209                 return false;
8210             }
8211             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8212                 return false;
8213             }
8214             final String p20_S = "(A,(B,(C,D)))";
8215             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8216             if ( p20.length != 1 ) {
8217                 return false;
8218             }
8219             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8220                 return false;
8221             }
8222             final String p21_S = "(A,(B,(C,(D,E))))";
8223             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8224             if ( p21.length != 1 ) {
8225                 return false;
8226             }
8227             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8228                 return false;
8229             }
8230             final String p22_S = "((((A,B),C),D),E)";
8231             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8232             if ( p22.length != 1 ) {
8233                 return false;
8234             }
8235             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8236                 return false;
8237             }
8238             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8239             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8240             if ( p23.length != 1 ) {
8241                 System.out.println( "xl=" + p23.length );
8242                 System.exit( -1 );
8243                 return false;
8244             }
8245             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8246                 return false;
8247             }
8248             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8249             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8250             if ( p24.length != 1 ) {
8251                 return false;
8252             }
8253             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8254                 return false;
8255             }
8256             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8257             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8258             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8259             if ( p241.length != 2 ) {
8260                 return false;
8261             }
8262             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8263                 return false;
8264             }
8265             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8266                 return false;
8267             }
8268             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8269                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8270                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8271                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8272                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8273                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8274                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8275                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8276             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8277             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8278                 return false;
8279             }
8280             final String p26_S = "(A,B)ab";
8281             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8282             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8283                 return false;
8284             }
8285             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8286             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8287             if ( p27s.length != 1 ) {
8288                 System.out.println( "xxl=" + p27s.length );
8289                 System.exit( -1 );
8290                 return false;
8291             }
8292             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8293                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8294                 System.exit( -1 );
8295                 return false;
8296             }
8297             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8298                                                     new NHXParser() );
8299             if ( p27.length != 1 ) {
8300                 System.out.println( "yl=" + p27.length );
8301                 System.exit( -1 );
8302                 return false;
8303             }
8304             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8305                 System.out.println( p27[ 0 ].toNewHampshireX() );
8306                 System.exit( -1 );
8307                 return false;
8308             }
8309             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8310             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8311             final String p28_S3 = "(A,B)ab";
8312             final String p28_S4 = "((((A,B),C),D),;E;)";
8313             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8314                                                     new NHXParser() );
8315             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8316                 return false;
8317             }
8318             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8319                 return false;
8320             }
8321             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8322                 return false;
8323             }
8324             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8325                 return false;
8326             }
8327             if ( p28.length != 4 ) {
8328                 return false;
8329             }
8330             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";
8331             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8332             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8333                 return false;
8334             }
8335             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";
8336             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8337             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8338                 return false;
8339             }
8340             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8341             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8342             if ( ( p32.length != 0 ) ) {
8343                 return false;
8344             }
8345             final String p33_S = "A";
8346             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8347             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8348                 return false;
8349             }
8350             final String p34_S = "B;";
8351             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8352             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8353                 return false;
8354             }
8355             final String p35_S = "B:0.2";
8356             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8357             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8358                 return false;
8359             }
8360             final String p36_S = "(A)";
8361             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8362             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8363                 return false;
8364             }
8365             final String p37_S = "((A))";
8366             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8367             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8368                 return false;
8369             }
8370             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8371             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8372             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8373                 return false;
8374             }
8375             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8376             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8377             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8378                 return false;
8379             }
8380             final String p40_S = "(A,B,C)";
8381             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8382             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8383                 return false;
8384             }
8385             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8386             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8387             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8388                 return false;
8389             }
8390             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8391             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8392             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8393                 return false;
8394             }
8395             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)";
8396             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8397             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8398                 return false;
8399             }
8400             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)))";
8401             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8402             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8403                 return false;
8404             }
8405             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8406             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8407             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8408                 return false;
8409             }
8410             final String p46_S = "";
8411             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8412             if ( p46.length != 0 ) {
8413                 return false;
8414             }
8415             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8416             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8417                 return false;
8418             }
8419             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8420             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8421                 return false;
8422             }
8423             final Phylogeny p49 = factory
8424                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8425                              new NHXParser() )[ 0 ];
8426             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8427                 return false;
8428             }
8429             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8430             if ( p50.getNode( "A" ) == null ) {
8431                 return false;
8432             }
8433             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8434                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8435                 return false;
8436             }
8437             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8438                 return false;
8439             }
8440             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8441                     .equals( "((A,B)88:2.0,C);" ) ) {
8442                 return false;
8443             }
8444             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8445             if ( p51.getNode( "A(A" ) == null ) {
8446                 return false;
8447             }
8448             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8449             if ( p52.getNode( "A(A" ) == null ) {
8450                 return false;
8451             }
8452             final Phylogeny p53 = factory
8453                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8454                              new NHXParser() )[ 0 ];
8455             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8456                 return false;
8457             }
8458             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8459             if ( p54.getNode( "A" ) == null ) {
8460                 return false;
8461             }
8462             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8463                 return false;
8464             }
8465             final Phylogeny p55 = factory
8466                     .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);" ),
8467                              new NHXParser() )[ 0 ];
8468             if ( !p55
8469                     .toNewHampshire()
8470                     .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);" ) ) {
8471                 System.out.println( p55.toNewHampshire() );
8472                 return false;
8473             }
8474             final Phylogeny p56 = factory
8475                     .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);" ),
8476                              new NHXParser() )[ 0 ];
8477             if ( !p56
8478                     .toNewHampshire()
8479                     .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);" ) ) {
8480                 System.out.println( p56.toNewHampshire() );
8481                 return false;
8482             }
8483             final Phylogeny p57 = factory
8484                     .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);" ),
8485                              new NHXParser() )[ 0 ];
8486             if ( !p57
8487                     .toNewHampshire()
8488                     .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);" ) ) {
8489                 System.out.println( p56.toNewHampshire() );
8490                 return false;
8491             }
8492             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8493             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8494             if ( !p58.toNewHampshire().equals( s58 ) ) {
8495                 System.out.println( p58.toNewHampshire() );
8496                 return false;
8497             }
8498             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8499             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8500             if ( !p59.toNewHampshire().equals( s59 ) ) {
8501                 System.out.println( p59.toNewHampshire() );
8502                 return false;
8503             }
8504             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8505             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8506             if ( !p60.toNewHampshire().equals( s60 ) ) {
8507                 System.out.println( p60.toNewHampshire() );
8508                 return false;
8509             }
8510             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8511             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8512             if ( !p61.toNewHampshire()
8513                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8514                 System.out.println( p61.toNewHampshire() );
8515                 return false;
8516             }
8517         }
8518         catch ( final Exception e ) {
8519             e.printStackTrace( System.out );
8520             return false;
8521         }
8522         return true;
8523     }
8524
8525     private static boolean testNHParsingIter() {
8526         try {
8527             final String p0_str = "(A,B);";
8528             final NHXParser p = new NHXParser();
8529             p.setSource( p0_str );
8530             if ( !p.hasNext() ) {
8531                 return false;
8532             }
8533             final Phylogeny p0 = p.next();
8534             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8535                 System.out.println( p0.toNewHampshire() );
8536                 return false;
8537             }
8538             if ( p.hasNext() ) {
8539                 return false;
8540             }
8541             if ( p.next() != null ) {
8542                 return false;
8543             }
8544             //
8545             final String p00_str = "(A,B)root;";
8546             p.setSource( p00_str );
8547             final Phylogeny p00 = p.next();
8548             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8549                 System.out.println( p00.toNewHampshire() );
8550                 return false;
8551             }
8552             //
8553             final String p000_str = "A;";
8554             p.setSource( p000_str );
8555             final Phylogeny p000 = p.next();
8556             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8557                 System.out.println( p000.toNewHampshire() );
8558                 return false;
8559             }
8560             //
8561             final String p0000_str = "A";
8562             p.setSource( p0000_str );
8563             final Phylogeny p0000 = p.next();
8564             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8565                 System.out.println( p0000.toNewHampshire() );
8566                 return false;
8567             }
8568             //
8569             p.setSource( "(A)" );
8570             final Phylogeny p00000 = p.next();
8571             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8572                 System.out.println( p00000.toNewHampshire() );
8573                 return false;
8574             }
8575             //
8576             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8577             p.setSource( p1_str );
8578             if ( !p.hasNext() ) {
8579                 return false;
8580             }
8581             final Phylogeny p1_0 = p.next();
8582             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8583                 System.out.println( p1_0.toNewHampshire() );
8584                 return false;
8585             }
8586             if ( !p.hasNext() ) {
8587                 return false;
8588             }
8589             final Phylogeny p1_1 = p.next();
8590             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8591                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8592                 return false;
8593             }
8594             if ( !p.hasNext() ) {
8595                 return false;
8596             }
8597             final Phylogeny p1_2 = p.next();
8598             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8599                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8600                 return false;
8601             }
8602             if ( !p.hasNext() ) {
8603                 return false;
8604             }
8605             final Phylogeny p1_3 = p.next();
8606             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8607                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8608                 return false;
8609             }
8610             if ( p.hasNext() ) {
8611                 return false;
8612             }
8613             if ( p.next() != null ) {
8614                 return false;
8615             }
8616             //
8617             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8618             p.setSource( p2_str );
8619             if ( !p.hasNext() ) {
8620                 return false;
8621             }
8622             Phylogeny p2_0 = p.next();
8623             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8624                 System.out.println( p2_0.toNewHampshire() );
8625                 return false;
8626             }
8627             if ( !p.hasNext() ) {
8628                 return false;
8629             }
8630             Phylogeny p2_1 = p.next();
8631             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8632                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8633                 return false;
8634             }
8635             if ( !p.hasNext() ) {
8636                 return false;
8637             }
8638             Phylogeny p2_2 = p.next();
8639             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8640                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8641                 return false;
8642             }
8643             if ( !p.hasNext() ) {
8644                 return false;
8645             }
8646             Phylogeny p2_3 = p.next();
8647             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8648                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8649                 return false;
8650             }
8651             if ( !p.hasNext() ) {
8652                 return false;
8653             }
8654             Phylogeny p2_4 = p.next();
8655             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8656                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8657                 return false;
8658             }
8659             if ( p.hasNext() ) {
8660                 return false;
8661             }
8662             if ( p.next() != null ) {
8663                 return false;
8664             }
8665             ////
8666             p.reset();
8667             if ( !p.hasNext() ) {
8668                 return false;
8669             }
8670             p2_0 = p.next();
8671             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8672                 System.out.println( p2_0.toNewHampshire() );
8673                 return false;
8674             }
8675             if ( !p.hasNext() ) {
8676                 return false;
8677             }
8678             p2_1 = p.next();
8679             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8680                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8681                 return false;
8682             }
8683             if ( !p.hasNext() ) {
8684                 return false;
8685             }
8686             p2_2 = p.next();
8687             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8688                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8689                 return false;
8690             }
8691             if ( !p.hasNext() ) {
8692                 return false;
8693             }
8694             p2_3 = p.next();
8695             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8696                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8697                 return false;
8698             }
8699             if ( !p.hasNext() ) {
8700                 return false;
8701             }
8702             p2_4 = p.next();
8703             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8704                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8705                 return false;
8706             }
8707             if ( p.hasNext() ) {
8708                 return false;
8709             }
8710             if ( p.next() != null ) {
8711                 return false;
8712             }
8713             //
8714             final String p3_str = "((A,B),C)abc";
8715             p.setSource( p3_str );
8716             if ( !p.hasNext() ) {
8717                 return false;
8718             }
8719             final Phylogeny p3_0 = p.next();
8720             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8721                 return false;
8722             }
8723             if ( p.hasNext() ) {
8724                 return false;
8725             }
8726             if ( p.next() != null ) {
8727                 return false;
8728             }
8729             //
8730             final String p4_str = "((A,B)ab,C)abc";
8731             p.setSource( p4_str );
8732             if ( !p.hasNext() ) {
8733                 return false;
8734             }
8735             final Phylogeny p4_0 = p.next();
8736             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8737                 return false;
8738             }
8739             if ( p.hasNext() ) {
8740                 return false;
8741             }
8742             if ( p.next() != null ) {
8743                 return false;
8744             }
8745             //
8746             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8747             p.setSource( p5_str );
8748             if ( !p.hasNext() ) {
8749                 return false;
8750             }
8751             final Phylogeny p5_0 = p.next();
8752             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8753                 return false;
8754             }
8755             if ( p.hasNext() ) {
8756                 return false;
8757             }
8758             if ( p.next() != null ) {
8759                 return false;
8760             }
8761             //
8762             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8763             p.setSource( p6_str );
8764             if ( !p.hasNext() ) {
8765                 return false;
8766             }
8767             Phylogeny p6_0 = p.next();
8768             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8769                 return false;
8770             }
8771             if ( p.hasNext() ) {
8772                 return false;
8773             }
8774             if ( p.next() != null ) {
8775                 return false;
8776             }
8777             p.reset();
8778             if ( !p.hasNext() ) {
8779                 return false;
8780             }
8781             p6_0 = p.next();
8782             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8783                 return false;
8784             }
8785             if ( p.hasNext() ) {
8786                 return false;
8787             }
8788             if ( p.next() != null ) {
8789                 return false;
8790             }
8791             //
8792             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8793             p.setSource( p7_str );
8794             if ( !p.hasNext() ) {
8795                 return false;
8796             }
8797             Phylogeny p7_0 = p.next();
8798             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8799                 return false;
8800             }
8801             if ( p.hasNext() ) {
8802                 return false;
8803             }
8804             if ( p.next() != null ) {
8805                 return false;
8806             }
8807             p.reset();
8808             if ( !p.hasNext() ) {
8809                 return false;
8810             }
8811             p7_0 = p.next();
8812             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8813                 return false;
8814             }
8815             if ( p.hasNext() ) {
8816                 return false;
8817             }
8818             if ( p.next() != null ) {
8819                 return false;
8820             }
8821             //
8822             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8823             p.setSource( p8_str );
8824             if ( !p.hasNext() ) {
8825                 return false;
8826             }
8827             Phylogeny p8_0 = p.next();
8828             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8829                 return false;
8830             }
8831             if ( !p.hasNext() ) {
8832                 return false;
8833             }
8834             if ( !p.hasNext() ) {
8835                 return false;
8836             }
8837             Phylogeny p8_1 = p.next();
8838             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8839                 return false;
8840             }
8841             if ( p.hasNext() ) {
8842                 return false;
8843             }
8844             if ( p.next() != null ) {
8845                 return false;
8846             }
8847             p.reset();
8848             if ( !p.hasNext() ) {
8849                 return false;
8850             }
8851             p8_0 = p.next();
8852             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8853                 return false;
8854             }
8855             if ( !p.hasNext() ) {
8856                 return false;
8857             }
8858             p8_1 = p.next();
8859             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8860                 return false;
8861             }
8862             if ( p.hasNext() ) {
8863                 return false;
8864             }
8865             if ( p.next() != null ) {
8866                 return false;
8867             }
8868             p.reset();
8869             //
8870             p.setSource( "" );
8871             if ( p.hasNext() ) {
8872                 return false;
8873             }
8874             //
8875             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8876             if ( !p.hasNext() ) {
8877                 return false;
8878             }
8879             Phylogeny p_27 = p.next();
8880             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8881                 System.out.println( p_27.toNewHampshireX() );
8882                 System.exit( -1 );
8883                 return false;
8884             }
8885             if ( p.hasNext() ) {
8886                 return false;
8887             }
8888             if ( p.next() != null ) {
8889                 return false;
8890             }
8891             p.reset();
8892             if ( !p.hasNext() ) {
8893                 return false;
8894             }
8895             p_27 = p.next();
8896             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8897                 System.out.println( p_27.toNewHampshireX() );
8898                 System.exit( -1 );
8899                 return false;
8900             }
8901             if ( p.hasNext() ) {
8902                 return false;
8903             }
8904             if ( p.next() != null ) {
8905                 return false;
8906             }
8907             //
8908             final String p30_str = "(A,B);(C,D)";
8909             final NHXParser p30 = new NHXParser();
8910             p30.setSource( p30_str );
8911             if ( !p30.hasNext() ) {
8912                 return false;
8913             }
8914             Phylogeny phy30 = p30.next();
8915             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8916                 System.out.println( phy30.toNewHampshire() );
8917                 return false;
8918             }
8919             if ( !p30.hasNext() ) {
8920                 return false;
8921             }
8922             Phylogeny phy301 = p30.next();
8923             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8924                 System.out.println( phy301.toNewHampshire() );
8925                 return false;
8926             }
8927             if ( p30.hasNext() ) {
8928                 return false;
8929             }
8930             if ( p30.hasNext() ) {
8931                 return false;
8932             }
8933             if ( p30.next() != null ) {
8934                 return false;
8935             }
8936             if ( p30.next() != null ) {
8937                 return false;
8938             }
8939             p30.reset();
8940             if ( !p30.hasNext() ) {
8941                 return false;
8942             }
8943             phy30 = p30.next();
8944             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8945                 System.out.println( phy30.toNewHampshire() );
8946                 return false;
8947             }
8948             if ( !p30.hasNext() ) {
8949                 return false;
8950             }
8951             phy301 = p30.next();
8952             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8953                 System.out.println( phy301.toNewHampshire() );
8954                 return false;
8955             }
8956             if ( p30.hasNext() ) {
8957                 return false;
8958             }
8959             if ( p30.hasNext() ) {
8960                 return false;
8961             }
8962             if ( p30.next() != null ) {
8963                 return false;
8964             }
8965             if ( p30.next() != null ) {
8966                 return false;
8967             }
8968         }
8969         catch ( final Exception e ) {
8970             e.printStackTrace( System.out );
8971             return false;
8972         }
8973         return true;
8974     }
8975
8976     private static boolean testNHXconversion() {
8977         try {
8978             final PhylogenyNode n1 = new PhylogenyNode();
8979             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8980             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8981             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8982             final PhylogenyNode n5 = PhylogenyNode
8983                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8984             final PhylogenyNode n6 = PhylogenyNode
8985                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8986             if ( !n1.toNewHampshireX().equals( "" ) ) {
8987                 return false;
8988             }
8989             if ( !n2.toNewHampshireX().equals( "" ) ) {
8990                 return false;
8991             }
8992             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8993                 return false;
8994             }
8995             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8996                 return false;
8997             }
8998             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8999                 return false;
9000             }
9001             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9002                 System.out.println( n6.toNewHampshireX() );
9003                 return false;
9004             }
9005             final PhylogenyNode n7 = new PhylogenyNode();
9006             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9007             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9008                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9009                 System.out.println( n7
9010                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9011                 return false;
9012             }
9013         }
9014         catch ( final Exception e ) {
9015             e.printStackTrace( System.out );
9016             return false;
9017         }
9018         return true;
9019     }
9020
9021     private static boolean testNHXNodeParsing() {
9022         try {
9023             final PhylogenyNode n1 = new PhylogenyNode();
9024             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9025             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9026             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9027             final PhylogenyNode n5 = PhylogenyNode
9028                     .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]" );
9029             if ( !n3.getName().equals( "n3" ) ) {
9030                 return false;
9031             }
9032             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9033                 return false;
9034             }
9035             if ( n3.isDuplication() ) {
9036                 return false;
9037             }
9038             if ( n3.isHasAssignedEvent() ) {
9039                 return false;
9040             }
9041             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9042                 return false;
9043             }
9044             if ( !n4.getName().equals( "n4" ) ) {
9045                 return false;
9046             }
9047             if ( n4.getDistanceToParent() != 0.01 ) {
9048                 return false;
9049             }
9050             if ( !n5.getName().equals( "n5" ) ) {
9051                 return false;
9052             }
9053             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9054                 return false;
9055             }
9056             if ( n5.getDistanceToParent() != 0.1 ) {
9057                 return false;
9058             }
9059             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9060                 return false;
9061             }
9062             if ( !n5.isDuplication() ) {
9063                 return false;
9064             }
9065             if ( !n5.isHasAssignedEvent() ) {
9066                 return false;
9067             }
9068             final PhylogenyNode n8 = PhylogenyNode
9069                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9070                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9071             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9072                 return false;
9073             }
9074             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9075                 return false;
9076             }
9077             final PhylogenyNode n9 = PhylogenyNode
9078                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9079                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9080             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9081                 return false;
9082             }
9083             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9084                 return false;
9085             }
9086             final PhylogenyNode n10 = PhylogenyNode
9087                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9088             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9089                 return false;
9090             }
9091             final PhylogenyNode n20 = PhylogenyNode
9092                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9093             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9094                 return false;
9095             }
9096             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9097                 return false;
9098             }
9099             final PhylogenyNode n20x = PhylogenyNode
9100                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9101             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9102                 return false;
9103             }
9104             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9105                 return false;
9106             }
9107             final PhylogenyNode n20xx = PhylogenyNode
9108                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9109             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9110                 return false;
9111             }
9112             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9113                 return false;
9114             }
9115             final PhylogenyNode n20xxx = PhylogenyNode
9116                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9117             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9118                 return false;
9119             }
9120             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9121                 return false;
9122             }
9123             final PhylogenyNode n20xxxx = PhylogenyNode
9124                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9125             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9126                 return false;
9127             }
9128             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9129                 return false;
9130             }
9131             final PhylogenyNode n21 = PhylogenyNode
9132                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9133             if ( !n21.getName().equals( "N21_PIG" ) ) {
9134                 return false;
9135             }
9136             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9137                 return false;
9138             }
9139             final PhylogenyNode n21x = PhylogenyNode
9140                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9141             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9142                 return false;
9143             }
9144             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9145                 return false;
9146             }
9147             final PhylogenyNode n22 = PhylogenyNode
9148                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9149             if ( !n22.getName().equals( "n22/PIG" ) ) {
9150                 return false;
9151             }
9152             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9153                 return false;
9154             }
9155             final PhylogenyNode n23 = PhylogenyNode
9156                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9157             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9158                 return false;
9159             }
9160             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9161                 return false;
9162             }
9163             final PhylogenyNode a = PhylogenyNode
9164                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9165             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9166                 return false;
9167             }
9168             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9169                 return false;
9170             }
9171             final PhylogenyNode c1 = PhylogenyNode
9172                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9173                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9174             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9175                 return false;
9176             }
9177             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9178                 return false;
9179             }
9180             final PhylogenyNode c2 = PhylogenyNode
9181                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9182                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9183             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9184                 return false;
9185             }
9186             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9187                 return false;
9188             }
9189             final PhylogenyNode e3 = PhylogenyNode
9190                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9191             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9192                 return false;
9193             }
9194             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9195                 return false;
9196             }
9197             final PhylogenyNode n11 = PhylogenyNode
9198                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9199                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9200             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9201                 return false;
9202             }
9203             if ( n11.getDistanceToParent() != 0.4 ) {
9204                 return false;
9205             }
9206             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9207                 return false;
9208             }
9209             final PhylogenyNode n12 = PhylogenyNode
9210                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9211                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9212             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9213                 return false;
9214             }
9215             if ( n12.getDistanceToParent() != 0.4 ) {
9216                 return false;
9217             }
9218             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9219                 return false;
9220             }
9221             final PhylogenyNode o = PhylogenyNode
9222                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9223             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9224                 return false;
9225             }
9226             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9227                 return false;
9228             }
9229             if ( n1.getName().compareTo( "" ) != 0 ) {
9230                 return false;
9231             }
9232             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9233                 return false;
9234             }
9235             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9236                 return false;
9237             }
9238             if ( n2.getName().compareTo( "" ) != 0 ) {
9239                 return false;
9240             }
9241             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9242                 return false;
9243             }
9244             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9245                 return false;
9246             }
9247             final PhylogenyNode n00 = PhylogenyNode
9248                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9249             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9250                 return false;
9251             }
9252             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9253                 return false;
9254             }
9255             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9256             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9257                 return false;
9258             }
9259             final PhylogenyNode n13 = PhylogenyNode
9260                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9261             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9262                 return false;
9263             }
9264             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9265                 return false;
9266             }
9267             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9268                 return false;
9269             }
9270             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9271                 return false;
9272             }
9273             final PhylogenyNode n14 = PhylogenyNode
9274                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9275             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9276                 return false;
9277             }
9278             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9279                 return false;
9280             }
9281             final PhylogenyNode n15 = PhylogenyNode
9282                     .createInstanceFromNhxString( "something_wicked[123]",
9283                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9284             if ( !n15.getName().equals( "something_wicked" ) ) {
9285                 return false;
9286             }
9287             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9288                 return false;
9289             }
9290             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9291                 return false;
9292             }
9293             final PhylogenyNode n16 = PhylogenyNode
9294                     .createInstanceFromNhxString( "something_wicked2[9]",
9295                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9296             if ( !n16.getName().equals( "something_wicked2" ) ) {
9297                 return false;
9298             }
9299             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9300                 return false;
9301             }
9302             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9303                 return false;
9304             }
9305             final PhylogenyNode n17 = PhylogenyNode
9306                     .createInstanceFromNhxString( "something_wicked3[a]",
9307                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9308             if ( !n17.getName().equals( "something_wicked3" ) ) {
9309                 return false;
9310             }
9311             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9312                 return false;
9313             }
9314             final PhylogenyNode n18 = PhylogenyNode
9315                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9316             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9317                 return false;
9318             }
9319             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9320                 return false;
9321             }
9322             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9323                 return false;
9324             }
9325             final PhylogenyNode n19 = PhylogenyNode
9326                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9327             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9328                 return false;
9329             }
9330             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9331                 return false;
9332             }
9333             final PhylogenyNode n30 = PhylogenyNode
9334                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9335                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9336             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9337                 return false;
9338             }
9339             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9340                 return false;
9341             }
9342             final PhylogenyNode n31 = PhylogenyNode
9343                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9344                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9345             if ( n31.getNodeData().isHasTaxonomy() ) {
9346                 return false;
9347             }
9348             final PhylogenyNode n32 = PhylogenyNode
9349                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9350             if ( n32.getNodeData().isHasTaxonomy() ) {
9351                 return false;
9352             }
9353             final PhylogenyNode n40 = PhylogenyNode
9354                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9355             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9356                 return false;
9357             }
9358             final PhylogenyNode n41 = PhylogenyNode
9359                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9360             if ( n41.getNodeData().isHasTaxonomy() ) {
9361                 return false;
9362             }
9363             final PhylogenyNode n42 = PhylogenyNode
9364                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9365             if ( n42.getNodeData().isHasTaxonomy() ) {
9366                 return false;
9367             }
9368             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9369                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9370             if ( n43.getNodeData().isHasTaxonomy() ) {
9371                 return false;
9372             }
9373             final PhylogenyNode n44 = PhylogenyNode
9374                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9375             if ( n44.getNodeData().isHasTaxonomy() ) {
9376                 return false;
9377             }
9378         }
9379         catch ( final Exception e ) {
9380             e.printStackTrace( System.out );
9381             return false;
9382         }
9383         return true;
9384     }
9385
9386     private static boolean testNHXParsing() {
9387         try {
9388             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9389             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9390             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9391                 return false;
9392             }
9393             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]";
9394             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9395             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9396                 return false;
9397             }
9398             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]";
9399             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9400             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9401                 return false;
9402             }
9403             final Phylogeny[] p3 = factory
9404                     .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]",
9405                              new NHXParser() );
9406             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9407                 return false;
9408             }
9409             final Phylogeny[] p4 = factory
9410                     .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(]",
9411                              new NHXParser() );
9412             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9413                 return false;
9414             }
9415             final Phylogeny[] p5 = factory
9416                     .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(((]",
9417                              new NHXParser() );
9418             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9419                 return false;
9420             }
9421             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)";
9422             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)";
9423             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9424             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9425                 return false;
9426             }
9427             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)))";
9428             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)))";
9429             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9430             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9431                 return false;
9432             }
9433             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])   ))[,,, ])))))))";
9434             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9435             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9436             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9437                 return false;
9438             }
9439             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9440             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9441                 return false;
9442             }
9443             final Phylogeny p10 = factory
9444                     .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]",
9445                              new NHXParser() )[ 0 ];
9446             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9447                 return false;
9448             }
9449             final Phylogeny p11 = factory
9450                     .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]",
9451                              new NHXParser() )[ 0 ];
9452             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9453                 return false;
9454             }
9455             final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
9456                                                   new NHXParser() )[ 0 ];
9457             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9458                 return false;
9459             }
9460         }
9461         catch ( final Exception e ) {
9462             e.printStackTrace( System.out );
9463             return false;
9464         }
9465         return true;
9466     }
9467
9468     private static boolean testNHXParsingMB() {
9469         try {
9470             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9471             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9472                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9473                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9474                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9475                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9476                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9477                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9478                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9479                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9480             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9481                 return false;
9482             }
9483             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9484                 return false;
9485             }
9486             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9487                            0.1100000000000000e+00 ) ) {
9488                 return false;
9489             }
9490             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9491                 return false;
9492             }
9493             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9494                 return false;
9495             }
9496             final Phylogeny p2 = factory
9497                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9498                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9499                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9500                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9501                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9502                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9503                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9504                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9505                                      + "7.369400000000000e-02}])",
9506                              new NHXParser() )[ 0 ];
9507             if ( p2.getNode( "1" ) == null ) {
9508                 return false;
9509             }
9510             if ( p2.getNode( "2" ) == null ) {
9511                 return false;
9512             }
9513         }
9514         catch ( final Exception e ) {
9515             e.printStackTrace( System.out );
9516             System.exit( -1 );
9517             return false;
9518         }
9519         return true;
9520     }
9521
9522     private static boolean testNHXParsingQuotes() {
9523         try {
9524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9525             final NHXParser p = new NHXParser();
9526             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9527             if ( phylogenies_0.length != 5 ) {
9528                 return false;
9529             }
9530             final Phylogeny phy = phylogenies_0[ 4 ];
9531             if ( phy.getNumberOfExternalNodes() != 7 ) {
9532                 return false;
9533             }
9534             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9535                 return false;
9536             }
9537             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9538                 return false;
9539             }
9540             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9541                     .getScientificName().equals( "hsapiens" ) ) {
9542                 return false;
9543             }
9544             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9545                 return false;
9546             }
9547             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9548                 return false;
9549             }
9550             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9551                 return false;
9552             }
9553             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9554                 return false;
9555             }
9556             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9557                 return false;
9558             }
9559             final NHXParser p1p = new NHXParser();
9560             p1p.setIgnoreQuotes( true );
9561             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9562             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9563                 return false;
9564             }
9565             final NHXParser p2p = new NHXParser();
9566             p1p.setIgnoreQuotes( false );
9567             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9568             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9569                 return false;
9570             }
9571             final NHXParser p3p = new NHXParser();
9572             p3p.setIgnoreQuotes( false );
9573             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9574             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9575                 return false;
9576             }
9577             final NHXParser p4p = new NHXParser();
9578             p4p.setIgnoreQuotes( false );
9579             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9580             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9581                 return false;
9582             }
9583             final Phylogeny p10 = factory
9584                     .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]",
9585                              new NHXParser() )[ 0 ];
9586             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]";
9587             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9588                 return false;
9589             }
9590             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9591             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9592                 return false;
9593             }
9594             final Phylogeny p12 = factory
9595                     .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]",
9596                              new NHXParser() )[ 0 ];
9597             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]";
9598             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9599                 return false;
9600             }
9601             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9602             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9603                 return false;
9604             }
9605             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;";
9606             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9607                 return false;
9608             }
9609             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9610             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9611                 return false;
9612             }
9613         }
9614         catch ( final Exception e ) {
9615             e.printStackTrace( System.out );
9616             return false;
9617         }
9618         return true;
9619     }
9620
9621     private static boolean testNodeRemoval() {
9622         try {
9623             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9624             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9625             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9626             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9627                 return false;
9628             }
9629             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9630             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9631             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9632                 return false;
9633             }
9634             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9635             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9636             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9637                 return false;
9638             }
9639         }
9640         catch ( final Exception e ) {
9641             e.printStackTrace( System.out );
9642             return false;
9643         }
9644         return true;
9645     }
9646
9647     private static boolean testPhylogenyBranch() {
9648         try {
9649             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9650             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9651             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9652             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9653             if ( !a1b1.equals( a1b1 ) ) {
9654                 return false;
9655             }
9656             if ( !a1b1.equals( b1a1 ) ) {
9657                 return false;
9658             }
9659             if ( !b1a1.equals( a1b1 ) ) {
9660                 return false;
9661             }
9662             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9663             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9664             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9665             if ( a1_b1.equals( b1_a1 ) ) {
9666                 return false;
9667             }
9668             if ( a1_b1.equals( a1_b1_ ) ) {
9669                 return false;
9670             }
9671             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9672             if ( !a1_b1.equals( b1_a1_ ) ) {
9673                 return false;
9674             }
9675             if ( a1_b1_.equals( b1_a1_ ) ) {
9676                 return false;
9677             }
9678             if ( !a1_b1_.equals( b1_a1 ) ) {
9679                 return false;
9680             }
9681         }
9682         catch ( final Exception e ) {
9683             e.printStackTrace( System.out );
9684             return false;
9685         }
9686         return true;
9687     }
9688
9689     private static boolean testPhyloXMLparsingOfDistributionElement() {
9690         try {
9691             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9692             PhyloXmlParser xml_parser = null;
9693             try {
9694                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9695             }
9696             catch ( final Exception e ) {
9697                 // Do nothing -- means were not running from jar.
9698             }
9699             if ( xml_parser == null ) {
9700                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9701                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9702                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9703                 }
9704                 else {
9705                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9706                 }
9707             }
9708             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9709                                                               xml_parser );
9710             if ( xml_parser.getErrorCount() > 0 ) {
9711                 System.out.println( xml_parser.getErrorMessages().toString() );
9712                 return false;
9713             }
9714             if ( phylogenies_0.length != 1 ) {
9715                 return false;
9716             }
9717             final Phylogeny t1 = phylogenies_0[ 0 ];
9718             PhylogenyNode n = null;
9719             Distribution d = null;
9720             n = t1.getNode( "root node" );
9721             if ( !n.getNodeData().isHasDistribution() ) {
9722                 return false;
9723             }
9724             if ( n.getNodeData().getDistributions().size() != 1 ) {
9725                 return false;
9726             }
9727             d = n.getNodeData().getDistribution();
9728             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9729                 return false;
9730             }
9731             if ( d.getPoints().size() != 1 ) {
9732                 return false;
9733             }
9734             if ( d.getPolygons() != null ) {
9735                 return false;
9736             }
9737             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9738                 return false;
9739             }
9740             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9741                 return false;
9742             }
9743             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9744                 return false;
9745             }
9746             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9747                 return false;
9748             }
9749             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9750                 return false;
9751             }
9752             n = t1.getNode( "node a" );
9753             if ( !n.getNodeData().isHasDistribution() ) {
9754                 return false;
9755             }
9756             if ( n.getNodeData().getDistributions().size() != 2 ) {
9757                 return false;
9758             }
9759             d = n.getNodeData().getDistribution( 1 );
9760             if ( !d.getDesc().equals( "San Diego" ) ) {
9761                 return false;
9762             }
9763             if ( d.getPoints().size() != 1 ) {
9764                 return false;
9765             }
9766             if ( d.getPolygons() != null ) {
9767                 return false;
9768             }
9769             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9770                 return false;
9771             }
9772             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9773                 return false;
9774             }
9775             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9776                 return false;
9777             }
9778             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9779                 return false;
9780             }
9781             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9782                 return false;
9783             }
9784             n = t1.getNode( "node bb" );
9785             if ( !n.getNodeData().isHasDistribution() ) {
9786                 return false;
9787             }
9788             if ( n.getNodeData().getDistributions().size() != 1 ) {
9789                 return false;
9790             }
9791             d = n.getNodeData().getDistribution( 0 );
9792             if ( d.getPoints().size() != 3 ) {
9793                 return false;
9794             }
9795             if ( d.getPolygons().size() != 2 ) {
9796                 return false;
9797             }
9798             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9799                 return false;
9800             }
9801             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9802                 return false;
9803             }
9804             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9805                 return false;
9806             }
9807             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9808                 return false;
9809             }
9810             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9811                 return false;
9812             }
9813             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9814                 return false;
9815             }
9816             Polygon p = d.getPolygons().get( 0 );
9817             if ( p.getPoints().size() != 3 ) {
9818                 return false;
9819             }
9820             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9821                 return false;
9822             }
9823             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9824                 return false;
9825             }
9826             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9827                 return false;
9828             }
9829             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9830                 return false;
9831             }
9832             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9833                 return false;
9834             }
9835             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9836                 return false;
9837             }
9838             p = d.getPolygons().get( 1 );
9839             if ( p.getPoints().size() != 3 ) {
9840                 return false;
9841             }
9842             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9843                 return false;
9844             }
9845             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9846                 return false;
9847             }
9848             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9849                 return false;
9850             }
9851             // Roundtrip:
9852             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9853             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9854             if ( rt.length != 1 ) {
9855                 return false;
9856             }
9857             final Phylogeny t1_rt = rt[ 0 ];
9858             n = t1_rt.getNode( "root node" );
9859             if ( !n.getNodeData().isHasDistribution() ) {
9860                 return false;
9861             }
9862             if ( n.getNodeData().getDistributions().size() != 1 ) {
9863                 return false;
9864             }
9865             d = n.getNodeData().getDistribution();
9866             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9867                 return false;
9868             }
9869             if ( d.getPoints().size() != 1 ) {
9870                 return false;
9871             }
9872             if ( d.getPolygons() != null ) {
9873                 return false;
9874             }
9875             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9876                 return false;
9877             }
9878             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9879                 return false;
9880             }
9881             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9882                 return false;
9883             }
9884             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9885                 return false;
9886             }
9887             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9888                 return false;
9889             }
9890             n = t1_rt.getNode( "node a" );
9891             if ( !n.getNodeData().isHasDistribution() ) {
9892                 return false;
9893             }
9894             if ( n.getNodeData().getDistributions().size() != 2 ) {
9895                 return false;
9896             }
9897             d = n.getNodeData().getDistribution( 1 );
9898             if ( !d.getDesc().equals( "San Diego" ) ) {
9899                 return false;
9900             }
9901             if ( d.getPoints().size() != 1 ) {
9902                 return false;
9903             }
9904             if ( d.getPolygons() != null ) {
9905                 return false;
9906             }
9907             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9908                 return false;
9909             }
9910             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9911                 return false;
9912             }
9913             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9914                 return false;
9915             }
9916             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9917                 return false;
9918             }
9919             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9920                 return false;
9921             }
9922             n = t1_rt.getNode( "node bb" );
9923             if ( !n.getNodeData().isHasDistribution() ) {
9924                 return false;
9925             }
9926             if ( n.getNodeData().getDistributions().size() != 1 ) {
9927                 return false;
9928             }
9929             d = n.getNodeData().getDistribution( 0 );
9930             if ( d.getPoints().size() != 3 ) {
9931                 return false;
9932             }
9933             if ( d.getPolygons().size() != 2 ) {
9934                 return false;
9935             }
9936             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9937                 return false;
9938             }
9939             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9940                 return false;
9941             }
9942             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9943                 return false;
9944             }
9945             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9946                 return false;
9947             }
9948             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9949                 return false;
9950             }
9951             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9952                 return false;
9953             }
9954             p = d.getPolygons().get( 0 );
9955             if ( p.getPoints().size() != 3 ) {
9956                 return false;
9957             }
9958             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9959                 return false;
9960             }
9961             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9962                 return false;
9963             }
9964             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9965                 return false;
9966             }
9967             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9968                 return false;
9969             }
9970             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9971                 return false;
9972             }
9973             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9974                 return false;
9975             }
9976             p = d.getPolygons().get( 1 );
9977             if ( p.getPoints().size() != 3 ) {
9978                 return false;
9979             }
9980             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9981                 return false;
9982             }
9983             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9984                 return false;
9985             }
9986             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9987                 return false;
9988             }
9989         }
9990         catch ( final Exception e ) {
9991             e.printStackTrace( System.out );
9992             return false;
9993         }
9994         return true;
9995     }
9996
9997     private static boolean testPostOrderIterator() {
9998         try {
9999             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10000             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10001             PhylogenyNodeIterator it0;
10002             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10003                 it0.next();
10004             }
10005             for( it0.reset(); it0.hasNext(); ) {
10006                 it0.next();
10007             }
10008             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10009             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10010             if ( !it.next().getName().equals( "A" ) ) {
10011                 return false;
10012             }
10013             if ( !it.next().getName().equals( "B" ) ) {
10014                 return false;
10015             }
10016             if ( !it.next().getName().equals( "ab" ) ) {
10017                 return false;
10018             }
10019             if ( !it.next().getName().equals( "C" ) ) {
10020                 return false;
10021             }
10022             if ( !it.next().getName().equals( "D" ) ) {
10023                 return false;
10024             }
10025             if ( !it.next().getName().equals( "cd" ) ) {
10026                 return false;
10027             }
10028             if ( !it.next().getName().equals( "abcd" ) ) {
10029                 return false;
10030             }
10031             if ( !it.next().getName().equals( "E" ) ) {
10032                 return false;
10033             }
10034             if ( !it.next().getName().equals( "F" ) ) {
10035                 return false;
10036             }
10037             if ( !it.next().getName().equals( "ef" ) ) {
10038                 return false;
10039             }
10040             if ( !it.next().getName().equals( "G" ) ) {
10041                 return false;
10042             }
10043             if ( !it.next().getName().equals( "H" ) ) {
10044                 return false;
10045             }
10046             if ( !it.next().getName().equals( "gh" ) ) {
10047                 return false;
10048             }
10049             if ( !it.next().getName().equals( "efgh" ) ) {
10050                 return false;
10051             }
10052             if ( !it.next().getName().equals( "r" ) ) {
10053                 return false;
10054             }
10055             if ( it.hasNext() ) {
10056                 return false;
10057             }
10058         }
10059         catch ( final Exception e ) {
10060             e.printStackTrace( System.out );
10061             return false;
10062         }
10063         return true;
10064     }
10065
10066     private static boolean testPreOrderIterator() {
10067         try {
10068             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10069             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10070             PhylogenyNodeIterator it0;
10071             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10072                 it0.next();
10073             }
10074             for( it0.reset(); it0.hasNext(); ) {
10075                 it0.next();
10076             }
10077             PhylogenyNodeIterator it = t0.iteratorPreorder();
10078             if ( !it.next().getName().equals( "r" ) ) {
10079                 return false;
10080             }
10081             if ( !it.next().getName().equals( "ab" ) ) {
10082                 return false;
10083             }
10084             if ( !it.next().getName().equals( "A" ) ) {
10085                 return false;
10086             }
10087             if ( !it.next().getName().equals( "B" ) ) {
10088                 return false;
10089             }
10090             if ( !it.next().getName().equals( "cd" ) ) {
10091                 return false;
10092             }
10093             if ( !it.next().getName().equals( "C" ) ) {
10094                 return false;
10095             }
10096             if ( !it.next().getName().equals( "D" ) ) {
10097                 return false;
10098             }
10099             if ( it.hasNext() ) {
10100                 return false;
10101             }
10102             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10103             it = t1.iteratorPreorder();
10104             if ( !it.next().getName().equals( "r" ) ) {
10105                 return false;
10106             }
10107             if ( !it.next().getName().equals( "abcd" ) ) {
10108                 return false;
10109             }
10110             if ( !it.next().getName().equals( "ab" ) ) {
10111                 return false;
10112             }
10113             if ( !it.next().getName().equals( "A" ) ) {
10114                 return false;
10115             }
10116             if ( !it.next().getName().equals( "B" ) ) {
10117                 return false;
10118             }
10119             if ( !it.next().getName().equals( "cd" ) ) {
10120                 return false;
10121             }
10122             if ( !it.next().getName().equals( "C" ) ) {
10123                 return false;
10124             }
10125             if ( !it.next().getName().equals( "D" ) ) {
10126                 return false;
10127             }
10128             if ( !it.next().getName().equals( "efgh" ) ) {
10129                 return false;
10130             }
10131             if ( !it.next().getName().equals( "ef" ) ) {
10132                 return false;
10133             }
10134             if ( !it.next().getName().equals( "E" ) ) {
10135                 return false;
10136             }
10137             if ( !it.next().getName().equals( "F" ) ) {
10138                 return false;
10139             }
10140             if ( !it.next().getName().equals( "gh" ) ) {
10141                 return false;
10142             }
10143             if ( !it.next().getName().equals( "G" ) ) {
10144                 return false;
10145             }
10146             if ( !it.next().getName().equals( "H" ) ) {
10147                 return false;
10148             }
10149             if ( it.hasNext() ) {
10150                 return false;
10151             }
10152         }
10153         catch ( final Exception e ) {
10154             e.printStackTrace( System.out );
10155             return false;
10156         }
10157         return true;
10158     }
10159
10160     private static boolean testPropertiesMap() {
10161         try {
10162             final PropertiesMap pm = new PropertiesMap();
10163             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10164             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10165             final Property p2 = new Property( "something:else",
10166                                               "?",
10167                                               "improbable:research",
10168                                               "xsd:decimal",
10169                                               AppliesTo.NODE );
10170             pm.addProperty( p0 );
10171             pm.addProperty( p1 );
10172             pm.addProperty( p2 );
10173             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10174                 return false;
10175             }
10176             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10177                 return false;
10178             }
10179             if ( pm.getProperties().size() != 3 ) {
10180                 return false;
10181             }
10182             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10183                 return false;
10184             }
10185             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10186                 return false;
10187             }
10188             if ( pm.getProperties().size() != 3 ) {
10189                 return false;
10190             }
10191             pm.removeProperty( "dimensions:diameter" );
10192             if ( pm.getProperties().size() != 2 ) {
10193                 return false;
10194             }
10195             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10196                 return false;
10197             }
10198             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10199                 return false;
10200             }
10201         }
10202         catch ( final Exception e ) {
10203             e.printStackTrace( System.out );
10204             return false;
10205         }
10206         return true;
10207     }
10208
10209     private static boolean testProteinId() {
10210         try {
10211             final ProteinId id1 = new ProteinId( "a" );
10212             final ProteinId id2 = new ProteinId( "a" );
10213             final ProteinId id3 = new ProteinId( "A" );
10214             final ProteinId id4 = new ProteinId( "b" );
10215             if ( !id1.equals( id1 ) ) {
10216                 return false;
10217             }
10218             if ( id1.getId().equals( "x" ) ) {
10219                 return false;
10220             }
10221             if ( id1.getId().equals( null ) ) {
10222                 return false;
10223             }
10224             if ( !id1.equals( id2 ) ) {
10225                 return false;
10226             }
10227             if ( id1.equals( id3 ) ) {
10228                 return false;
10229             }
10230             if ( id1.hashCode() != id1.hashCode() ) {
10231                 return false;
10232             }
10233             if ( id1.hashCode() != id2.hashCode() ) {
10234                 return false;
10235             }
10236             if ( id1.hashCode() == id3.hashCode() ) {
10237                 return false;
10238             }
10239             if ( id1.compareTo( id1 ) != 0 ) {
10240                 return false;
10241             }
10242             if ( id1.compareTo( id2 ) != 0 ) {
10243                 return false;
10244             }
10245             if ( id1.compareTo( id3 ) != 0 ) {
10246                 return false;
10247             }
10248             if ( id1.compareTo( id4 ) >= 0 ) {
10249                 return false;
10250             }
10251             if ( id4.compareTo( id1 ) <= 0 ) {
10252                 return false;
10253             }
10254             if ( !id4.getId().equals( "b" ) ) {
10255                 return false;
10256             }
10257             final ProteinId id5 = new ProteinId( " C " );
10258             if ( !id5.getId().equals( "C" ) ) {
10259                 return false;
10260             }
10261             if ( id5.equals( id1 ) ) {
10262                 return false;
10263             }
10264         }
10265         catch ( final Exception e ) {
10266             e.printStackTrace( System.out );
10267             return false;
10268         }
10269         return true;
10270     }
10271
10272     private static boolean testReIdMethods() {
10273         try {
10274             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10275             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10276             final long count = PhylogenyNode.getNodeCount();
10277             p.levelOrderReID();
10278             if ( p.getNode( "r" ).getId() != count ) {
10279                 return false;
10280             }
10281             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10282                 return false;
10283             }
10284             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10285                 return false;
10286             }
10287             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10288                 return false;
10289             }
10290             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10291                 return false;
10292             }
10293             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10294                 return false;
10295             }
10296             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10297                 return false;
10298             }
10299             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10300                 return false;
10301             }
10302             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10303                 return false;
10304             }
10305             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10306                 return false;
10307             }
10308             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10309                 return false;
10310             }
10311             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10312                 return false;
10313             }
10314             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10315                 return false;
10316             }
10317             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10318                 return false;
10319             }
10320             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10321                 return false;
10322             }
10323         }
10324         catch ( final Exception e ) {
10325             e.printStackTrace( System.out );
10326             return false;
10327         }
10328         return true;
10329     }
10330
10331     private static boolean testRerooting() {
10332         try {
10333             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10334             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",
10335                                                  new NHXParser() )[ 0 ];
10336             if ( !t1.isRooted() ) {
10337                 return false;
10338             }
10339             t1.reRoot( t1.getNode( "D" ) );
10340             t1.reRoot( t1.getNode( "CD" ) );
10341             t1.reRoot( t1.getNode( "A" ) );
10342             t1.reRoot( t1.getNode( "B" ) );
10343             t1.reRoot( t1.getNode( "AB" ) );
10344             t1.reRoot( t1.getNode( "D" ) );
10345             t1.reRoot( t1.getNode( "C" ) );
10346             t1.reRoot( t1.getNode( "CD" ) );
10347             t1.reRoot( t1.getNode( "A" ) );
10348             t1.reRoot( t1.getNode( "B" ) );
10349             t1.reRoot( t1.getNode( "AB" ) );
10350             t1.reRoot( t1.getNode( "D" ) );
10351             t1.reRoot( t1.getNode( "D" ) );
10352             t1.reRoot( t1.getNode( "C" ) );
10353             t1.reRoot( t1.getNode( "A" ) );
10354             t1.reRoot( t1.getNode( "B" ) );
10355             t1.reRoot( t1.getNode( "AB" ) );
10356             t1.reRoot( t1.getNode( "C" ) );
10357             t1.reRoot( t1.getNode( "D" ) );
10358             t1.reRoot( t1.getNode( "CD" ) );
10359             t1.reRoot( t1.getNode( "D" ) );
10360             t1.reRoot( t1.getNode( "A" ) );
10361             t1.reRoot( t1.getNode( "B" ) );
10362             t1.reRoot( t1.getNode( "AB" ) );
10363             t1.reRoot( t1.getNode( "C" ) );
10364             t1.reRoot( t1.getNode( "D" ) );
10365             t1.reRoot( t1.getNode( "CD" ) );
10366             t1.reRoot( t1.getNode( "D" ) );
10367             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10368                 return false;
10369             }
10370             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10371                 return false;
10372             }
10373             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10374                 return false;
10375             }
10376             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10377                 return false;
10378             }
10379             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10380                 return false;
10381             }
10382             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10383                 return false;
10384             }
10385             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",
10386                                                  new NHXParser() )[ 0 ];
10387             t2.reRoot( t2.getNode( "A" ) );
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( "D" ) );
10393             t2.reRoot( t2.getNode( "C" ) );
10394             t2.reRoot( t2.getNode( "ABC" ) );
10395             t2.reRoot( t2.getNode( "A" ) );
10396             t2.reRoot( t2.getNode( "B" ) );
10397             t2.reRoot( t2.getNode( "AB" ) );
10398             t2.reRoot( t2.getNode( "AB" ) );
10399             t2.reRoot( t2.getNode( "D" ) );
10400             t2.reRoot( t2.getNode( "C" ) );
10401             t2.reRoot( t2.getNode( "B" ) );
10402             t2.reRoot( t2.getNode( "AB" ) );
10403             t2.reRoot( t2.getNode( "D" ) );
10404             t2.reRoot( t2.getNode( "D" ) );
10405             t2.reRoot( t2.getNode( "ABC" ) );
10406             t2.reRoot( t2.getNode( "A" ) );
10407             t2.reRoot( t2.getNode( "B" ) );
10408             t2.reRoot( t2.getNode( "AB" ) );
10409             t2.reRoot( t2.getNode( "D" ) );
10410             t2.reRoot( t2.getNode( "C" ) );
10411             t2.reRoot( t2.getNode( "ABC" ) );
10412             t2.reRoot( t2.getNode( "A" ) );
10413             t2.reRoot( t2.getNode( "B" ) );
10414             t2.reRoot( t2.getNode( "AB" ) );
10415             t2.reRoot( t2.getNode( "D" ) );
10416             t2.reRoot( t2.getNode( "D" ) );
10417             t2.reRoot( t2.getNode( "C" ) );
10418             t2.reRoot( t2.getNode( "A" ) );
10419             t2.reRoot( t2.getNode( "B" ) );
10420             t2.reRoot( t2.getNode( "AB" ) );
10421             t2.reRoot( t2.getNode( "C" ) );
10422             t2.reRoot( t2.getNode( "D" ) );
10423             t2.reRoot( t2.getNode( "ABC" ) );
10424             t2.reRoot( t2.getNode( "D" ) );
10425             t2.reRoot( t2.getNode( "A" ) );
10426             t2.reRoot( t2.getNode( "B" ) );
10427             t2.reRoot( t2.getNode( "AB" ) );
10428             t2.reRoot( t2.getNode( "C" ) );
10429             t2.reRoot( t2.getNode( "D" ) );
10430             t2.reRoot( t2.getNode( "ABC" ) );
10431             t2.reRoot( t2.getNode( "D" ) );
10432             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10433                 return false;
10434             }
10435             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10436                 return false;
10437             }
10438             t2.reRoot( t2.getNode( "ABC" ) );
10439             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10440                 return false;
10441             }
10442             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10443                 return false;
10444             }
10445             t2.reRoot( t2.getNode( "AB" ) );
10446             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10447                 return false;
10448             }
10449             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10450                 return false;
10451             }
10452             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10453                 return false;
10454             }
10455             t2.reRoot( t2.getNode( "AB" ) );
10456             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10457                 return false;
10458             }
10459             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10460                 return false;
10461             }
10462             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10463                 return false;
10464             }
10465             t2.reRoot( t2.getNode( "D" ) );
10466             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10467                 return false;
10468             }
10469             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10470                 return false;
10471             }
10472             t2.reRoot( t2.getNode( "ABC" ) );
10473             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10474                 return false;
10475             }
10476             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10477                 return false;
10478             }
10479             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10480                                                  new NHXParser() )[ 0 ];
10481             t3.reRoot( t3.getNode( "B" ) );
10482             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10483                 return false;
10484             }
10485             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10486                 return false;
10487             }
10488             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10489                 return false;
10490             }
10491             t3.reRoot( t3.getNode( "B" ) );
10492             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10493                 return false;
10494             }
10495             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10496                 return false;
10497             }
10498             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10499                 return false;
10500             }
10501             t3.reRoot( t3.getRoot() );
10502             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10503                 return false;
10504             }
10505             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10506                 return false;
10507             }
10508             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10509                 return false;
10510             }
10511         }
10512         catch ( final Exception e ) {
10513             e.printStackTrace( System.out );
10514             return false;
10515         }
10516         return true;
10517     }
10518
10519     private static boolean testSDIse() {
10520         try {
10521             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10522             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10523             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10524             gene1.setRooted( true );
10525             species1.setRooted( true );
10526             final SDI sdi = new SDI( gene1, species1 );
10527             if ( !gene1.getRoot().isDuplication() ) {
10528                 return false;
10529             }
10530             final Phylogeny species2 = factory
10531                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10532                              new NHXParser() )[ 0 ];
10533             final Phylogeny gene2 = factory
10534                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10535                              new NHXParser() )[ 0 ];
10536             species2.setRooted( true );
10537             gene2.setRooted( true );
10538             final SDI sdi2 = new SDI( gene2, species2 );
10539             if ( sdi2.getDuplicationsSum() != 0 ) {
10540                 return false;
10541             }
10542             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10543                 return false;
10544             }
10545             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10546                 return false;
10547             }
10548             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10549                 return false;
10550             }
10551             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10552                 return false;
10553             }
10554             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10555                 return false;
10556             }
10557             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10558                 return false;
10559             }
10560             final Phylogeny species3 = factory
10561                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10562                              new NHXParser() )[ 0 ];
10563             final Phylogeny gene3 = factory
10564                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10565                              new NHXParser() )[ 0 ];
10566             species3.setRooted( true );
10567             gene3.setRooted( true );
10568             final SDI sdi3 = new SDI( gene3, species3 );
10569             if ( sdi3.getDuplicationsSum() != 1 ) {
10570                 return false;
10571             }
10572             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10573                 return false;
10574             }
10575             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10576                 return false;
10577             }
10578             final Phylogeny species4 = factory
10579                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10580                              new NHXParser() )[ 0 ];
10581             final Phylogeny gene4 = factory
10582                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10583                              new NHXParser() )[ 0 ];
10584             species4.setRooted( true );
10585             gene4.setRooted( true );
10586             final SDI sdi4 = new SDI( gene4, species4 );
10587             if ( sdi4.getDuplicationsSum() != 1 ) {
10588                 return false;
10589             }
10590             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10591                 return false;
10592             }
10593             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10594                 return false;
10595             }
10596             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10597                 return false;
10598             }
10599             if ( species4.getNumberOfExternalNodes() != 6 ) {
10600                 return false;
10601             }
10602             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10603                 return false;
10604             }
10605             final Phylogeny species5 = factory
10606                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10607                              new NHXParser() )[ 0 ];
10608             final Phylogeny gene5 = factory
10609                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10610                              new NHXParser() )[ 0 ];
10611             species5.setRooted( true );
10612             gene5.setRooted( true );
10613             final SDI sdi5 = new SDI( gene5, species5 );
10614             if ( sdi5.getDuplicationsSum() != 2 ) {
10615                 return false;
10616             }
10617             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10618                 return false;
10619             }
10620             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10621                 return false;
10622             }
10623             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10624                 return false;
10625             }
10626             if ( species5.getNumberOfExternalNodes() != 6 ) {
10627                 return false;
10628             }
10629             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10630                 return false;
10631             }
10632             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10633             // Conjecture for Comparing Molecular Phylogenies"
10634             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10635             final Phylogeny species6 = factory
10636                     .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,"
10637                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10638                              new NHXParser() )[ 0 ];
10639             final Phylogeny gene6 = factory
10640                     .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,"
10641                                      + "((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,"
10642                                      + "(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;",
10643                              new NHXParser() )[ 0 ];
10644             species6.setRooted( true );
10645             gene6.setRooted( true );
10646             final SDI sdi6 = new SDI( gene6, species6 );
10647             if ( sdi6.getDuplicationsSum() != 3 ) {
10648                 return false;
10649             }
10650             if ( !gene6.getNode( "r" ).isDuplication() ) {
10651                 return false;
10652             }
10653             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10654                 return false;
10655             }
10656             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10657                 return false;
10658             }
10659             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10660                 return false;
10661             }
10662             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10663                 return false;
10664             }
10665             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10666                 return false;
10667             }
10668             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10669                 return false;
10670             }
10671             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10672                 return false;
10673             }
10674             sdi6.computeMappingCostL();
10675             if ( sdi6.computeMappingCostL() != 17 ) {
10676                 return false;
10677             }
10678             if ( species6.getNumberOfExternalNodes() != 9 ) {
10679                 return false;
10680             }
10681             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10682                 return false;
10683             }
10684             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10685                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10686                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10687                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10688                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10689             species7.setRooted( true );
10690             final Phylogeny gene7_1 = Test
10691                     .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])" );
10692             gene7_1.setRooted( true );
10693             final SDI sdi7 = new SDI( gene7_1, species7 );
10694             if ( sdi7.getDuplicationsSum() != 0 ) {
10695                 return false;
10696             }
10697             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10698                 return false;
10699             }
10700             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10701                 return false;
10702             }
10703             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10704                 return false;
10705             }
10706             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10707                 return false;
10708             }
10709             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10710                 return false;
10711             }
10712             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10713                 return false;
10714             }
10715             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10716                 return false;
10717             }
10718             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10719                 return false;
10720             }
10721             final Phylogeny gene7_2 = Test
10722                     .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])" );
10723             gene7_2.setRooted( true );
10724             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10725             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10726                 return false;
10727             }
10728             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10729                 return false;
10730             }
10731             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10732                 return false;
10733             }
10734             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10735                 return false;
10736             }
10737             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10738                 return false;
10739             }
10740             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10741                 return false;
10742             }
10743             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10744                 return false;
10745             }
10746             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10747                 return false;
10748             }
10749             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10750                 return false;
10751             }
10752             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10753                 return false;
10754             }
10755         }
10756         catch ( final Exception e ) {
10757             return false;
10758         }
10759         return true;
10760     }
10761
10762     private static boolean testSDIunrooted() {
10763         try {
10764             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10765             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10766             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10767             final Iterator<PhylogenyBranch> iter = l.iterator();
10768             PhylogenyBranch br = iter.next();
10769             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10770                 return false;
10771             }
10772             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10773                 return false;
10774             }
10775             br = iter.next();
10776             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10777                 return false;
10778             }
10779             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10780                 return false;
10781             }
10782             br = iter.next();
10783             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10784                 return false;
10785             }
10786             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10787                 return false;
10788             }
10789             br = iter.next();
10790             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10791                 return false;
10792             }
10793             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10794                 return false;
10795             }
10796             br = iter.next();
10797             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10798                 return false;
10799             }
10800             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10801                 return false;
10802             }
10803             br = iter.next();
10804             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10805                 return false;
10806             }
10807             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10808                 return false;
10809             }
10810             br = iter.next();
10811             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10812                 return false;
10813             }
10814             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10815                 return false;
10816             }
10817             br = iter.next();
10818             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10819                 return false;
10820             }
10821             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10822                 return false;
10823             }
10824             br = iter.next();
10825             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10826                 return false;
10827             }
10828             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10829                 return false;
10830             }
10831             br = iter.next();
10832             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10833                 return false;
10834             }
10835             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10836                 return false;
10837             }
10838             br = iter.next();
10839             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10840                 return false;
10841             }
10842             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10843                 return false;
10844             }
10845             br = iter.next();
10846             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10847                 return false;
10848             }
10849             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10850                 return false;
10851             }
10852             br = iter.next();
10853             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10854                 return false;
10855             }
10856             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10857                 return false;
10858             }
10859             br = iter.next();
10860             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10861                 return false;
10862             }
10863             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10864                 return false;
10865             }
10866             br = iter.next();
10867             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10868                 return false;
10869             }
10870             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10871                 return false;
10872             }
10873             if ( iter.hasNext() ) {
10874                 return false;
10875             }
10876             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10877             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10878             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10879             br = iter1.next();
10880             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10881                 return false;
10882             }
10883             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10884                 return false;
10885             }
10886             br = iter1.next();
10887             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10888                 return false;
10889             }
10890             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10891                 return false;
10892             }
10893             br = iter1.next();
10894             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10895                 return false;
10896             }
10897             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10898                 return false;
10899             }
10900             if ( iter1.hasNext() ) {
10901                 return false;
10902             }
10903             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10904             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10905             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10906             br = iter2.next();
10907             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10908                 return false;
10909             }
10910             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10911                 return false;
10912             }
10913             br = iter2.next();
10914             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10915                 return false;
10916             }
10917             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10918                 return false;
10919             }
10920             br = iter2.next();
10921             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10922                 return false;
10923             }
10924             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10925                 return false;
10926             }
10927             if ( iter2.hasNext() ) {
10928                 return false;
10929             }
10930             final Phylogeny species0 = factory
10931                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10932                              new NHXParser() )[ 0 ];
10933             final Phylogeny gene1 = factory
10934                     .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])",
10935                              new NHXParser() )[ 0 ];
10936             species0.setRooted( true );
10937             gene1.setRooted( true );
10938             final SDIR sdi_unrooted = new SDIR();
10939             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10940             if ( sdi_unrooted.getCount() != 1 ) {
10941                 return false;
10942             }
10943             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10944                 return false;
10945             }
10946             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10947                 return false;
10948             }
10949             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10950                 return false;
10951             }
10952             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10953                 return false;
10954             }
10955             final Phylogeny gene2 = factory
10956                     .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])",
10957                              new NHXParser() )[ 0 ];
10958             gene2.setRooted( true );
10959             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10960             if ( sdi_unrooted.getCount() != 1 ) {
10961                 return false;
10962             }
10963             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10964                 return false;
10965             }
10966             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10967                 return false;
10968             }
10969             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10970                 return false;
10971             }
10972             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10973                 return false;
10974             }
10975             final Phylogeny species6 = factory
10976                     .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,"
10977                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10978                              new NHXParser() )[ 0 ];
10979             final Phylogeny gene6 = factory
10980                     .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],"
10981                                      + "(((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],"
10982                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10983                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10984                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10985                              new NHXParser() )[ 0 ];
10986             species6.setRooted( true );
10987             gene6.setRooted( true );
10988             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10989             if ( sdi_unrooted.getCount() != 1 ) {
10990                 return false;
10991             }
10992             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10993                 return false;
10994             }
10995             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10996                 return false;
10997             }
10998             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10999                 return false;
11000             }
11001             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11002                 return false;
11003             }
11004             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11005                 return false;
11006             }
11007             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11008                 return false;
11009             }
11010             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11011                 return false;
11012             }
11013             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11014                 return false;
11015             }
11016             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11017                 return false;
11018             }
11019             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11020                 return false;
11021             }
11022             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11023                 return false;
11024             }
11025             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11026                 return false;
11027             }
11028             p6 = null;
11029             final Phylogeny species7 = factory
11030                     .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,"
11031                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11032                              new NHXParser() )[ 0 ];
11033             final Phylogeny gene7 = factory
11034                     .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],"
11035                                      + "(((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],"
11036                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11037                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11038                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11039                              new NHXParser() )[ 0 ];
11040             species7.setRooted( true );
11041             gene7.setRooted( true );
11042             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11043             if ( sdi_unrooted.getCount() != 1 ) {
11044                 return false;
11045             }
11046             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11047                 return false;
11048             }
11049             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11050                 return false;
11051             }
11052             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11053                 return false;
11054             }
11055             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11056                 return false;
11057             }
11058             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11059                 return false;
11060             }
11061             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11062                 return false;
11063             }
11064             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11065                 return false;
11066             }
11067             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11068                 return false;
11069             }
11070             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11071                 return false;
11072             }
11073             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11074                 return false;
11075             }
11076             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11077                 return false;
11078             }
11079             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11080                 return false;
11081             }
11082             p7 = null;
11083             final Phylogeny species8 = factory
11084                     .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,"
11085                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11086                              new NHXParser() )[ 0 ];
11087             final Phylogeny gene8 = factory
11088                     .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],"
11089                                      + "(((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],"
11090                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11091                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11092                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11093                              new NHXParser() )[ 0 ];
11094             species8.setRooted( true );
11095             gene8.setRooted( true );
11096             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11097             if ( sdi_unrooted.getCount() != 1 ) {
11098                 return false;
11099             }
11100             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11101                 return false;
11102             }
11103             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11104                 return false;
11105             }
11106             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11107                 return false;
11108             }
11109             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11110                 return false;
11111             }
11112             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11113                 return false;
11114             }
11115             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11116                 return false;
11117             }
11118             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11119                 return false;
11120             }
11121             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11122                 return false;
11123             }
11124             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11125                 return false;
11126             }
11127             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11128                 return false;
11129             }
11130             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11131                 return false;
11132             }
11133             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11134                 return false;
11135             }
11136             p8 = null;
11137         }
11138         catch ( final Exception e ) {
11139             e.printStackTrace( System.out );
11140             return false;
11141         }
11142         return true;
11143     }
11144
11145     private static boolean testSequenceDbWsTools1() {
11146         try {
11147             final PhylogenyNode n = new PhylogenyNode();
11148             n.setName( "NP_001025424" );
11149             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11150             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11151                     || !acc.getValue().equals( "NP_001025424" ) ) {
11152                 return false;
11153             }
11154             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11155             acc = SequenceDbWsTools.obtainSeqAccession( n );
11156             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11157                     || !acc.getValue().equals( "NP_001025424" ) ) {
11158                 return false;
11159             }
11160             n.setName( "NP_001025424.1" );
11161             acc = SequenceDbWsTools.obtainSeqAccession( n );
11162             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11163                     || !acc.getValue().equals( "NP_001025424" ) ) {
11164                 return false;
11165             }
11166             n.setName( "NM_001030253" );
11167             acc = SequenceDbWsTools.obtainSeqAccession( n );
11168             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11169                     || !acc.getValue().equals( "NM_001030253" ) ) {
11170                 return false;
11171             }
11172             n.setName( "BCL2_HUMAN" );
11173             acc = SequenceDbWsTools.obtainSeqAccession( n );
11174             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11175                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11176                 System.out.println( acc.toString() );
11177                 return false;
11178             }
11179             n.setName( "P10415" );
11180             acc = SequenceDbWsTools.obtainSeqAccession( n );
11181             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11182                     || !acc.getValue().equals( "P10415" ) ) {
11183                 System.out.println( acc.toString() );
11184                 return false;
11185             }
11186             n.setName( " P10415 " );
11187             acc = SequenceDbWsTools.obtainSeqAccession( n );
11188             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11189                     || !acc.getValue().equals( "P10415" ) ) {
11190                 System.out.println( acc.toString() );
11191                 return false;
11192             }
11193             n.setName( "_P10415|" );
11194             acc = SequenceDbWsTools.obtainSeqAccession( n );
11195             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11196                     || !acc.getValue().equals( "P10415" ) ) {
11197                 System.out.println( acc.toString() );
11198                 return false;
11199             }
11200             n.setName( "AY695820" );
11201             acc = SequenceDbWsTools.obtainSeqAccession( n );
11202             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11203                     || !acc.getValue().equals( "AY695820" ) ) {
11204                 System.out.println( acc.toString() );
11205                 return false;
11206             }
11207             n.setName( "_AY695820_" );
11208             acc = SequenceDbWsTools.obtainSeqAccession( n );
11209             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11210                     || !acc.getValue().equals( "AY695820" ) ) {
11211                 System.out.println( acc.toString() );
11212                 return false;
11213             }
11214             n.setName( "AAA59452" );
11215             acc = SequenceDbWsTools.obtainSeqAccession( n );
11216             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11217                     || !acc.getValue().equals( "AAA59452" ) ) {
11218                 System.out.println( acc.toString() );
11219                 return false;
11220             }
11221             n.setName( "_AAA59452_" );
11222             acc = SequenceDbWsTools.obtainSeqAccession( n );
11223             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11224                     || !acc.getValue().equals( "AAA59452" ) ) {
11225                 System.out.println( acc.toString() );
11226                 return false;
11227             }
11228             n.setName( "AAA59452.1" );
11229             acc = SequenceDbWsTools.obtainSeqAccession( n );
11230             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11231                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11232                 System.out.println( acc.toString() );
11233                 return false;
11234             }
11235             n.setName( "_AAA59452.1_" );
11236             acc = SequenceDbWsTools.obtainSeqAccession( n );
11237             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11238                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11239                 System.out.println( acc.toString() );
11240                 return false;
11241             }
11242             n.setName( "GI:94894583" );
11243             acc = SequenceDbWsTools.obtainSeqAccession( n );
11244             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11245                     || !acc.getValue().equals( "94894583" ) ) {
11246                 System.out.println( acc.toString() );
11247                 return false;
11248             }
11249             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11250             acc = SequenceDbWsTools.obtainSeqAccession( n );
11251             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11252                     || !acc.getValue().equals( "71845847" ) ) {
11253                 System.out.println( acc.toString() );
11254                 return false;
11255             }
11256             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11257             acc = SequenceDbWsTools.obtainSeqAccession( n );
11258             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11259                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11260                 System.out.println( acc.toString() );
11261                 return false;
11262             }
11263         }
11264         catch ( final Exception e ) {
11265             return false;
11266         }
11267         return true;
11268     }
11269
11270     private static boolean testSequenceDbWsTools2() {
11271         try {
11272             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11273             SequenceDbWsTools.obtainSeqInformation( n1 );
11274             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11275                 return false;
11276             }
11277             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11278                 return false;
11279             }
11280             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11281                 return false;
11282             }
11283             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11284                 return false;
11285             }
11286             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11287             SequenceDbWsTools.obtainSeqInformation( n2 );
11288             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11289                 return false;
11290             }
11291             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11292                 return false;
11293             }
11294             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11295                 return false;
11296             }
11297             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11298                 return false;
11299             }
11300             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11301             SequenceDbWsTools.obtainSeqInformation( n3 );
11302             if ( !n3.getNodeData().getSequence().getName()
11303                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11304                 return false;
11305             }
11306             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11307                 return false;
11308             }
11309             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11310                 return false;
11311             }
11312             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11313                 return false;
11314             }
11315         }
11316         catch ( final IOException e ) {
11317             System.out.println();
11318             System.out.println( "the following might be due to absence internet connection:" );
11319             e.printStackTrace( System.out );
11320             return true;
11321         }
11322         catch ( final Exception e ) {
11323             e.printStackTrace();
11324             return false;
11325         }
11326         return true;
11327     }
11328
11329     private static boolean testSequenceIdParsing() {
11330         try {
11331             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11332             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11333                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11334                 if ( id != null ) {
11335                     System.out.println( "value   =" + id.getValue() );
11336                     System.out.println( "provider=" + id.getSource() );
11337                 }
11338                 return false;
11339             }
11340             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11341             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11342                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11343                 if ( id != null ) {
11344                     System.out.println( "value   =" + id.getValue() );
11345                     System.out.println( "provider=" + id.getSource() );
11346                 }
11347                 return false;
11348             }
11349             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11350             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11351                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11352                 if ( id != null ) {
11353                     System.out.println( "value   =" + id.getValue() );
11354                     System.out.println( "provider=" + id.getSource() );
11355                 }
11356                 return false;
11357             }
11358             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11359             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11360                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11361                 if ( id != null ) {
11362                     System.out.println( "value   =" + id.getValue() );
11363                     System.out.println( "provider=" + id.getSource() );
11364                 }
11365                 return false;
11366             }
11367             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11368             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11369                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11370                 if ( id != null ) {
11371                     System.out.println( "value   =" + id.getValue() );
11372                     System.out.println( "provider=" + id.getSource() );
11373                 }
11374                 return false;
11375             }
11376             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11377             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11378                     || !id.getValue().equals( "BAF37827" ) || !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             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11386             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11387                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11388                 if ( id != null ) {
11389                     System.out.println( "value   =" + id.getValue() );
11390                     System.out.println( "provider=" + id.getSource() );
11391                 }
11392                 return false;
11393             }
11394             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11395             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11396                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11397                 if ( id != null ) {
11398                     System.out.println( "value   =" + id.getValue() );
11399                     System.out.println( "provider=" + id.getSource() );
11400                 }
11401                 return false;
11402             }
11403             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11404             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11405                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11406                 if ( id != null ) {
11407                     System.out.println( "value   =" + id.getValue() );
11408                     System.out.println( "provider=" + id.getSource() );
11409                 }
11410                 return false;
11411             }
11412             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11413             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11414                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11415                 if ( id != null ) {
11416                     System.out.println( "value   =" + id.getValue() );
11417                     System.out.println( "provider=" + id.getSource() );
11418                 }
11419                 return false;
11420             }
11421             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11422             if ( id != null ) {
11423                 System.out.println( "value   =" + id.getValue() );
11424                 System.out.println( "provider=" + id.getSource() );
11425                 return false;
11426             }
11427             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11428             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11429                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11430                 if ( id != null ) {
11431                     System.out.println( "value   =" + id.getValue() );
11432                     System.out.println( "provider=" + id.getSource() );
11433                 }
11434                 return false;
11435             }
11436             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11437             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11438                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11439                 if ( id != null ) {
11440                     System.out.println( "value   =" + id.getValue() );
11441                     System.out.println( "provider=" + id.getSource() );
11442                 }
11443                 return false;
11444             }
11445             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11446             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11447                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11448                 if ( id != null ) {
11449                     System.out.println( "value   =" + id.getValue() );
11450                     System.out.println( "provider=" + id.getSource() );
11451                 }
11452                 return false;
11453             }
11454             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11455             if ( id != null ) {
11456                 System.out.println( "value   =" + id.getValue() );
11457                 System.out.println( "provider=" + id.getSource() );
11458                 return false;
11459             }
11460         }
11461         catch ( final Exception e ) {
11462             e.printStackTrace( System.out );
11463             return false;
11464         }
11465         return true;
11466     }
11467
11468     private static boolean testSequenceWriter() {
11469         try {
11470             final String n = ForesterUtil.LINE_SEPARATOR;
11471             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11472                 return false;
11473             }
11474             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11475                 return false;
11476             }
11477             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11478                 return false;
11479             }
11480             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11481                 return false;
11482             }
11483             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11484                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11485                 return false;
11486             }
11487             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11488                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11489                 return false;
11490             }
11491         }
11492         catch ( final Exception e ) {
11493             e.printStackTrace();
11494             return false;
11495         }
11496         return true;
11497     }
11498
11499     private static boolean testSpecies() {
11500         try {
11501             final Species s1 = new BasicSpecies( "a" );
11502             final Species s2 = new BasicSpecies( "a" );
11503             final Species s3 = new BasicSpecies( "A" );
11504             final Species s4 = new BasicSpecies( "b" );
11505             if ( !s1.equals( s1 ) ) {
11506                 return false;
11507             }
11508             if ( s1.getSpeciesId().equals( "x" ) ) {
11509                 return false;
11510             }
11511             if ( s1.getSpeciesId().equals( null ) ) {
11512                 return false;
11513             }
11514             if ( !s1.equals( s2 ) ) {
11515                 return false;
11516             }
11517             if ( s1.equals( s3 ) ) {
11518                 return false;
11519             }
11520             if ( s1.hashCode() != s1.hashCode() ) {
11521                 return false;
11522             }
11523             if ( s1.hashCode() != s2.hashCode() ) {
11524                 return false;
11525             }
11526             if ( s1.hashCode() == s3.hashCode() ) {
11527                 return false;
11528             }
11529             if ( s1.compareTo( s1 ) != 0 ) {
11530                 return false;
11531             }
11532             if ( s1.compareTo( s2 ) != 0 ) {
11533                 return false;
11534             }
11535             if ( s1.compareTo( s3 ) != 0 ) {
11536                 return false;
11537             }
11538             if ( s1.compareTo( s4 ) >= 0 ) {
11539                 return false;
11540             }
11541             if ( s4.compareTo( s1 ) <= 0 ) {
11542                 return false;
11543             }
11544             if ( !s4.getSpeciesId().equals( "b" ) ) {
11545                 return false;
11546             }
11547             final Species s5 = new BasicSpecies( " C " );
11548             if ( !s5.getSpeciesId().equals( "C" ) ) {
11549                 return false;
11550             }
11551             if ( s5.equals( s1 ) ) {
11552                 return false;
11553             }
11554         }
11555         catch ( final Exception e ) {
11556             e.printStackTrace( System.out );
11557             return false;
11558         }
11559         return true;
11560     }
11561
11562     private static boolean testSplit() {
11563         try {
11564             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11565             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11566             //Archaeopteryx.createApplication( p0 );
11567             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11568             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11569             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11570             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11571             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11572             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11573             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11574             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11575             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11576             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11577             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11578             // System.out.println( s0.toString() );
11579             //
11580             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11583             if ( s0.match( query_nodes ) ) {
11584                 return false;
11585             }
11586             query_nodes = new HashSet<PhylogenyNode>();
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11592             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11593             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11594             if ( !s0.match( query_nodes ) ) {
11595                 return false;
11596             }
11597             //
11598             query_nodes = new HashSet<PhylogenyNode>();
11599             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11600             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11602             if ( !s0.match( query_nodes ) ) {
11603                 return false;
11604             }
11605             //
11606             query_nodes = new HashSet<PhylogenyNode>();
11607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11611             if ( !s0.match( query_nodes ) ) {
11612                 return false;
11613             }
11614             //
11615             query_nodes = new HashSet<PhylogenyNode>();
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11620             if ( !s0.match( query_nodes ) ) {
11621                 return false;
11622             }
11623             //
11624             query_nodes = new HashSet<PhylogenyNode>();
11625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11628             if ( !s0.match( query_nodes ) ) {
11629                 return false;
11630             }
11631             query_nodes = new HashSet<PhylogenyNode>();
11632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11634             if ( !s0.match( query_nodes ) ) {
11635                 return false;
11636             }
11637             query_nodes = new HashSet<PhylogenyNode>();
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11643             if ( !s0.match( query_nodes ) ) {
11644                 return false;
11645             }
11646             query_nodes = new HashSet<PhylogenyNode>();
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11650             if ( !s0.match( query_nodes ) ) {
11651                 return false;
11652             }
11653             query_nodes = new HashSet<PhylogenyNode>();
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11658             if ( !s0.match( query_nodes ) ) {
11659                 return false;
11660             }
11661             query_nodes = new HashSet<PhylogenyNode>();
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11664             if ( s0.match( query_nodes ) ) {
11665                 return false;
11666             }
11667             query_nodes = new HashSet<PhylogenyNode>();
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11672             if ( s0.match( query_nodes ) ) {
11673                 return false;
11674             }
11675             query_nodes = new HashSet<PhylogenyNode>();
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11681             if ( s0.match( query_nodes ) ) {
11682                 return false;
11683             }
11684             query_nodes = new HashSet<PhylogenyNode>();
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11688             if ( s0.match( query_nodes ) ) {
11689                 return false;
11690             }
11691             query_nodes = new HashSet<PhylogenyNode>();
11692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11694             if ( s0.match( query_nodes ) ) {
11695                 return false;
11696             }
11697             query_nodes = new HashSet<PhylogenyNode>();
11698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11700             if ( s0.match( query_nodes ) ) {
11701                 return false;
11702             }
11703             query_nodes = new HashSet<PhylogenyNode>();
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11706             if ( s0.match( query_nodes ) ) {
11707                 return false;
11708             }
11709             query_nodes = new HashSet<PhylogenyNode>();
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11712             if ( s0.match( query_nodes ) ) {
11713                 return false;
11714             }
11715             query_nodes = new HashSet<PhylogenyNode>();
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11718             if ( s0.match( query_nodes ) ) {
11719                 return false;
11720             }
11721             query_nodes = new HashSet<PhylogenyNode>();
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11724             if ( s0.match( query_nodes ) ) {
11725                 return false;
11726             }
11727             query_nodes = new HashSet<PhylogenyNode>();
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11731             if ( s0.match( query_nodes ) ) {
11732                 return false;
11733             }
11734             query_nodes = new HashSet<PhylogenyNode>();
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11738             if ( s0.match( query_nodes ) ) {
11739                 return false;
11740             }
11741             query_nodes = new HashSet<PhylogenyNode>();
11742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11745             if ( s0.match( query_nodes ) ) {
11746                 return false;
11747             }
11748             query_nodes = new HashSet<PhylogenyNode>();
11749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11753             if ( s0.match( query_nodes ) ) {
11754                 return false;
11755             }
11756             /////////
11757             //            query_nodes = new HashSet<PhylogenyNode>();
11758             //            query_nodes.add( new PhylogenyNode( "X" ) );
11759             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11760             //            query_nodes.add( new PhylogenyNode( "A" ) );
11761             //            query_nodes.add( new PhylogenyNode( "B" ) );
11762             //            query_nodes.add( new PhylogenyNode( "C" ) );
11763             //            query_nodes.add( new PhylogenyNode( "D" ) );
11764             //            query_nodes.add( new PhylogenyNode( "E" ) );
11765             //            query_nodes.add( new PhylogenyNode( "F" ) );
11766             //            query_nodes.add( new PhylogenyNode( "G" ) );
11767             //            if ( !s0.match( query_nodes ) ) {
11768             //                return false;
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             //            if ( !s0.match( query_nodes ) ) {
11777             //                return false;
11778             //            }
11779             //            //
11780             //            query_nodes = new HashSet<PhylogenyNode>();
11781             //            query_nodes.add( new PhylogenyNode( "X" ) );
11782             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11783             //            query_nodes.add( new PhylogenyNode( "D" ) );
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( "A" ) );
11795             //            query_nodes.add( new PhylogenyNode( "B" ) );
11796             //            query_nodes.add( new PhylogenyNode( "C" ) );
11797             //            query_nodes.add( new PhylogenyNode( "D" ) );
11798             //            if ( !s0.match( query_nodes ) ) {
11799             //                return false;
11800             //            }
11801             //            //
11802             //            query_nodes = new HashSet<PhylogenyNode>();
11803             //            query_nodes.add( new PhylogenyNode( "X" ) );
11804             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11805             //            query_nodes.add( new PhylogenyNode( "E" ) );
11806             //            query_nodes.add( new PhylogenyNode( "F" ) );
11807             //            query_nodes.add( new PhylogenyNode( "G" ) );
11808             //            if ( !s0.match( query_nodes ) ) {
11809             //                return false;
11810             //            }
11811             //            //
11812             //            query_nodes = new HashSet<PhylogenyNode>();
11813             //            query_nodes.add( new PhylogenyNode( "X" ) );
11814             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11815             //            query_nodes.add( new PhylogenyNode( "F" ) );
11816             //            query_nodes.add( new PhylogenyNode( "G" ) );
11817             //            if ( !s0.match( query_nodes ) ) {
11818             //                return false;
11819             //            }
11820             //
11821             query_nodes = new HashSet<PhylogenyNode>();
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11826             if ( s0.match( query_nodes ) ) {
11827                 return false;
11828             }
11829             //
11830             query_nodes = new HashSet<PhylogenyNode>();
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11835             if ( s0.match( query_nodes ) ) {
11836                 return false;
11837             }
11838             ///////////////////////////
11839             //
11840             query_nodes = new HashSet<PhylogenyNode>();
11841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11844             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11845             if ( s0.match( query_nodes ) ) {
11846                 return false;
11847             }
11848             //
11849             query_nodes = new HashSet<PhylogenyNode>();
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11854             if ( s0.match( query_nodes ) ) {
11855                 return false;
11856             }
11857             //
11858             query_nodes = new HashSet<PhylogenyNode>();
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11863             if ( s0.match( query_nodes ) ) {
11864                 return false;
11865             }
11866             //
11867             query_nodes = new HashSet<PhylogenyNode>();
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11872             if ( s0.match( query_nodes ) ) {
11873                 return false;
11874             }
11875             //
11876             query_nodes = new HashSet<PhylogenyNode>();
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11881             if ( s0.match( query_nodes ) ) {
11882                 return false;
11883             }
11884             //
11885             query_nodes = new HashSet<PhylogenyNode>();
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11889             if ( s0.match( query_nodes ) ) {
11890                 return false;
11891             }
11892             //
11893             query_nodes = new HashSet<PhylogenyNode>();
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11899             if ( s0.match( query_nodes ) ) {
11900                 return false;
11901             }
11902             //
11903             query_nodes = new HashSet<PhylogenyNode>();
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11909             if ( s0.match( query_nodes ) ) {
11910                 return false;
11911             }
11912             //
11913             query_nodes = new HashSet<PhylogenyNode>();
11914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11919             if ( s0.match( query_nodes ) ) {
11920                 return false;
11921             }
11922             //
11923             query_nodes = new HashSet<PhylogenyNode>();
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11930             if ( s0.match( query_nodes ) ) {
11931                 return false;
11932             }
11933         }
11934         catch ( final Exception e ) {
11935             e.printStackTrace();
11936             return false;
11937         }
11938         return true;
11939     }
11940
11941     private static boolean testSplitStrict() {
11942         try {
11943             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11944             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11945             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11946             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11947             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11948             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11949             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11950             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11951             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11952             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11953             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11954             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11957             if ( s0.match( query_nodes ) ) {
11958                 return false;
11959             }
11960             query_nodes = new HashSet<PhylogenyNode>();
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11968             if ( !s0.match( query_nodes ) ) {
11969                 return false;
11970             }
11971             //
11972             query_nodes = new HashSet<PhylogenyNode>();
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11976             if ( !s0.match( query_nodes ) ) {
11977                 return false;
11978             }
11979             //
11980             query_nodes = new HashSet<PhylogenyNode>();
11981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11985             if ( !s0.match( query_nodes ) ) {
11986                 return false;
11987             }
11988             //
11989             query_nodes = new HashSet<PhylogenyNode>();
11990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11994             if ( !s0.match( query_nodes ) ) {
11995                 return false;
11996             }
11997             //
11998             query_nodes = new HashSet<PhylogenyNode>();
11999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12002             if ( !s0.match( query_nodes ) ) {
12003                 return false;
12004             }
12005             //
12006             query_nodes = new HashSet<PhylogenyNode>();
12007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12009             if ( !s0.match( query_nodes ) ) {
12010                 return false;
12011             }
12012             //
12013             query_nodes = new HashSet<PhylogenyNode>();
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12019             if ( !s0.match( query_nodes ) ) {
12020                 return false;
12021             }
12022             //
12023             query_nodes = new HashSet<PhylogenyNode>();
12024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12026             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12027             if ( !s0.match( query_nodes ) ) {
12028                 return false;
12029             }
12030             //
12031             query_nodes = new HashSet<PhylogenyNode>();
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12034             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12036             if ( !s0.match( query_nodes ) ) {
12037                 return false;
12038             }
12039             //
12040             query_nodes = new HashSet<PhylogenyNode>();
12041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12043             if ( s0.match( query_nodes ) ) {
12044                 return false;
12045             }
12046             //
12047             query_nodes = new HashSet<PhylogenyNode>();
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12052             if ( s0.match( query_nodes ) ) {
12053                 return false;
12054             }
12055             //
12056             query_nodes = new HashSet<PhylogenyNode>();
12057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12062             if ( s0.match( query_nodes ) ) {
12063                 return false;
12064             }
12065             //
12066             query_nodes = new HashSet<PhylogenyNode>();
12067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "D" ) );
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( "B" ) );
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( "C" ) );
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( "E" ) );
12098             if ( s0.match( query_nodes ) ) {
12099                 return false;
12100             }
12101             //
12102             query_nodes = new HashSet<PhylogenyNode>();
12103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12105             if ( s0.match( query_nodes ) ) {
12106                 return false;
12107             }
12108             //
12109             query_nodes = new HashSet<PhylogenyNode>();
12110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12112             if ( s0.match( query_nodes ) ) {
12113                 return false;
12114             }
12115             //
12116             query_nodes = new HashSet<PhylogenyNode>();
12117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12119             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12120             if ( s0.match( query_nodes ) ) {
12121                 return false;
12122             }
12123             //
12124             query_nodes = new HashSet<PhylogenyNode>();
12125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12128             if ( s0.match( query_nodes ) ) {
12129                 return false;
12130             }
12131             //
12132             query_nodes = new HashSet<PhylogenyNode>();
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12136             if ( s0.match( query_nodes ) ) {
12137                 return false;
12138             }
12139             //
12140             query_nodes = new HashSet<PhylogenyNode>();
12141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12145             if ( s0.match( query_nodes ) ) {
12146                 return false;
12147             }
12148         }
12149         catch ( final Exception e ) {
12150             e.printStackTrace();
12151             return false;
12152         }
12153         return true;
12154     }
12155
12156     private static boolean testSubtreeDeletion() {
12157         try {
12158             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12159             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12160             t1.deleteSubtree( t1.getNode( "A" ), false );
12161             if ( t1.getNumberOfExternalNodes() != 5 ) {
12162                 return false;
12163             }
12164             t1.toNewHampshireX();
12165             t1.deleteSubtree( t1.getNode( "E" ), false );
12166             if ( t1.getNumberOfExternalNodes() != 4 ) {
12167                 return false;
12168             }
12169             t1.toNewHampshireX();
12170             t1.deleteSubtree( t1.getNode( "F" ), false );
12171             if ( t1.getNumberOfExternalNodes() != 3 ) {
12172                 return false;
12173             }
12174             t1.toNewHampshireX();
12175             t1.deleteSubtree( t1.getNode( "D" ), false );
12176             t1.toNewHampshireX();
12177             if ( t1.getNumberOfExternalNodes() != 3 ) {
12178                 return false;
12179             }
12180             t1.deleteSubtree( t1.getNode( "def" ), false );
12181             t1.toNewHampshireX();
12182             if ( t1.getNumberOfExternalNodes() != 2 ) {
12183                 return false;
12184             }
12185             t1.deleteSubtree( t1.getNode( "B" ), false );
12186             t1.toNewHampshireX();
12187             if ( t1.getNumberOfExternalNodes() != 1 ) {
12188                 return false;
12189             }
12190             t1.deleteSubtree( t1.getNode( "C" ), false );
12191             t1.toNewHampshireX();
12192             if ( t1.getNumberOfExternalNodes() != 1 ) {
12193                 return false;
12194             }
12195             t1.deleteSubtree( t1.getNode( "abc" ), false );
12196             t1.toNewHampshireX();
12197             if ( t1.getNumberOfExternalNodes() != 1 ) {
12198                 return false;
12199             }
12200             t1.deleteSubtree( t1.getNode( "r" ), false );
12201             if ( t1.getNumberOfExternalNodes() != 0 ) {
12202                 return false;
12203             }
12204             if ( !t1.isEmpty() ) {
12205                 return false;
12206             }
12207             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12208             t2.deleteSubtree( t2.getNode( "A" ), false );
12209             t2.toNewHampshireX();
12210             if ( t2.getNumberOfExternalNodes() != 5 ) {
12211                 return false;
12212             }
12213             t2.deleteSubtree( t2.getNode( "abc" ), false );
12214             t2.toNewHampshireX();
12215             if ( t2.getNumberOfExternalNodes() != 3 ) {
12216                 return false;
12217             }
12218             t2.deleteSubtree( t2.getNode( "def" ), false );
12219             t2.toNewHampshireX();
12220             if ( t2.getNumberOfExternalNodes() != 1 ) {
12221                 return false;
12222             }
12223         }
12224         catch ( final Exception e ) {
12225             e.printStackTrace( System.out );
12226             return false;
12227         }
12228         return true;
12229     }
12230
12231     private static boolean testSupportCount() {
12232         try {
12233             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12234             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12235             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12236                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12237                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12238                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12239                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12240                                                               new NHXParser() );
12241             SupportCount.count( t0_1, phylogenies_1, true, false );
12242             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12243             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12244                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12245                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12246                                                                       + "(((((A,B),C),D),E),(F,G))"
12247                                                                       + "(((((A,B),C),D),E),(F,G))"
12248                                                                       + "(((((A,B),C),D),E),(F,G))"
12249                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12250                                                                       + "(((((A,B),C),D),E),(F,G))"
12251                                                                       + "((((((A,B),C),D),E),F),G)"
12252                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12253                                                               new NHXParser() );
12254             SupportCount.count( t0_2, phylogenies_2, true, false );
12255             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12256             while ( it.hasNext() ) {
12257                 final PhylogenyNode n = it.next();
12258                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12259                     return false;
12260                 }
12261             }
12262             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12263             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12264                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12265             SupportCount.count( t0_3, phylogenies_3, true, false );
12266             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12267             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12268                 return false;
12269             }
12270             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12271                 return false;
12272             }
12273             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12274                 return false;
12275             }
12276             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12277                 return false;
12278             }
12279             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12280                 return false;
12281             }
12282             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12283                 return false;
12284             }
12285             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12286                 return false;
12287             }
12288             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12289                 return false;
12290             }
12291             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12292                 return false;
12293             }
12294             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12295                 return false;
12296             }
12297             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12298             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12299                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12300             SupportCount.count( t0_4, phylogenies_4, true, false );
12301             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12302             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12303                 return false;
12304             }
12305             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12306                 return false;
12307             }
12308             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12309                 return false;
12310             }
12311             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12312                 return false;
12313             }
12314             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12315                 return false;
12316             }
12317             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12318                 return false;
12319             }
12320             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12321                 return false;
12322             }
12323             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12324                 return false;
12325             }
12326             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12327                 return false;
12328             }
12329             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12330                 return false;
12331             }
12332             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12333             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12334             double d = SupportCount.compare( b1, a, true, true, true );
12335             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12336                 return false;
12337             }
12338             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12339             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12340             d = SupportCount.compare( b2, a, true, true, true );
12341             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12342                 return false;
12343             }
12344             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12345             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12346             d = SupportCount.compare( b3, a, true, true, true );
12347             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12348                 return false;
12349             }
12350             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12351             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12352             d = SupportCount.compare( b4, a, true, true, false );
12353             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12354                 return false;
12355             }
12356         }
12357         catch ( final Exception e ) {
12358             e.printStackTrace( System.out );
12359             return false;
12360         }
12361         return true;
12362     }
12363
12364     private static boolean testSupportTransfer() {
12365         try {
12366             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12367             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)",
12368                                                  new NHXParser() )[ 0 ];
12369             final Phylogeny p2 = factory
12370                     .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 ];
12371             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12372                 return false;
12373             }
12374             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12375                 return false;
12376             }
12377             support_transfer.moveBranchLengthsToBootstrap( p1 );
12378             support_transfer.transferSupportValues( p1, p2 );
12379             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12380                 return false;
12381             }
12382             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12383                 return false;
12384             }
12385             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12386                 return false;
12387             }
12388             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12389                 return false;
12390             }
12391             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12392                 return false;
12393             }
12394             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12395                 return false;
12396             }
12397             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12398                 return false;
12399             }
12400             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12401                 return false;
12402             }
12403         }
12404         catch ( final Exception e ) {
12405             e.printStackTrace( System.out );
12406             return false;
12407         }
12408         return true;
12409     }
12410
12411     private static boolean testTaxonomyExtraction() {
12412         try {
12413             final PhylogenyNode n0 = PhylogenyNode
12414                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12415             if ( n0.getNodeData().isHasTaxonomy() ) {
12416                 return false;
12417             }
12418             final PhylogenyNode n1 = PhylogenyNode
12419                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12420             if ( n1.getNodeData().isHasTaxonomy() ) {
12421                 System.out.println( n1.toString() );
12422                 return false;
12423             }
12424             final PhylogenyNode n2x = PhylogenyNode
12425                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12426             if ( n2x.getNodeData().isHasTaxonomy() ) {
12427                 return false;
12428             }
12429             final PhylogenyNode n3 = PhylogenyNode
12430                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12431             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12432                 System.out.println( n3.toString() );
12433                 return false;
12434             }
12435             final PhylogenyNode n4 = PhylogenyNode
12436                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12437             if ( n4.getNodeData().isHasTaxonomy() ) {
12438                 System.out.println( n4.toString() );
12439                 return false;
12440             }
12441             final PhylogenyNode n5 = PhylogenyNode
12442                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12443             if ( n5.getNodeData().isHasTaxonomy() ) {
12444                 System.out.println( n5.toString() );
12445                 return false;
12446             }
12447             final PhylogenyNode n6 = PhylogenyNode
12448                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12449             if ( n6.getNodeData().isHasTaxonomy() ) {
12450                 System.out.println( n6.toString() );
12451                 return false;
12452             }
12453             final PhylogenyNode n7 = PhylogenyNode
12454                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12455             if ( n7.getNodeData().isHasTaxonomy() ) {
12456                 System.out.println( n7.toString() );
12457                 return false;
12458             }
12459             final PhylogenyNode n8 = PhylogenyNode
12460                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12461             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12462                 System.out.println( n8.toString() );
12463                 return false;
12464             }
12465             final PhylogenyNode n9 = PhylogenyNode
12466                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12467             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12468                 System.out.println( n9.toString() );
12469                 return false;
12470             }
12471             final PhylogenyNode n10x = PhylogenyNode
12472                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12473             if ( n10x.getNodeData().isHasTaxonomy() ) {
12474                 System.out.println( n10x.toString() );
12475                 return false;
12476             }
12477             final PhylogenyNode n10xx = PhylogenyNode
12478                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12479             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12480                 System.out.println( n10xx.toString() );
12481                 return false;
12482             }
12483             final PhylogenyNode n10 = PhylogenyNode
12484                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12485             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12486                 System.out.println( n10.toString() );
12487                 return false;
12488             }
12489             final PhylogenyNode n11 = PhylogenyNode
12490                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12491             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12492                 System.out.println( n11.toString() );
12493                 return false;
12494             }
12495             final PhylogenyNode n12 = PhylogenyNode
12496                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12497                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12498             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12499                 System.out.println( n12.toString() );
12500                 return false;
12501             }
12502             final PhylogenyNode n13 = PhylogenyNode
12503                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12504             if ( n13.getNodeData().isHasTaxonomy() ) {
12505                 System.out.println( n13.toString() );
12506                 return false;
12507             }
12508             final PhylogenyNode n14 = PhylogenyNode
12509                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12510             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12511                 System.out.println( n14.toString() );
12512                 return false;
12513             }
12514             final PhylogenyNode n15 = PhylogenyNode
12515                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12516             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12517                 System.out.println( n15.toString() );
12518                 return false;
12519             }
12520             final PhylogenyNode n16 = PhylogenyNode
12521                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12522             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12523                 System.out.println( n16.toString() );
12524                 return false;
12525             }
12526             final PhylogenyNode n17 = PhylogenyNode
12527                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12528             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12529                 System.out.println( n17.toString() );
12530                 return false;
12531             }
12532             final PhylogenyNode n18 = PhylogenyNode
12533                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12534             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12535                 System.out.println( n18.toString() );
12536                 return false;
12537             }
12538             final PhylogenyNode n19 = PhylogenyNode
12539                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12540                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12541             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12542                 System.out.println( n19.toString() );
12543                 return false;
12544             }
12545             final PhylogenyNode n20 = PhylogenyNode
12546                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12547             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12548                 System.out.println( n20.toString() );
12549                 return false;
12550             }
12551             final PhylogenyNode n21 = PhylogenyNode
12552                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12553                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12554             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12555                 System.out.println( n21.toString() );
12556                 return false;
12557             }
12558             final PhylogenyNode n23 = PhylogenyNode
12559                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12560                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12561             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12562                 System.out.println( n23.toString() );
12563                 return false;
12564             }
12565             final PhylogenyNode n24 = PhylogenyNode
12566                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12567             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12568                 System.out.println( n24.toString() );
12569                 return false;
12570             }
12571             //
12572             final PhylogenyNode n25 = PhylogenyNode
12573                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12574                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12576                 System.out.println( n25.toString() );
12577                 return false;
12578             }
12579             final PhylogenyNode n26 = PhylogenyNode
12580                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12581                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12582             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12583                 System.out.println( n26.toString() );
12584                 return false;
12585             }
12586             final PhylogenyNode n27 = PhylogenyNode
12587                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12588             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12589                 System.out.println( n27.toString() );
12590                 return false;
12591             }
12592         }
12593         catch ( final Exception e ) {
12594             e.printStackTrace( System.out );
12595             return false;
12596         }
12597         return true;
12598     }
12599
12600     private static boolean testTreeCopy() {
12601         try {
12602             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12603             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12604             final Phylogeny t1 = t0.copy();
12605             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12606                 return false;
12607             }
12608             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12609                 return false;
12610             }
12611             t0.deleteSubtree( t0.getNode( "c" ), true );
12612             t0.deleteSubtree( t0.getNode( "a" ), true );
12613             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12614             t0.getNode( "b" ).setName( "Bee" );
12615             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12616                 return false;
12617             }
12618             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12619                 return false;
12620             }
12621             t0.deleteSubtree( t0.getNode( "e" ), true );
12622             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12623             t0.deleteSubtree( t0.getNode( "d" ), true );
12624             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12625                 return false;
12626             }
12627         }
12628         catch ( final Exception e ) {
12629             e.printStackTrace();
12630             return false;
12631         }
12632         return true;
12633     }
12634
12635     private static boolean testTreeMethods() {
12636         try {
12637             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12638             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12639             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12640             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12641                 System.out.println( t0.toNewHampshireX() );
12642                 return false;
12643             }
12644             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12645             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12646             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12647                 return false;
12648             }
12649             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12650                 return false;
12651             }
12652             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12653                 return false;
12654             }
12655         }
12656         catch ( final Exception e ) {
12657             e.printStackTrace( System.out );
12658             return false;
12659         }
12660         return true;
12661     }
12662
12663     private static boolean testUniprotEntryRetrieval() {
12664         try {
12665             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12666             if ( !entry.getAccession().equals( "P12345" ) ) {
12667                 return false;
12668             }
12669             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12670                 return false;
12671             }
12672             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12673                 return false;
12674             }
12675             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12676                 return false;
12677             }
12678             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12679                 return false;
12680             }
12681             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12682                 return false;
12683             }
12684             if ( entry.getMolecularSequence() == null ) {
12685                 return false;
12686             }
12687             if ( !entry
12688                     .getMolecularSequence()
12689                     .getMolecularSequenceAsString()
12690                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12691                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12692                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12693                 System.out.println( "expected something else." );
12694                 return false;
12695             }
12696         }
12697         catch ( final IOException e ) {
12698             System.out.println();
12699             System.out.println( "the following might be due to absence internet connection:" );
12700             e.printStackTrace( System.out );
12701             return true;
12702         }
12703         catch ( final NullPointerException f ) {
12704             f.printStackTrace( System.out );
12705             return false;
12706         }
12707         catch ( final Exception e ) {
12708             return false;
12709         }
12710         return true;
12711     }
12712
12713     private static boolean testUniprotTaxonomySearch() {
12714         try {
12715             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12716                                                                                                  10 );
12717             if ( results.size() != 1 ) {
12718                 return false;
12719             }
12720             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12721                 return false;
12722             }
12723             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12724                 return false;
12725             }
12726             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12727                 return false;
12728             }
12729             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12730                 return false;
12731             }
12732             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12733                 return false;
12734             }
12735             results = null;
12736             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12737             if ( results.size() != 1 ) {
12738                 return false;
12739             }
12740             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12741                 return false;
12742             }
12743             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12744                 return false;
12745             }
12746             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12747                 return false;
12748             }
12749             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12750                 return false;
12751             }
12752             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12753                 return false;
12754             }
12755             results = null;
12756             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12757             if ( results.size() != 1 ) {
12758                 return false;
12759             }
12760             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12761                 return false;
12762             }
12763             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12764                 return false;
12765             }
12766             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12767                 return false;
12768             }
12769             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12770                 return false;
12771             }
12772             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12773                 return false;
12774             }
12775             results = null;
12776             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12777             if ( results.size() != 1 ) {
12778                 return false;
12779             }
12780             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12781                 return false;
12782             }
12783             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12784                 return false;
12785             }
12786             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12787                 return false;
12788             }
12789             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12790                 return false;
12791             }
12792             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12793                 return false;
12794             }
12795             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12796                 return false;
12797             }
12798             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12799                 return false;
12800             }
12801             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12802                     .equals( "Nematostella vectensis" ) ) {
12803                 System.out.println( results.get( 0 ).getLineage() );
12804                 return false;
12805             }
12806             //
12807             results = null;
12808             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12809             if ( results.size() != 1 ) {
12810                 return false;
12811             }
12812             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12813                 return false;
12814             }
12815             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12816                 return false;
12817             }
12818             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12819                 return false;
12820             }
12821             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12822                 return false;
12823             }
12824             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12825                 return false;
12826             }
12827             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12828                     .equals( "Xenopus tropicalis" ) ) {
12829                 System.out.println( results.get( 0 ).getLineage() );
12830                 return false;
12831             }
12832             //
12833             results = null;
12834             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12835             if ( results.size() != 1 ) {
12836                 return false;
12837             }
12838             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12839                 return false;
12840             }
12841             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12842                 return false;
12843             }
12844             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12845                 return false;
12846             }
12847             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12848                 return false;
12849             }
12850             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12851                 return false;
12852             }
12853             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12854                     .equals( "Xenopus tropicalis" ) ) {
12855                 System.out.println( results.get( 0 ).getLineage() );
12856                 return false;
12857             }
12858             //
12859             results = null;
12860             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12861             if ( results.size() != 1 ) {
12862                 return false;
12863             }
12864             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12865                 return false;
12866             }
12867             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12868                 return false;
12869             }
12870             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12871                 return false;
12872             }
12873             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12874                 return false;
12875             }
12876             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12877                 return false;
12878             }
12879             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12880                     .equals( "Xenopus tropicalis" ) ) {
12881                 System.out.println( results.get( 0 ).getLineage() );
12882                 return false;
12883             }
12884         }
12885         catch ( final IOException e ) {
12886             System.out.println();
12887             System.out.println( "the following might be due to absence internet connection:" );
12888             e.printStackTrace( System.out );
12889             return true;
12890         }
12891         catch ( final Exception e ) {
12892             return false;
12893         }
12894         return true;
12895     }
12896
12897     private static boolean testWabiTxSearch() {
12898         try {
12899             String result = "";
12900             result = TxSearch.searchSimple( "nematostella" );
12901             result = TxSearch.getTxId( "nematostella" );
12902             if ( !result.equals( "45350" ) ) {
12903                 return false;
12904             }
12905             result = TxSearch.getTxName( "45350" );
12906             if ( !result.equals( "Nematostella" ) ) {
12907                 return false;
12908             }
12909             result = TxSearch.getTxId( "nematostella vectensis" );
12910             if ( !result.equals( "45351" ) ) {
12911                 return false;
12912             }
12913             result = TxSearch.getTxName( "45351" );
12914             if ( !result.equals( "Nematostella vectensis" ) ) {
12915                 return false;
12916             }
12917             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12918             if ( !result.equals( "536089" ) ) {
12919                 return false;
12920             }
12921             result = TxSearch.getTxName( "536089" );
12922             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12923                 return false;
12924             }
12925             final List<String> queries = new ArrayList<String>();
12926             queries.add( "Campylobacter coli" );
12927             queries.add( "Escherichia coli" );
12928             queries.add( "Arabidopsis" );
12929             queries.add( "Trichoplax" );
12930             queries.add( "Samanea saman" );
12931             queries.add( "Kluyveromyces marxianus" );
12932             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12933             queries.add( "Bornavirus parrot/PDD/2008" );
12934             final List<RANKS> ranks = new ArrayList<RANKS>();
12935             ranks.add( RANKS.SUPERKINGDOM );
12936             ranks.add( RANKS.KINGDOM );
12937             ranks.add( RANKS.FAMILY );
12938             ranks.add( RANKS.GENUS );
12939             ranks.add( RANKS.TRIBE );
12940             result = TxSearch.searchLineage( queries, ranks );
12941             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12942             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12943         }
12944         catch ( final Exception e ) {
12945             System.out.println();
12946             System.out.println( "the following might be due to absence internet connection:" );
12947             e.printStackTrace( System.out );
12948             return false;
12949         }
12950         return true;
12951     }
12952 }