in progress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.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          = false;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
146                                                                    + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
149                                                                    + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     public static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                 + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         System.out.print( "MSA entropy: " );
185         if ( Test.testMsaEntropy() ) {
186             System.out.println( "OK." );
187             succeeded++;
188         }
189         else {
190             System.out.println( "failed." );
191             failed++;
192         }
193         System.out.print( "Basic node methods: " );
194         if ( Test.testBasicNodeMethods() ) {
195             System.out.println( "OK." );
196             succeeded++;
197         }
198         else {
199             System.out.println( "failed." );
200             failed++;
201         }
202         System.out.print( "Protein id: " );
203         if ( !testProteinId() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Species: " );
212         if ( !testSpecies() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Basic domain: " );
221         if ( !testBasicDomain() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Basic protein: " );
230         if ( !testBasicProtein() ) {
231             System.out.println( "failed." );
232             failed++;
233         }
234         else {
235             succeeded++;
236         }
237         System.out.println( "OK." );
238         System.out.print( "Sequence writer: " );
239         if ( testSequenceWriter() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "Sequence id parsing: " );
248         if ( testSequenceIdParsing() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "UniProtKB id extraction: " );
257         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Sequence DB tools 1: " );
266         if ( testSequenceDbWsTools1() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Hmmscan output parser: " );
275         if ( testHmmscanOutputParser() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "Overlap removal: " );
284         if ( !org.forester.test.Test.testOverlapRemoval() ) {
285             System.out.println( "failed." );
286             failed++;
287         }
288         else {
289             succeeded++;
290         }
291         System.out.println( "OK." );
292         System.out.print( "Engulfing overlap removal: " );
293         if ( !Test.testEngulfingOverlapRemoval() ) {
294             System.out.println( "failed." );
295             failed++;
296         }
297         else {
298             succeeded++;
299         }
300         System.out.println( "OK." );
301         System.out.print( "Taxonomy code extraction: " );
302         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "SN extraction: " );
311         if ( Test.testExtractSNFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy extraction (general): " );
320         if ( Test.testTaxonomyExtraction() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Uri for Aptx web sequence accession: " );
329         if ( Test.testCreateUriForSeqWeb() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Basic node construction and parsing of NHX (node level): " );
338         if ( Test.testNHXNodeParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing iterating: " );
347         if ( Test.testNHParsingIter() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NH parsing: " );
356         if ( Test.testNHParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Conversion to NHX (node level): " );
365         if ( Test.testNHXconversion() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NHX parsing: " );
374         if ( Test.testNHXParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing with quotes: " );
383         if ( Test.testNHXParsingQuotes() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing (MrBayes): " );
392         if ( Test.testNHXParsingMB() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus characters parsing: " );
401         if ( Test.testNexusCharactersParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus tree parsing iterating: " );
410         if ( Test.testNexusTreeParsingIterating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus tree parsing: " );
419         if ( Test.testNexusTreeParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing (translating): " );
428         if ( Test.testNexusTreeParsingTranslating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus matrix parsing: " );
437         if ( Test.testNexusMatrixParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Basic phyloXML parsing: " );
446         if ( Test.testBasicPhyloXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic phyloXML parsing (validating against schema): " );
455         if ( testBasicPhyloXMLparsingValidating() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
464         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "phyloXML Distribution Element: " );
473         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Tol XML parsing: " );
482         if ( Test.testBasicTolXMLparsing() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Copying of node data: " );
491         if ( Test.testCopyOfNodeData() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tree copy: " );
500         if ( Test.testTreeCopy() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Basic tree methods: " );
509         if ( Test.testBasicTreeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree methods: " );
518         if ( Test.testTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Postorder Iterator: " );
527         if ( Test.testPostOrderIterator() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Preorder Iterator: " );
536         if ( Test.testPreOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Levelorder Iterator: " );
545         if ( Test.testLevelOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Re-id methods: " );
554         if ( Test.testReIdMethods() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Methods on last external nodes: " );
563         if ( Test.testLastExternalNodeMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on external nodes: " );
572         if ( Test.testExternalNodeRelatedMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Deletion of external nodes: " );
581         if ( Test.testDeletionOfExternalNodes() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Subtree deletion: " );
590         if ( Test.testSubtreeDeletion() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Phylogeny branch: " );
599         if ( Test.testPhylogenyBranch() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Rerooting: " );
608         if ( Test.testRerooting() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Mipoint rooting: " );
617         if ( Test.testMidpointrooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Node removal: " );
626         if ( Test.testNodeRemoval() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Support count: " );
635         if ( Test.testSupportCount() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support transfer: " );
644         if ( Test.testSupportTransfer() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Finding of LCA: " );
653         if ( Test.testGetLCA() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Finding of LCA 2: " );
662         if ( Test.testGetLCA2() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Calculation of distance between nodes: " );
671         if ( Test.testGetDistance() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Descriptive statistics: " );
680         if ( Test.testDescriptiveStatistics() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Data objects and methods: " );
689         if ( Test.testDataObjects() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Properties map: " );
698         if ( Test.testPropertiesMap() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "SDIse: " );
707         if ( Test.testSDIse() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIunrooted: " );
716         if ( Test.testSDIunrooted() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "GSDI: " );
725         if ( TestGSDI.test() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "RIO: " );
734         if ( TestRIO.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Phylogeny reconstruction:" );
743         System.out.println();
744         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "Analysis of domain architectures: " );
753         System.out.println();
754         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "GO: " );
763         System.out.println();
764         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Modeling tools: " );
773         if ( TestPccx.test() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Split Matrix strict: " );
782         if ( Test.testSplitStrict() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix: " );
791         if ( Test.testSplit() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Confidence Assessor: " );
800         if ( Test.testConfidenceAssessor() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Basic table: " );
809         if ( Test.testBasicTable() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "General table: " );
818         if ( Test.testGeneralTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Amino acid sequence: " );
827         if ( Test.testAminoAcidSequence() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General MSA parser: " );
836         if ( Test.testGeneralMsaParser() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Fasta parser for msa: " );
845         if ( Test.testFastaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Creation of balanced phylogeny: " );
854         if ( Test.testCreateBalancedPhylogeny() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Genbank accessor parsing: " );
863         if ( Test.testGenbankAccessorParsing() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         String path = "";
872         final String os = ForesterUtil.OS_NAME.toLowerCase();
873         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
874             path = "/usr/local/bin/mafft";
875         }
876         else if ( os.indexOf( "win" ) >= 0 ) {
877             path = "C:\\Program Files\\mafft-win\\mafft.bat";
878         }
879         else {
880             path = "mafft";
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/bin/mafft";
883             }
884             if ( !MsaInferrer.isInstalled( path ) ) {
885                 path = "/usr/local/bin/mafft";
886             }
887         }
888         if ( MsaInferrer.isInstalled( path ) ) {
889             System.out.print( "MAFFT (external program): " );
890             if ( Test.testMafft( path ) ) {
891                 System.out.println( "OK." );
892                 succeeded++;
893             }
894             else {
895                 System.out.println( "failed [will not count towards failed tests]" );
896             }
897         }
898         System.out.print( "Next nodes with collapsed: " );
899         if ( Test.testNextNodeWithCollapsing() ) {
900             System.out.println( "OK." );
901             succeeded++;
902         }
903         else {
904             System.out.println( "failed." );
905             failed++;
906         }
907         System.out.print( "Simple MSA quality: " );
908         if ( Test.testMsaQualityMethod() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Deleteable MSA: " );
917         if ( Test.testDeleteableMsa() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         if ( PERFORM_DB_TESTS ) {
926             System.out.print( "Uniprot Entry Retrieval: " );
927             if ( Test.testUniprotEntryRetrieval() ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed." );
933                 failed++;
934             }
935             System.out.print( "Ebi Entry Retrieval: " );
936             if ( Test.testEbiEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Sequence DB tools 2: " );
945             if ( testSequenceDbWsTools2() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952                 System.exit( -1 );
953             }
954             System.out.print( "Uniprot Taxonomy Search: " );
955             if ( Test.testUniprotTaxonomySearch() ) {
956                 System.out.println( "OK." );
957                 succeeded++;
958             }
959             else {
960                 System.out.println( "failed." );
961                 failed++;
962             }
963         }
964         if ( PERFORM_WEB_TREE_ACCESS ) {
965             System.out.print( "NHX parsing from URL: " );
966             if ( Test.testNHXparsingFromURL() ) {
967                 System.out.println( "OK." );
968                 succeeded++;
969             }
970             else {
971                 System.out.println( "failed." );
972                 failed++;
973             }
974             System.out.print( "NHX parsing from URL 2: " );
975             if ( Test.testNHXparsingFromURL2() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "phyloXML parsing from URL: " );
984             if ( Test.testPhyloXMLparsingFromURL() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             System.out.print( "TreeBase acccess: " );
993             if ( Test.testTreeBaseReading() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             //
1002             System.out.print( "ToL access: " );
1003             if ( Test.testToLReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             //
1012             System.out.print( "TreeFam access: " );
1013             if ( Test.testTreeFamReading() ) {
1014                 System.out.println( "OK." );
1015                 succeeded++;
1016             }
1017             else {
1018                 System.out.println( "failed." );
1019                 failed++;
1020             }
1021             //
1022             //
1023             System.out.print( "Pfam tree access: " );
1024             if ( Test.testPfamTreeReading() ) {
1025                 System.out.println( "OK." );
1026                 succeeded++;
1027             }
1028             else {
1029                 System.out.println( "failed." );
1030                 failed++;
1031             }
1032         }
1033         System.out.println();
1034         final Runtime rt = java.lang.Runtime.getRuntime();
1035         final long free_memory = rt.freeMemory() / 1000000;
1036         final long total_memory = rt.totalMemory() / 1000000;
1037         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1038                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1039         System.out.println();
1040         System.out.println( "Successful tests: " + succeeded );
1041         System.out.println( "Failed     tests: " + failed );
1042         System.out.println();
1043         if ( failed < 1 ) {
1044             System.out.println( "OK." );
1045         }
1046         else {
1047             System.out.println( "Not OK." );
1048         }
1049     }
1050
1051     public static boolean testEngulfingOverlapRemoval() {
1052         try {
1053             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1054             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1055             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1056             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1057             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1058             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1059             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1060             final List<Boolean> covered = new ArrayList<Boolean>();
1061             covered.add( true ); // 0
1062             covered.add( false ); // 1
1063             covered.add( true ); // 2
1064             covered.add( false ); // 3
1065             covered.add( true ); // 4
1066             covered.add( true ); // 5
1067             covered.add( false ); // 6
1068             covered.add( true ); // 7
1069             covered.add( true ); // 8
1070             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1071                 return false;
1072             }
1073             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1074                 return false;
1075             }
1076             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1077                 return false;
1078             }
1079             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1086                 return false;
1087             }
1088             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1089                 return false;
1090             }
1091             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1092             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1093             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1094             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1095             abc.addProteinDomain( a );
1096             abc.addProteinDomain( b );
1097             abc.addProteinDomain( c );
1098             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1099             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1100             if ( abc.getNumberOfProteinDomains() != 3 ) {
1101                 return false;
1102             }
1103             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1104                 return false;
1105             }
1106             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1107                 return false;
1108             }
1109             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1110                 return false;
1111             }
1112             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1113                 return false;
1114             }
1115             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1116             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1117             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1118             final Protein def = new BasicProtein( "def", "nemve", 0 );
1119             def.addProteinDomain( d );
1120             def.addProteinDomain( e );
1121             def.addProteinDomain( f );
1122             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1123             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1124             if ( def.getNumberOfProteinDomains() != 3 ) {
1125                 return false;
1126             }
1127             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1128                 return false;
1129             }
1130             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1131                 return false;
1132             }
1133             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1134                 return false;
1135             }
1136             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1137                 return false;
1138             }
1139             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1140                 return false;
1141             }
1142         }
1143         catch ( final Exception e ) {
1144             e.printStackTrace( System.out );
1145             return false;
1146         }
1147         return true;
1148     }
1149
1150     public static final boolean testNHXparsingFromURL2() {
1151         try {
1152             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1153             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1154                                                                       false,
1155                                                                       false,
1156                                                                       false,
1157                                                                       TAXONOMY_EXTRACTION.NO,
1158                                                                       false );
1159             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1160                 return false;
1161             }
1162             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1163                 System.out.println( phys[ 0 ].toNewHampshire() );
1164                 return false;
1165             }
1166             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1167                 System.out.println( phys[ 1 ].toNewHampshire() );
1168                 return false;
1169             }
1170             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1171                                                                        false,
1172                                                                        false,
1173                                                                        false,
1174                                                                        TAXONOMY_EXTRACTION.NO,
1175                                                                        false );
1176             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1177                 return false;
1178             }
1179             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1180                 System.out.println( phys2[ 0 ].toNewHampshire() );
1181                 return false;
1182             }
1183             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1184                 System.out.println( phys2[ 1 ].toNewHampshire() );
1185                 return false;
1186             }
1187             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1188                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1189             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1190                 return false;
1191             }
1192             if ( !phys3[ 0 ]
1193                     .toNewHampshire()
1194                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1195                 System.out.println( phys3[ 0 ].toNewHampshire() );
1196                 return false;
1197             }
1198             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1199                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1200             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1201                 return false;
1202             }
1203             if ( !phys4[ 0 ]
1204                     .toNewHampshire()
1205                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1206                 System.out.println( phys4[ 0 ].toNewHampshire() );
1207                 return false;
1208             }
1209         }
1210         catch ( final Exception e ) {
1211             e.printStackTrace();
1212         }
1213         return true;
1214     }
1215
1216     public static final boolean testNHXparsingFromURL() {
1217         try {
1218             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1219             final URL u = new URL( s );
1220             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1221             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1222             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1223                 return false;
1224             }
1225             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1226                 System.out.println( phys[ 0 ].toNewHampshire() );
1227                 return false;
1228             }
1229             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1230                 System.out.println( phys[ 1 ].toNewHampshire() );
1231                 return false;
1232             }
1233             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1234             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1235                 return false;
1236             }
1237             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1238                 System.out.println( phys2[ 0 ].toNewHampshire() );
1239                 return false;
1240             }
1241             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1242             final NHXParser p = new NHXParser();
1243             final URL u2 = new URL( s );
1244             p.setSource( u2 );
1245             if ( !p.hasNext() ) {
1246                 return false;
1247             }
1248             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1249                 return false;
1250             }
1251             if ( !p.hasNext() ) {
1252                 return false;
1253             }
1254             p.reset();
1255             if ( !p.hasNext() ) {
1256                 return false;
1257             }
1258             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1259                 return false;
1260             }
1261             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1262                 return false;
1263             }
1264             p.reset();
1265             if ( !p.hasNext() ) {
1266                 return false;
1267             }
1268             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1269                 return false;
1270             }
1271             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1272                 return false;
1273             }
1274         }
1275         catch ( final Exception e ) {
1276             e.printStackTrace();
1277         }
1278         return true;
1279     }
1280
1281     public static boolean testOverlapRemoval() {
1282         try {
1283             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1284             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1285             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1286             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1287             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1288             final List<Boolean> covered = new ArrayList<Boolean>();
1289             covered.add( true ); // 0
1290             covered.add( false ); // 1
1291             covered.add( true ); // 2
1292             covered.add( false ); // 3
1293             covered.add( true ); // 4
1294             covered.add( true ); // 5
1295             covered.add( false ); // 6
1296             covered.add( true ); // 7
1297             covered.add( true ); // 8
1298             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1299                 return false;
1300             }
1301             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1302                 return false;
1303             }
1304             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1305                 return false;
1306             }
1307             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1308                 return false;
1309             }
1310             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1311                 return false;
1312             }
1313             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1314             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1315             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1316             ab.addProteinDomain( a );
1317             ab.addProteinDomain( b );
1318             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1319             if ( ab.getNumberOfProteinDomains() != 2 ) {
1320                 return false;
1321             }
1322             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1323                 return false;
1324             }
1325             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1326                 return false;
1327             }
1328             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1329             if ( ab.getNumberOfProteinDomains() != 2 ) {
1330                 return false;
1331             }
1332             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1333                 return false;
1334             }
1335             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1336             final Domain d = new BasicDomain( "d",
1337                                               ( short ) 10000,
1338                                               ( short ) 10500,
1339                                               ( short ) 1,
1340                                               ( short ) 1,
1341                                               0.0000001,
1342                                               1 );
1343             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1344             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1345             cde.addProteinDomain( c );
1346             cde.addProteinDomain( d );
1347             cde.addProteinDomain( e );
1348             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1349             if ( cde.getNumberOfProteinDomains() != 3 ) {
1350                 return false;
1351             }
1352             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1353                 return false;
1354             }
1355             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1356             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1357             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1358             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1359             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1360             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1361             fghi.addProteinDomain( f );
1362             fghi.addProteinDomain( g );
1363             fghi.addProteinDomain( h );
1364             fghi.addProteinDomain( i );
1365             fghi.addProteinDomain( i );
1366             fghi.addProteinDomain( i );
1367             fghi.addProteinDomain( i2 );
1368             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1369             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1370                 return false;
1371             }
1372             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1373                 return false;
1374             }
1375             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1376                 return false;
1377             }
1378             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1379             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1380                 return false;
1381             }
1382             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1383                 return false;
1384             }
1385             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1386             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1387             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1388             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1389             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1390             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1391             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1392             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1393             jklm.addProteinDomain( j );
1394             jklm.addProteinDomain( k );
1395             jklm.addProteinDomain( l );
1396             jklm.addProteinDomain( m );
1397             jklm.addProteinDomain( m0 );
1398             jklm.addProteinDomain( m1 );
1399             jklm.addProteinDomain( m2 );
1400             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1401             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1402                 return false;
1403             }
1404             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1405                 return false;
1406             }
1407             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1408                 return false;
1409             }
1410             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1411             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1412                 return false;
1413             }
1414             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1415                 return false;
1416             }
1417             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1418             final Protein od = new BasicProtein( "od", "varanus", 0 );
1419             od.addProteinDomain( only );
1420             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1421             if ( od.getNumberOfProteinDomains() != 1 ) {
1422                 return false;
1423             }
1424             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1425                 return false;
1426             }
1427         }
1428         catch ( final Exception e ) {
1429             e.printStackTrace( System.out );
1430             return false;
1431         }
1432         return true;
1433     }
1434
1435     public static final boolean testPfamTreeReading() {
1436         try {
1437             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1438             final NHXParser parser = new NHXParser();
1439             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1440             parser.setReplaceUnderscores( false );
1441             parser.setGuessRootedness( true );
1442             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1443             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1444             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1445                 return false;
1446             }
1447             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1448                 return false;
1449             }
1450         }
1451         catch ( final Exception e ) {
1452             e.printStackTrace();
1453         }
1454         return true;
1455     }
1456
1457     public static final boolean testPhyloXMLparsingFromURL() {
1458         try {
1459             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1460             final URL u = new URL( s );
1461             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1462             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1463             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1464                 return false;
1465             }
1466         }
1467         catch ( final Exception e ) {
1468             e.printStackTrace();
1469         }
1470         return true;
1471     }
1472
1473     public static final boolean testToLReading() {
1474         try {
1475             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1476             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1477             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1478             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1479                 return false;
1480             }
1481             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1482                 return false;
1483             }
1484             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1485                 return false;
1486             }
1487             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1488                 return false;
1489             }
1490         }
1491         catch ( final Exception e ) {
1492             e.printStackTrace();
1493         }
1494         return true;
1495     }
1496
1497     public static final boolean testTreeBaseReading() {
1498         try {
1499             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1500             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1501             parser.setReplaceUnderscores( true );
1502             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1503             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1504             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1505                 return false;
1506             }
1507             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1508             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1509             parser2.setReplaceUnderscores( true );
1510             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1511             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1512             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1513                 return false;
1514             }
1515         }
1516         catch ( final Exception e ) {
1517             e.printStackTrace();
1518         }
1519         return true;
1520     }
1521
1522     public static final boolean testTreeFamReading() {
1523         try {
1524             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1525             final NHXParser parser = new NHXParser();
1526             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1527             parser.setReplaceUnderscores( false );
1528             parser.setGuessRootedness( true );
1529             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1530             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1531             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1532                 return false;
1533             }
1534             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1535                 return false;
1536             }
1537         }
1538         catch ( final Exception e ) {
1539             e.printStackTrace();
1540         }
1541         return true;
1542     }
1543
1544     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1545         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1546         return p;
1547     }
1548
1549     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1550         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1551     }
1552
1553     private static boolean testAminoAcidSequence() {
1554         try {
1555             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1556             if ( aa1.getLength() != 13 ) {
1557                 return false;
1558             }
1559             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1560                 return false;
1561             }
1562             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1563                 return false;
1564             }
1565             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1566                 return false;
1567             }
1568             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1569             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1570                 return false;
1571             }
1572             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1573             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1574                 return false;
1575             }
1576             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1577             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1578                 return false;
1579             }
1580         }
1581         catch ( final Exception e ) {
1582             e.printStackTrace();
1583             return false;
1584         }
1585         return true;
1586     }
1587
1588     private static boolean testBasicDomain() {
1589         try {
1590             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1591             if ( !pd.getDomainId().equals( "id" ) ) {
1592                 return false;
1593             }
1594             if ( pd.getNumber() != 1 ) {
1595                 return false;
1596             }
1597             if ( pd.getTotalCount() != 4 ) {
1598                 return false;
1599             }
1600             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1601                 return false;
1602             }
1603             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1604             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1605             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1606             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1607             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1608             if ( !a1.equals( a1 ) ) {
1609                 return false;
1610             }
1611             if ( !a1.equals( a1_copy ) ) {
1612                 return false;
1613             }
1614             if ( !a1.equals( a1_equal ) ) {
1615                 return false;
1616             }
1617             if ( !a1.equals( a2 ) ) {
1618                 return false;
1619             }
1620             if ( a1.equals( a3 ) ) {
1621                 return false;
1622             }
1623             if ( a1.compareTo( a1 ) != 0 ) {
1624                 return false;
1625             }
1626             if ( a1.compareTo( a1_copy ) != 0 ) {
1627                 return false;
1628             }
1629             if ( a1.compareTo( a1_equal ) != 0 ) {
1630                 return false;
1631             }
1632             if ( a1.compareTo( a2 ) != 0 ) {
1633                 return false;
1634             }
1635             if ( a1.compareTo( a3 ) == 0 ) {
1636                 return false;
1637             }
1638         }
1639         catch ( final Exception e ) {
1640             e.printStackTrace( System.out );
1641             return false;
1642         }
1643         return true;
1644     }
1645
1646     private static boolean testBasicNodeMethods() {
1647         try {
1648             if ( PhylogenyNode.getNodeCount() != 0 ) {
1649                 return false;
1650             }
1651             final PhylogenyNode n1 = new PhylogenyNode();
1652             final PhylogenyNode n2 = PhylogenyNode
1653                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1654             final PhylogenyNode n3 = PhylogenyNode
1655                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1656             final PhylogenyNode n4 = PhylogenyNode
1657                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1658             if ( n1.isHasAssignedEvent() ) {
1659                 return false;
1660             }
1661             if ( PhylogenyNode.getNodeCount() != 4 ) {
1662                 return false;
1663             }
1664             if ( n3.getIndicator() != 0 ) {
1665                 return false;
1666             }
1667             if ( n3.getNumberOfExternalNodes() != 1 ) {
1668                 return false;
1669             }
1670             if ( !n3.isExternal() ) {
1671                 return false;
1672             }
1673             if ( !n3.isRoot() ) {
1674                 return false;
1675             }
1676             if ( !n4.getName().equals( "n4" ) ) {
1677                 return false;
1678             }
1679         }
1680         catch ( final Exception e ) {
1681             e.printStackTrace( System.out );
1682             return false;
1683         }
1684         return true;
1685     }
1686
1687     private static boolean testBasicPhyloXMLparsing() {
1688         try {
1689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1690             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1691             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1692                                                               xml_parser );
1693             if ( xml_parser.getErrorCount() > 0 ) {
1694                 System.out.println( xml_parser.getErrorMessages().toString() );
1695                 return false;
1696             }
1697             if ( phylogenies_0.length != 4 ) {
1698                 return false;
1699             }
1700             final Phylogeny t1 = phylogenies_0[ 0 ];
1701             final Phylogeny t2 = phylogenies_0[ 1 ];
1702             final Phylogeny t3 = phylogenies_0[ 2 ];
1703             final Phylogeny t4 = phylogenies_0[ 3 ];
1704             if ( t1.getNumberOfExternalNodes() != 1 ) {
1705                 return false;
1706             }
1707             if ( !t1.isRooted() ) {
1708                 return false;
1709             }
1710             if ( t1.isRerootable() ) {
1711                 return false;
1712             }
1713             if ( !t1.getType().equals( "gene_tree" ) ) {
1714                 return false;
1715             }
1716             if ( t2.getNumberOfExternalNodes() != 2 ) {
1717                 return false;
1718             }
1719             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1720                 return false;
1721             }
1722             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1723                 return false;
1724             }
1725             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1726                 return false;
1727             }
1728             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1729                 return false;
1730             }
1731             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1732                 return false;
1733             }
1734             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1735                 return false;
1736             }
1737             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1738                     .startsWith( "actgtgggggt" ) ) {
1739                 return false;
1740             }
1741             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1742                     .startsWith( "ctgtgatgcat" ) ) {
1743                 return false;
1744             }
1745             if ( t3.getNumberOfExternalNodes() != 4 ) {
1746                 return false;
1747             }
1748             if ( !t1.getName().equals( "t1" ) ) {
1749                 return false;
1750             }
1751             if ( !t2.getName().equals( "t2" ) ) {
1752                 return false;
1753             }
1754             if ( !t3.getName().equals( "t3" ) ) {
1755                 return false;
1756             }
1757             if ( !t4.getName().equals( "t4" ) ) {
1758                 return false;
1759             }
1760             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1761                 return false;
1762             }
1763             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1764                 return false;
1765             }
1766             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1767                 return false;
1768             }
1769             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1770                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1771                 return false;
1772             }
1773             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1774                 return false;
1775             }
1776             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1777                 return false;
1778             }
1779             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1780                 return false;
1781             }
1782             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1783                     .equals( "apoptosis" ) ) {
1784                 return false;
1785             }
1786             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1787                     .equals( "GO:0006915" ) ) {
1788                 return false;
1789             }
1790             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1791                     .equals( "UniProtKB" ) ) {
1792                 return false;
1793             }
1794             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1795                     .equals( "experimental" ) ) {
1796                 return false;
1797             }
1798             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1799                     .equals( "function" ) ) {
1800                 return false;
1801             }
1802             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1803                     .getValue() != 1 ) {
1804                 return false;
1805             }
1806             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1807                     .getType().equals( "ml" ) ) {
1808                 return false;
1809             }
1810             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1811                     .equals( "apoptosis" ) ) {
1812                 return false;
1813             }
1814             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1815                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1816                 return false;
1817             }
1818             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1819                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1820                 return false;
1821             }
1822             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1823                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1824                 return false;
1825             }
1826             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1827                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1828                 return false;
1829             }
1830             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1831                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1832                 return false;
1833             }
1834             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1835                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1836                 return false;
1837             }
1838             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1839                     .equals( "GO:0005829" ) ) {
1840                 return false;
1841             }
1842             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1843                     .equals( "intracellular organelle" ) ) {
1844                 return false;
1845             }
1846             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1847                 return false;
1848             }
1849             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1850                     .equals( "UniProt link" ) ) ) {
1851                 return false;
1852             }
1853             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1854                 return false;
1855             }
1856             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1857             if ( x.size() != 4 ) {
1858                 return false;
1859             }
1860             int c = 0;
1861             for( final Accession acc : x ) {
1862                 if ( c == 0 ) {
1863                     if ( !acc.getSource().equals( "KEGG" ) ) {
1864                         return false;
1865                     }
1866                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1867                         return false;
1868                     }
1869                 }
1870                 c++;
1871             }
1872         }
1873         catch ( final Exception e ) {
1874             e.printStackTrace( System.out );
1875             return false;
1876         }
1877         return true;
1878     }
1879
1880     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1881         try {
1882             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1883             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1884             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1885                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1886             }
1887             else {
1888                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1889             }
1890             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1891                                                               xml_parser );
1892             if ( xml_parser.getErrorCount() > 0 ) {
1893                 System.out.println( xml_parser.getErrorMessages().toString() );
1894                 return false;
1895             }
1896             if ( phylogenies_0.length != 4 ) {
1897                 return false;
1898             }
1899             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1900             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1901             if ( phylogenies_t1.length != 1 ) {
1902                 return false;
1903             }
1904             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1905             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1906                 return false;
1907             }
1908             if ( !t1_rt.isRooted() ) {
1909                 return false;
1910             }
1911             if ( t1_rt.isRerootable() ) {
1912                 return false;
1913             }
1914             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1915                 return false;
1916             }
1917             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1918             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1919             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1920             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1921                 return false;
1922             }
1923             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1924                 return false;
1925             }
1926             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1927                 return false;
1928             }
1929             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1930                 return false;
1931             }
1932             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1933                     .startsWith( "actgtgggggt" ) ) {
1934                 return false;
1935             }
1936             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1937                     .startsWith( "ctgtgatgcat" ) ) {
1938                 return false;
1939             }
1940             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1941             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1942             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1943             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1944             if ( phylogenies_1.length != 1 ) {
1945                 return false;
1946             }
1947             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1948             if ( !t3_rt.getName().equals( "t3" ) ) {
1949                 return false;
1950             }
1951             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1952                 return false;
1953             }
1954             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1955                 return false;
1956             }
1957             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1958                 return false;
1959             }
1960             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1961                 return false;
1962             }
1963             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1964                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1974                     .equals( "UniProtKB" ) ) {
1975                 return false;
1976             }
1977             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1978                     .equals( "apoptosis" ) ) {
1979                 return false;
1980             }
1981             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1982                     .equals( "GO:0006915" ) ) {
1983                 return false;
1984             }
1985             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1986                     .equals( "UniProtKB" ) ) {
1987                 return false;
1988             }
1989             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1990                     .equals( "experimental" ) ) {
1991                 return false;
1992             }
1993             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1994                     .equals( "function" ) ) {
1995                 return false;
1996             }
1997             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1998                     .getValue() != 1 ) {
1999                 return false;
2000             }
2001             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2002                     .getType().equals( "ml" ) ) {
2003                 return false;
2004             }
2005             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2006                     .equals( "apoptosis" ) ) {
2007                 return false;
2008             }
2009             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2010                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2011                 return false;
2012             }
2013             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2014                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2015                 return false;
2016             }
2017             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2018                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2019                 return false;
2020             }
2021             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2022                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2023                 return false;
2024             }
2025             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2026                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2027                 return false;
2028             }
2029             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2030                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2031                 return false;
2032             }
2033             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2034                     .equals( "GO:0005829" ) ) {
2035                 return false;
2036             }
2037             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2038                     .equals( "intracellular organelle" ) ) {
2039                 return false;
2040             }
2041             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2042                 return false;
2043             }
2044             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2045                     .equals( "UniProt link" ) ) ) {
2046                 return false;
2047             }
2048             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2049                 return false;
2050             }
2051             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2052                 return false;
2053             }
2054             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2055                     .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) {
2056                 return false;
2057             }
2058             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2059                 return false;
2060             }
2061             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2062                 return false;
2063             }
2064             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2065                 return false;
2066             }
2067             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2068                 return false;
2069             }
2070             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2071                     .equals( "ncbi" ) ) {
2072                 return false;
2073             }
2074             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2075                 return false;
2076             }
2077             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2078                     .getName().equals( "B" ) ) {
2079                 return false;
2080             }
2081             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2082                     .getFrom() != 21 ) {
2083                 return false;
2084             }
2085             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2086                 return false;
2087             }
2088             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2089                     .getLength() != 24 ) {
2090                 return false;
2091             }
2092             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2093                     .getConfidence() != 2144 ) {
2094                 return false;
2095             }
2096             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2097                     .equals( "pfam" ) ) {
2098                 return false;
2099             }
2100             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2101                 return false;
2102             }
2103             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2104                 return false;
2105             }
2106             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2107                 return false;
2108             }
2109             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2110                 return false;
2111             }
2112             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2113             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2114                 return false;
2115             }
2116             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2117                 return false;
2118             }
2119             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2120                 return false;
2121             }
2122             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2123                 return false;
2124             }
2125             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2126                 return false;
2127             }
2128             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2129                 return false;
2130             }
2131             if ( taxbb.getSynonyms().size() != 2 ) {
2132                 return false;
2133             }
2134             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2135                 return false;
2136             }
2137             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2138                 return false;
2139             }
2140             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2141                 return false;
2142             }
2143             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2144                 return false;
2145             }
2146             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2147                 return false;
2148             }
2149             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2150                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2151                 return false;
2152             }
2153             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2154                 return false;
2155             }
2156             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2157                 return false;
2158             }
2159             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2160                 return false;
2161             }
2162             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2163                 return false;
2164             }
2165             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2166                 return false;
2167             }
2168             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2169                 return false;
2170             }
2171             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2172                 return false;
2173             }
2174             //
2175             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2176                 return false;
2177             }
2178             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2179                     .equalsIgnoreCase( "435" ) ) {
2180                 return false;
2181             }
2182             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2183                 return false;
2184             }
2185             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2186                     .equalsIgnoreCase( "443.7" ) ) {
2187                 return false;
2188             }
2189             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2190                 return false;
2191             }
2192             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2193                 return false;
2194             }
2195             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2196                     .equalsIgnoreCase( "433" ) ) {
2197                 return false;
2198             }
2199             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2200                     .getCrossReferences();
2201             if ( x.size() != 4 ) {
2202                 return false;
2203             }
2204             int c = 0;
2205             for( final Accession acc : x ) {
2206                 if ( c == 0 ) {
2207                     if ( !acc.getSource().equals( "KEGG" ) ) {
2208                         return false;
2209                     }
2210                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2211                         return false;
2212                     }
2213                 }
2214                 c++;
2215             }
2216         }
2217         catch ( final Exception e ) {
2218             e.printStackTrace( System.out );
2219             return false;
2220         }
2221         return true;
2222     }
2223
2224     private static boolean testBasicPhyloXMLparsingValidating() {
2225         try {
2226             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2227             PhyloXmlParser xml_parser = null;
2228             try {
2229                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2230             }
2231             catch ( final Exception e ) {
2232                 // Do nothing -- means were not running from jar.
2233             }
2234             if ( xml_parser == null ) {
2235                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2236                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2237                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2238                 }
2239                 else {
2240                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2241                 }
2242             }
2243             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2244                                                               xml_parser );
2245             if ( xml_parser.getErrorCount() > 0 ) {
2246                 System.out.println( xml_parser.getErrorMessages().toString() );
2247                 return false;
2248             }
2249             if ( phylogenies_0.length != 4 ) {
2250                 return false;
2251             }
2252             final Phylogeny t1 = phylogenies_0[ 0 ];
2253             final Phylogeny t2 = phylogenies_0[ 1 ];
2254             final Phylogeny t3 = phylogenies_0[ 2 ];
2255             final Phylogeny t4 = phylogenies_0[ 3 ];
2256             if ( !t1.getName().equals( "t1" ) ) {
2257                 return false;
2258             }
2259             if ( !t2.getName().equals( "t2" ) ) {
2260                 return false;
2261             }
2262             if ( !t3.getName().equals( "t3" ) ) {
2263                 return false;
2264             }
2265             if ( !t4.getName().equals( "t4" ) ) {
2266                 return false;
2267             }
2268             if ( t1.getNumberOfExternalNodes() != 1 ) {
2269                 return false;
2270             }
2271             if ( t2.getNumberOfExternalNodes() != 2 ) {
2272                 return false;
2273             }
2274             if ( t3.getNumberOfExternalNodes() != 4 ) {
2275                 return false;
2276             }
2277             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2278             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2279             if ( xml_parser.getErrorCount() > 0 ) {
2280                 System.out.println( "errors:" );
2281                 System.out.println( xml_parser.getErrorMessages().toString() );
2282                 return false;
2283             }
2284             if ( phylogenies_1.length != 4 ) {
2285                 return false;
2286             }
2287             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2288                                                               xml_parser );
2289             if ( xml_parser.getErrorCount() > 0 ) {
2290                 System.out.println( "errors:" );
2291                 System.out.println( xml_parser.getErrorMessages().toString() );
2292                 return false;
2293             }
2294             if ( phylogenies_2.length != 1 ) {
2295                 return false;
2296             }
2297             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2298                 return false;
2299             }
2300             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2301                                                               xml_parser );
2302             if ( xml_parser.getErrorCount() > 0 ) {
2303                 System.out.println( xml_parser.getErrorMessages().toString() );
2304                 return false;
2305             }
2306             if ( phylogenies_3.length != 2 ) {
2307                 return false;
2308             }
2309             final Phylogeny a = phylogenies_3[ 0 ];
2310             if ( !a.getName().equals( "tree 4" ) ) {
2311                 return false;
2312             }
2313             if ( a.getNumberOfExternalNodes() != 3 ) {
2314                 return false;
2315             }
2316             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2317                 return false;
2318             }
2319             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2320                 return false;
2321             }
2322             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2323                                                               xml_parser );
2324             if ( xml_parser.getErrorCount() > 0 ) {
2325                 System.out.println( xml_parser.getErrorMessages().toString() );
2326                 return false;
2327             }
2328             if ( phylogenies_4.length != 1 ) {
2329                 return false;
2330             }
2331             final Phylogeny s = phylogenies_4[ 0 ];
2332             if ( s.getNumberOfExternalNodes() != 6 ) {
2333                 return false;
2334             }
2335             s.getNode( "first" );
2336             s.getNode( "<>" );
2337             s.getNode( "\"<a'b&c'd\">\"" );
2338             s.getNode( "'''\"" );
2339             s.getNode( "\"\"\"" );
2340             s.getNode( "dick & doof" );
2341         }
2342         catch ( final Exception e ) {
2343             e.printStackTrace( System.out );
2344             return false;
2345         }
2346         return true;
2347     }
2348
2349     private static boolean testBasicProtein() {
2350         try {
2351             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2352             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             p0.addProteinDomain( y );
2360             p0.addProteinDomain( e );
2361             p0.addProteinDomain( b );
2362             p0.addProteinDomain( c );
2363             p0.addProteinDomain( d );
2364             p0.addProteinDomain( a );
2365             p0.addProteinDomain( x );
2366             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2367                 return false;
2368             }
2369             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2370                 return false;
2371             }
2372             //
2373             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2374             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             aa0.addProteinDomain( a1 );
2376             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2377                 return false;
2378             }
2379             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2380                 return false;
2381             }
2382             //
2383             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2384             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2385             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2386             aa1.addProteinDomain( a11 );
2387             aa1.addProteinDomain( a12 );
2388             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2389                 return false;
2390             }
2391             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2392                 return false;
2393             }
2394             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2395             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2396                 return false;
2397             }
2398             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2399                 return false;
2400             }
2401             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2402                 return false;
2403             }
2404             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2405             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2406                 return false;
2407             }
2408             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2409                 return false;
2410             }
2411             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2412                 return false;
2413             }
2414             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2415                 return false;
2416             }
2417             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2418             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2419                 return false;
2420             }
2421             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2422                 return false;
2423             }
2424             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2425                 return false;
2426             }
2427             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2428                 return false;
2429             }
2430             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2431             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2432                 return false;
2433             }
2434             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2435                 return false;
2436             }
2437             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2438                 return false;
2439             }
2440             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2441                 return false;
2442             }
2443             //
2444             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2445             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2446             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2447             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2448             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2449             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2450             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2451             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2452             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2453             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2454             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2455             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2456             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2457             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2458             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2459             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2460             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2461             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2462             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2463             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2464             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2465             p00.addProteinDomain( y0 );
2466             p00.addProteinDomain( e0 );
2467             p00.addProteinDomain( b0 );
2468             p00.addProteinDomain( c0 );
2469             p00.addProteinDomain( d0 );
2470             p00.addProteinDomain( a0 );
2471             p00.addProteinDomain( x0 );
2472             p00.addProteinDomain( y1 );
2473             p00.addProteinDomain( y2 );
2474             p00.addProteinDomain( y3 );
2475             p00.addProteinDomain( e1 );
2476             p00.addProteinDomain( e2 );
2477             p00.addProteinDomain( e3 );
2478             p00.addProteinDomain( e4 );
2479             p00.addProteinDomain( e5 );
2480             p00.addProteinDomain( z0 );
2481             p00.addProteinDomain( z1 );
2482             p00.addProteinDomain( z2 );
2483             p00.addProteinDomain( zz0 );
2484             p00.addProteinDomain( zz1 );
2485             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2486                 return false;
2487             }
2488             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2489                 return false;
2490             }
2491             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2492                 return false;
2493             }
2494             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2495                 return false;
2496             }
2497             if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2498                 return false;
2499             }
2500             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2501             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2502             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2503             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2504             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2505             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2506             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2507             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2508             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2509             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2510             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2511             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2512             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2513             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2514             p.addProteinDomain( B15 );
2515             p.addProteinDomain( C50 );
2516             p.addProteinDomain( A60 );
2517             p.addProteinDomain( A30 );
2518             p.addProteinDomain( C70 );
2519             p.addProteinDomain( B35 );
2520             p.addProteinDomain( B40 );
2521             p.addProteinDomain( A0 );
2522             p.addProteinDomain( A10 );
2523             p.addProteinDomain( A20 );
2524             p.addProteinDomain( B25 );
2525             p.addProteinDomain( D80 );
2526             List<String> domains_ids = new ArrayList<String>();
2527             domains_ids.add( "A" );
2528             domains_ids.add( "B" );
2529             domains_ids.add( "C" );
2530             if ( !p.contains( domains_ids, false ) ) {
2531                 return false;
2532             }
2533             if ( !p.contains( domains_ids, true ) ) {
2534                 return false;
2535             }
2536             domains_ids.add( "X" );
2537             if ( p.contains( domains_ids, false ) ) {
2538                 return false;
2539             }
2540             if ( p.contains( domains_ids, true ) ) {
2541                 return false;
2542             }
2543             domains_ids = new ArrayList<String>();
2544             domains_ids.add( "A" );
2545             domains_ids.add( "C" );
2546             domains_ids.add( "D" );
2547             if ( !p.contains( domains_ids, false ) ) {
2548                 return false;
2549             }
2550             if ( !p.contains( domains_ids, true ) ) {
2551                 return false;
2552             }
2553             domains_ids = new ArrayList<String>();
2554             domains_ids.add( "A" );
2555             domains_ids.add( "D" );
2556             domains_ids.add( "C" );
2557             if ( !p.contains( domains_ids, false ) ) {
2558                 return false;
2559             }
2560             if ( p.contains( domains_ids, true ) ) {
2561                 return false;
2562             }
2563             domains_ids = new ArrayList<String>();
2564             domains_ids.add( "A" );
2565             domains_ids.add( "A" );
2566             domains_ids.add( "B" );
2567             if ( !p.contains( domains_ids, false ) ) {
2568                 return false;
2569             }
2570             if ( !p.contains( domains_ids, true ) ) {
2571                 return false;
2572             }
2573             domains_ids = new ArrayList<String>();
2574             domains_ids.add( "A" );
2575             domains_ids.add( "A" );
2576             domains_ids.add( "A" );
2577             domains_ids.add( "B" );
2578             domains_ids.add( "B" );
2579             if ( !p.contains( domains_ids, false ) ) {
2580                 return false;
2581             }
2582             if ( !p.contains( domains_ids, true ) ) {
2583                 return false;
2584             }
2585             domains_ids = new ArrayList<String>();
2586             domains_ids.add( "A" );
2587             domains_ids.add( "A" );
2588             domains_ids.add( "B" );
2589             domains_ids.add( "A" );
2590             domains_ids.add( "B" );
2591             domains_ids.add( "B" );
2592             domains_ids.add( "A" );
2593             domains_ids.add( "B" );
2594             domains_ids.add( "C" );
2595             domains_ids.add( "A" );
2596             domains_ids.add( "C" );
2597             domains_ids.add( "D" );
2598             if ( !p.contains( domains_ids, false ) ) {
2599                 return false;
2600             }
2601             if ( p.contains( domains_ids, true ) ) {
2602                 return false;
2603             }
2604         }
2605         catch ( final Exception e ) {
2606             e.printStackTrace( System.out );
2607             return false;
2608         }
2609         return true;
2610     }
2611
2612     private static boolean testBasicTable() {
2613         try {
2614             final BasicTable<String> t0 = new BasicTable<String>();
2615             if ( t0.getNumberOfColumns() != 0 ) {
2616                 return false;
2617             }
2618             if ( t0.getNumberOfRows() != 0 ) {
2619                 return false;
2620             }
2621             t0.setValue( 3, 2, "23" );
2622             t0.setValue( 10, 1, "error" );
2623             t0.setValue( 10, 1, "110" );
2624             t0.setValue( 9, 1, "19" );
2625             t0.setValue( 1, 10, "101" );
2626             t0.setValue( 10, 10, "1010" );
2627             t0.setValue( 100, 10, "10100" );
2628             t0.setValue( 0, 0, "00" );
2629             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2630                 return false;
2631             }
2632             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2633                 return false;
2634             }
2635             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2636                 return false;
2637             }
2638             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2639                 return false;
2640             }
2641             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2642                 return false;
2643             }
2644             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2645                 return false;
2646             }
2647             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2648                 return false;
2649             }
2650             if ( t0.getNumberOfColumns() != 101 ) {
2651                 return false;
2652             }
2653             if ( t0.getNumberOfRows() != 11 ) {
2654                 return false;
2655             }
2656             if ( t0.getValueAsString( 49, 4 ) != null ) {
2657                 return false;
2658             }
2659             final String l = ForesterUtil.getLineSeparator();
2660             final StringBuffer source = new StringBuffer();
2661             source.append( "" + l );
2662             source.append( "# 1 1 1 1 1 1 1 1" + l );
2663             source.append( " 00 01 02 03" + l );
2664             source.append( "   10 11 12 13  " + l );
2665             source.append( "20 21 22 23 " + l );
2666             source.append( "    30  31    32 33" + l );
2667             source.append( "40 41 42 43" + l );
2668             source.append( "  # 1 1 1 1 1 " + l );
2669             source.append( "50 51 52 53 54" + l );
2670             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2671             if ( t1.getNumberOfColumns() != 5 ) {
2672                 return false;
2673             }
2674             if ( t1.getNumberOfRows() != 6 ) {
2675                 return false;
2676             }
2677             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2678                 return false;
2679             }
2680             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2681                 return false;
2682             }
2683             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2684                 return false;
2685             }
2686             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2687                 return false;
2688             }
2689             final StringBuffer source1 = new StringBuffer();
2690             source1.append( "" + l );
2691             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2692             source1.append( " 00; 01 ;02;03" + l );
2693             source1.append( "   10; 11; 12; 13  " + l );
2694             source1.append( "20; 21; 22; 23 " + l );
2695             source1.append( "    30;  31;    32; 33" + l );
2696             source1.append( "40;41;42;43" + l );
2697             source1.append( "  # 1 1 1 1 1 " + l );
2698             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2699             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2700             if ( t2.getNumberOfColumns() != 5 ) {
2701                 return false;
2702             }
2703             if ( t2.getNumberOfRows() != 6 ) {
2704                 return false;
2705             }
2706             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2707                 return false;
2708             }
2709             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2710                 return false;
2711             }
2712             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2713                 return false;
2714             }
2715             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2716                 return false;
2717             }
2718             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2719                 return false;
2720             }
2721             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2722                 return false;
2723             }
2724             final StringBuffer source2 = new StringBuffer();
2725             source2.append( "" + l );
2726             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2727             source2.append( " 00; 01 ;02;03" + l );
2728             source2.append( "   10; 11; 12; 13  " + l );
2729             source2.append( "20; 21; 22; 23 " + l );
2730             source2.append( "                     " + l );
2731             source2.append( "    30;  31;    32; 33" + l );
2732             source2.append( "40;41;42;43" + l );
2733             source2.append( "  comment: 1 1 1 1 1 " + l );
2734             source2.append( ";;;50  ;   52; 53;;54   " + l );
2735             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2736                                                                         ';',
2737                                                                         false,
2738                                                                         false,
2739                                                                         "comment:",
2740                                                                         false );
2741             if ( tl.size() != 2 ) {
2742                 return false;
2743             }
2744             final BasicTable<String> t3 = tl.get( 0 );
2745             final BasicTable<String> t4 = tl.get( 1 );
2746             if ( t3.getNumberOfColumns() != 4 ) {
2747                 return false;
2748             }
2749             if ( t3.getNumberOfRows() != 3 ) {
2750                 return false;
2751             }
2752             if ( t4.getNumberOfColumns() != 4 ) {
2753                 return false;
2754             }
2755             if ( t4.getNumberOfRows() != 3 ) {
2756                 return false;
2757             }
2758             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2759                 return false;
2760             }
2761             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2762                 return false;
2763             }
2764         }
2765         catch ( final Exception e ) {
2766             e.printStackTrace( System.out );
2767             return false;
2768         }
2769         return true;
2770     }
2771
2772     private static boolean testBasicTolXMLparsing() {
2773         try {
2774             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2775             final TolParser parser = new TolParser();
2776             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2777             if ( parser.getErrorCount() > 0 ) {
2778                 System.out.println( parser.getErrorMessages().toString() );
2779                 return false;
2780             }
2781             if ( phylogenies_0.length != 1 ) {
2782                 return false;
2783             }
2784             final Phylogeny t1 = phylogenies_0[ 0 ];
2785             if ( t1.getNumberOfExternalNodes() != 5 ) {
2786                 return false;
2787             }
2788             if ( !t1.isRooted() ) {
2789                 return false;
2790             }
2791             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2792                 return false;
2793             }
2794             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2795                 return false;
2796             }
2797             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2798                 return false;
2799             }
2800             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2801                 return false;
2802             }
2803             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2804             if ( parser.getErrorCount() > 0 ) {
2805                 System.out.println( parser.getErrorMessages().toString() );
2806                 return false;
2807             }
2808             if ( phylogenies_1.length != 1 ) {
2809                 return false;
2810             }
2811             final Phylogeny t2 = phylogenies_1[ 0 ];
2812             if ( t2.getNumberOfExternalNodes() != 664 ) {
2813                 return false;
2814             }
2815             if ( !t2.isRooted() ) {
2816                 return false;
2817             }
2818             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2819                 return false;
2820             }
2821             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2822                 return false;
2823             }
2824             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2825                 return false;
2826             }
2827             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2828                 return false;
2829             }
2830             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2831                 return false;
2832             }
2833             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2834                     .equals( "Aquifex" ) ) {
2835                 return false;
2836             }
2837             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2838             if ( parser.getErrorCount() > 0 ) {
2839                 System.out.println( parser.getErrorMessages().toString() );
2840                 return false;
2841             }
2842             if ( phylogenies_2.length != 1 ) {
2843                 return false;
2844             }
2845             final Phylogeny t3 = phylogenies_2[ 0 ];
2846             if ( t3.getNumberOfExternalNodes() != 184 ) {
2847                 return false;
2848             }
2849             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2850                 return false;
2851             }
2852             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2853                 return false;
2854             }
2855             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2856                 return false;
2857             }
2858             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2859             if ( parser.getErrorCount() > 0 ) {
2860                 System.out.println( parser.getErrorMessages().toString() );
2861                 return false;
2862             }
2863             if ( phylogenies_3.length != 1 ) {
2864                 return false;
2865             }
2866             final Phylogeny t4 = phylogenies_3[ 0 ];
2867             if ( t4.getNumberOfExternalNodes() != 1 ) {
2868                 return false;
2869             }
2870             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2871                 return false;
2872             }
2873             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2874                 return false;
2875             }
2876             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2877                 return false;
2878             }
2879             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2880             if ( parser.getErrorCount() > 0 ) {
2881                 System.out.println( parser.getErrorMessages().toString() );
2882                 return false;
2883             }
2884             if ( phylogenies_4.length != 1 ) {
2885                 return false;
2886             }
2887             final Phylogeny t5 = phylogenies_4[ 0 ];
2888             if ( t5.getNumberOfExternalNodes() != 13 ) {
2889                 return false;
2890             }
2891             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2892                 return false;
2893             }
2894             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2895                 return false;
2896             }
2897             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2898                 return false;
2899             }
2900         }
2901         catch ( final Exception e ) {
2902             e.printStackTrace( System.out );
2903             return false;
2904         }
2905         return true;
2906     }
2907
2908     private static boolean testBasicTreeMethods() {
2909         try {
2910             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2911             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2912             if ( t2.getNumberOfExternalNodes() != 4 ) {
2913                 return false;
2914             }
2915             if ( t2.getHeight() != 8.5 ) {
2916                 return false;
2917             }
2918             if ( !t2.isCompletelyBinary() ) {
2919                 return false;
2920             }
2921             if ( t2.isEmpty() ) {
2922                 return false;
2923             }
2924             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2925             if ( t3.getNumberOfExternalNodes() != 5 ) {
2926                 return false;
2927             }
2928             if ( t3.getHeight() != 11 ) {
2929                 return false;
2930             }
2931             if ( t3.isCompletelyBinary() ) {
2932                 return false;
2933             }
2934             final PhylogenyNode n = t3.getNode( "ABC" );
2935             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ];
2936             if ( t4.getNumberOfExternalNodes() != 9 ) {
2937                 return false;
2938             }
2939             if ( t4.getHeight() != 11 ) {
2940                 return false;
2941             }
2942             if ( t4.isCompletelyBinary() ) {
2943                 return false;
2944             }
2945             final StringBuffer sb5 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
2946             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2947             if ( t5.getNumberOfExternalNodes() != 8 ) {
2948                 return false;
2949             }
2950             if ( t5.getHeight() != 15 ) {
2951                 return false;
2952             }
2953             final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
2954             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2955             if ( t6.getHeight() != 15 ) {
2956                 return false;
2957             }
2958             final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" );
2959             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2960             if ( t7.getHeight() != 15 ) {
2961                 return false;
2962             }
2963             final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" );
2964             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2965             if ( t8.getNumberOfExternalNodes() != 10 ) {
2966                 return false;
2967             }
2968             if ( t8.getHeight() != 15 ) {
2969                 return false;
2970             }
2971             final char[] a9 = new char[] { 'a' };
2972             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2973             if ( t9.getHeight() != 0 ) {
2974                 return false;
2975             }
2976             final char[] a10 = new char[] { 'a', ':', '6' };
2977             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2978             if ( t10.getHeight() != 6 ) {
2979                 return false;
2980             }
2981         }
2982         catch ( final Exception e ) {
2983             e.printStackTrace( System.out );
2984             return false;
2985         }
2986         return true;
2987     }
2988
2989     private static boolean testConfidenceAssessor() {
2990         try {
2991             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2992             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2993             final Phylogeny[] ev0 = factory
2994                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2995                              new NHXParser() );
2996             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2997             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2998                 return false;
2999             }
3000             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3001                 return false;
3002             }
3003             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3004             final Phylogeny[] ev1 = factory
3005                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3006                              new NHXParser() );
3007             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3008             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3009                 return false;
3010             }
3011             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3012                 return false;
3013             }
3014             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3015             final Phylogeny[] ev_b = factory
3016                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3017                              new NHXParser() );
3018             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3019             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3020                 return false;
3021             }
3022             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3023                 return false;
3024             }
3025             //
3026             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3027             final Phylogeny[] ev1x = factory
3028                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3029                              new NHXParser() );
3030             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3031             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3032                 return false;
3033             }
3034             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3035                 return false;
3036             }
3037             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3038             final Phylogeny[] ev_bx = factory
3039                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3040                              new NHXParser() );
3041             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3042             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3043                 return false;
3044             }
3045             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3046                 return false;
3047             }
3048             //
3049             final Phylogeny[] t2 = factory
3050                     .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
3051                              new NHXParser() );
3052             final Phylogeny[] ev2 = factory
3053                     .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
3054                              new NHXParser() );
3055             for( final Phylogeny target : t2 ) {
3056                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3057             }
3058             //
3059             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3060                                                  new NHXParser() )[ 0 ];
3061             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3062             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3063             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3064                 return false;
3065             }
3066             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3067                 return false;
3068             }
3069             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3070                 return false;
3071             }
3072         }
3073         catch ( final Exception e ) {
3074             e.printStackTrace();
3075             return false;
3076         }
3077         return true;
3078     }
3079
3080     private static boolean testCopyOfNodeData() {
3081         try {
3082             final PhylogenyNode n1 = PhylogenyNode
3083                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:O=22:SO=33:SN=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
3084             final PhylogenyNode n2 = n1.copyNodeData();
3085             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3086                 return false;
3087             }
3088         }
3089         catch ( final Exception e ) {
3090             e.printStackTrace();
3091             return false;
3092         }
3093         return true;
3094     }
3095
3096     private static boolean testCreateBalancedPhylogeny() {
3097         try {
3098             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3099             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3100                 return false;
3101             }
3102             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3103                 return false;
3104             }
3105             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3106             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3107                 return false;
3108             }
3109             if ( p1.getNumberOfExternalNodes() != 100 ) {
3110                 return false;
3111             }
3112         }
3113         catch ( final Exception e ) {
3114             e.printStackTrace();
3115             return false;
3116         }
3117         return true;
3118     }
3119
3120     private static boolean testCreateUriForSeqWeb() {
3121         try {
3122             final PhylogenyNode n = new PhylogenyNode();
3123             n.setName( "tr|B3RJ64" );
3124             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3125                 return false;
3126             }
3127             n.setName( "B0LM41_HUMAN" );
3128             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3129                 return false;
3130             }
3131             n.setName( "NP_001025424" );
3132             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3133                 return false;
3134             }
3135             n.setName( "_NM_001030253-" );
3136             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3137                 return false;
3138             }
3139             n.setName( "XM_002122186" );
3140             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3141                 return false;
3142             }
3143             n.setName( "dgh_AAA34956_gdg" );
3144             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3145                 return false;
3146             }
3147             n.setName( "AAA34956" );
3148             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3149                 return false;
3150             }
3151             n.setName( "GI:394892" );
3152             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3153                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3154                 return false;
3155             }
3156             n.setName( "gi_394892" );
3157             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3158                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3159                 return false;
3160             }
3161             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3162             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3163                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3164                 return false;
3165             }
3166             n.setName( "P12345" );
3167             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3168                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3169                 return false;
3170             }
3171             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3172             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3173                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3174                 return false;
3175             }
3176         }
3177         catch ( final Exception e ) {
3178             e.printStackTrace( System.out );
3179             return false;
3180         }
3181         return true;
3182     }
3183
3184     private static boolean testDataObjects() {
3185         try {
3186             final Confidence s0 = new Confidence();
3187             final Confidence s1 = new Confidence();
3188             if ( !s0.isEqual( s1 ) ) {
3189                 return false;
3190             }
3191             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3192             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3193             if ( s2.isEqual( s1 ) ) {
3194                 return false;
3195             }
3196             if ( !s2.isEqual( s3 ) ) {
3197                 return false;
3198             }
3199             final Confidence s4 = ( Confidence ) s3.copy();
3200             if ( !s4.isEqual( s3 ) ) {
3201                 return false;
3202             }
3203             s3.asSimpleText();
3204             s3.asText();
3205             // Taxonomy
3206             // ----------
3207             final Taxonomy t1 = new Taxonomy();
3208             final Taxonomy t2 = new Taxonomy();
3209             final Taxonomy t3 = new Taxonomy();
3210             final Taxonomy t4 = new Taxonomy();
3211             final Taxonomy t5 = new Taxonomy();
3212             t1.setIdentifier( new Identifier( "ecoli" ) );
3213             t1.setTaxonomyCode( "ECOLI" );
3214             t1.setScientificName( "E. coli" );
3215             t1.setCommonName( "coli" );
3216             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3217             if ( !t1.isEqual( t0 ) ) {
3218                 return false;
3219             }
3220             t2.setIdentifier( new Identifier( "ecoli" ) );
3221             t2.setTaxonomyCode( "OTHER" );
3222             t2.setScientificName( "what" );
3223             t2.setCommonName( "something" );
3224             if ( !t1.isEqual( t2 ) ) {
3225                 return false;
3226             }
3227             t2.setIdentifier( new Identifier( "nemve" ) );
3228             if ( t1.isEqual( t2 ) ) {
3229                 return false;
3230             }
3231             t1.setIdentifier( null );
3232             t3.setTaxonomyCode( "ECOLI" );
3233             t3.setScientificName( "what" );
3234             t3.setCommonName( "something" );
3235             if ( !t1.isEqual( t3 ) ) {
3236                 return false;
3237             }
3238             t1.setIdentifier( null );
3239             t1.setTaxonomyCode( "" );
3240             t4.setScientificName( "E. ColI" );
3241             t4.setCommonName( "something" );
3242             if ( !t1.isEqual( t4 ) ) {
3243                 return false;
3244             }
3245             t4.setScientificName( "B. subtilis" );
3246             t4.setCommonName( "something" );
3247             if ( t1.isEqual( t4 ) ) {
3248                 return false;
3249             }
3250             t1.setIdentifier( null );
3251             t1.setTaxonomyCode( "" );
3252             t1.setScientificName( "" );
3253             t5.setCommonName( "COLI" );
3254             if ( !t1.isEqual( t5 ) ) {
3255                 return false;
3256             }
3257             t5.setCommonName( "vibrio" );
3258             if ( t1.isEqual( t5 ) ) {
3259                 return false;
3260             }
3261             // Identifier
3262             // ----------
3263             final Identifier id0 = new Identifier( "123", "pfam" );
3264             final Identifier id1 = ( Identifier ) id0.copy();
3265             if ( !id1.isEqual( id1 ) ) {
3266                 return false;
3267             }
3268             if ( !id1.isEqual( id0 ) ) {
3269                 return false;
3270             }
3271             if ( !id0.isEqual( id1 ) ) {
3272                 return false;
3273             }
3274             id1.asSimpleText();
3275             id1.asText();
3276             // ProteinDomain
3277             // ---------------
3278             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3279             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3280             if ( !pd1.isEqual( pd1 ) ) {
3281                 return false;
3282             }
3283             if ( !pd1.isEqual( pd0 ) ) {
3284                 return false;
3285             }
3286             pd1.asSimpleText();
3287             pd1.asText();
3288             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3289             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3290             if ( !pd3.isEqual( pd3 ) ) {
3291                 return false;
3292             }
3293             if ( !pd2.isEqual( pd3 ) ) {
3294                 return false;
3295             }
3296             if ( !pd0.isEqual( pd3 ) ) {
3297                 return false;
3298             }
3299             pd3.asSimpleText();
3300             pd3.asText();
3301             // DomainArchitecture
3302             // ------------------
3303             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3304             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3305             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3306             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3307             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3308             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3309             domains0.add( d2 );
3310             domains0.add( d0 );
3311             domains0.add( d3 );
3312             domains0.add( d1 );
3313             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3314             if ( ds0.getNumberOfDomains() != 4 ) {
3315                 return false;
3316             }
3317             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3318             if ( !ds0.isEqual( ds0 ) ) {
3319                 return false;
3320             }
3321             if ( !ds0.isEqual( ds1 ) ) {
3322                 return false;
3323             }
3324             if ( ds1.getNumberOfDomains() != 4 ) {
3325                 return false;
3326             }
3327             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3328             domains1.add( d1 );
3329             domains1.add( d2 );
3330             domains1.add( d4 );
3331             domains1.add( d0 );
3332             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3333             if ( ds0.isEqual( ds2 ) ) {
3334                 return false;
3335             }
3336             ds1.asSimpleText();
3337             ds1.asText();
3338             ds1.toNHX();
3339             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3340             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3341                 System.out.println( ds3.toNHX() );
3342                 return false;
3343             }
3344             if ( ds3.getNumberOfDomains() != 3 ) {
3345                 return false;
3346             }
3347             // Event
3348             // -----
3349             final Event e1 = new Event( Event.EventType.fusion );
3350             if ( e1.isDuplication() ) {
3351                 return false;
3352             }
3353             if ( !e1.isFusion() ) {
3354                 return false;
3355             }
3356             if ( !e1.asText().toString().equals( "fusion" ) ) {
3357                 return false;
3358             }
3359             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3360                 return false;
3361             }
3362             final Event e11 = new Event( Event.EventType.fusion );
3363             if ( !e11.isEqual( e1 ) ) {
3364                 return false;
3365             }
3366             if ( !e11.toNHX().toString().equals( "" ) ) {
3367                 return false;
3368             }
3369             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3370             if ( e2.isDuplication() ) {
3371                 return false;
3372             }
3373             if ( !e2.isSpeciationOrDuplication() ) {
3374                 return false;
3375             }
3376             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3377                 return false;
3378             }
3379             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3380                 return false;
3381             }
3382             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3383                 return false;
3384             }
3385             if ( e11.isEqual( e2 ) ) {
3386                 return false;
3387             }
3388             final Event e2c = ( Event ) e2.copy();
3389             if ( !e2c.isEqual( e2 ) ) {
3390                 return false;
3391             }
3392             Event e3 = new Event( 1, 2, 3 );
3393             if ( e3.isDuplication() ) {
3394                 return false;
3395             }
3396             if ( e3.isSpeciation() ) {
3397                 return false;
3398             }
3399             if ( e3.isGeneLoss() ) {
3400                 return false;
3401             }
3402             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3403                 return false;
3404             }
3405             final Event e3c = ( Event ) e3.copy();
3406             final Event e3cc = ( Event ) e3c.copy();
3407             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3408                 return false;
3409             }
3410             e3 = null;
3411             if ( !e3c.isEqual( e3cc ) ) {
3412                 return false;
3413             }
3414             Event e4 = new Event( 1, 2, 3 );
3415             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3416                 return false;
3417             }
3418             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3419                 return false;
3420             }
3421             final Event e4c = ( Event ) e4.copy();
3422             e4 = null;
3423             final Event e4cc = ( Event ) e4c.copy();
3424             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3425                 return false;
3426             }
3427             if ( !e4c.isEqual( e4cc ) ) {
3428                 return false;
3429             }
3430             final Event e5 = new Event();
3431             if ( !e5.isUnassigned() ) {
3432                 return false;
3433             }
3434             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3435                 return false;
3436             }
3437             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3438                 return false;
3439             }
3440             final Event e6 = new Event( 1, 0, 0 );
3441             if ( !e6.asText().toString().equals( "duplication" ) ) {
3442                 return false;
3443             }
3444             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3445                 return false;
3446             }
3447             final Event e7 = new Event( 0, 1, 0 );
3448             if ( !e7.asText().toString().equals( "speciation" ) ) {
3449                 return false;
3450             }
3451             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3452                 return false;
3453             }
3454             final Event e8 = new Event( 0, 0, 1 );
3455             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3456                 return false;
3457             }
3458             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3459                 return false;
3460             }
3461         }
3462         catch ( final Exception e ) {
3463             e.printStackTrace( System.out );
3464             return false;
3465         }
3466         return true;
3467     }
3468
3469     private static boolean testDeletionOfExternalNodes() {
3470         try {
3471             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3472             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3473             final PhylogenyWriter w = new PhylogenyWriter();
3474             if ( t0.isEmpty() ) {
3475                 return false;
3476             }
3477             if ( t0.getNumberOfExternalNodes() != 1 ) {
3478                 return false;
3479             }
3480             t0.deleteSubtree( t0.getNode( "A" ), false );
3481             if ( t0.getNumberOfExternalNodes() != 0 ) {
3482                 return false;
3483             }
3484             if ( !t0.isEmpty() ) {
3485                 return false;
3486             }
3487             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3488             if ( t1.getNumberOfExternalNodes() != 2 ) {
3489                 return false;
3490             }
3491             t1.deleteSubtree( t1.getNode( "A" ), false );
3492             if ( t1.getNumberOfExternalNodes() != 1 ) {
3493                 return false;
3494             }
3495             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3496                 return false;
3497             }
3498             t1.deleteSubtree( t1.getNode( "B" ), false );
3499             if ( t1.getNumberOfExternalNodes() != 1 ) {
3500                 return false;
3501             }
3502             t1.deleteSubtree( t1.getNode( "r" ), false );
3503             if ( !t1.isEmpty() ) {
3504                 return false;
3505             }
3506             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3507             if ( t2.getNumberOfExternalNodes() != 3 ) {
3508                 return false;
3509             }
3510             t2.deleteSubtree( t2.getNode( "B" ), false );
3511             if ( t2.getNumberOfExternalNodes() != 2 ) {
3512                 return false;
3513             }
3514             t2.toNewHampshireX();
3515             PhylogenyNode n = t2.getNode( "A" );
3516             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3517                 return false;
3518             }
3519             t2.deleteSubtree( t2.getNode( "A" ), false );
3520             if ( t2.getNumberOfExternalNodes() != 2 ) {
3521                 return false;
3522             }
3523             t2.deleteSubtree( t2.getNode( "C" ), true );
3524             if ( t2.getNumberOfExternalNodes() != 1 ) {
3525                 return false;
3526             }
3527             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3528             if ( t3.getNumberOfExternalNodes() != 4 ) {
3529                 return false;
3530             }
3531             t3.deleteSubtree( t3.getNode( "B" ), true );
3532             if ( t3.getNumberOfExternalNodes() != 3 ) {
3533                 return false;
3534             }
3535             n = t3.getNode( "A" );
3536             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3537                 return false;
3538             }
3539             n = n.getNextExternalNode();
3540             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3541                 return false;
3542             }
3543             t3.deleteSubtree( t3.getNode( "A" ), true );
3544             if ( t3.getNumberOfExternalNodes() != 2 ) {
3545                 return false;
3546             }
3547             n = t3.getNode( "C" );
3548             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3549                 return false;
3550             }
3551             t3.deleteSubtree( t3.getNode( "C" ), true );
3552             if ( t3.getNumberOfExternalNodes() != 1 ) {
3553                 return false;
3554             }
3555             t3.deleteSubtree( t3.getNode( "D" ), true );
3556             if ( t3.getNumberOfExternalNodes() != 0 ) {
3557                 return false;
3558             }
3559             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3560             if ( t4.getNumberOfExternalNodes() != 6 ) {
3561                 return false;
3562             }
3563             t4.deleteSubtree( t4.getNode( "B2" ), true );
3564             if ( t4.getNumberOfExternalNodes() != 5 ) {
3565                 return false;
3566             }
3567             String s = w.toNewHampshire( t4, true ).toString();
3568             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3569                 return false;
3570             }
3571             t4.deleteSubtree( t4.getNode( "B11" ), true );
3572             if ( t4.getNumberOfExternalNodes() != 4 ) {
3573                 return false;
3574             }
3575             t4.deleteSubtree( t4.getNode( "C" ), true );
3576             if ( t4.getNumberOfExternalNodes() != 3 ) {
3577                 return false;
3578             }
3579             n = t4.getNode( "A" );
3580             n = n.getNextExternalNode();
3581             if ( !n.getName().equals( "B12" ) ) {
3582                 return false;
3583             }
3584             n = n.getNextExternalNode();
3585             if ( !n.getName().equals( "D" ) ) {
3586                 return false;
3587             }
3588             s = w.toNewHampshire( t4, true ).toString();
3589             if ( !s.equals( "((A,B12),D);" ) ) {
3590                 return false;
3591             }
3592             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3593             t5.deleteSubtree( t5.getNode( "A" ), true );
3594             if ( t5.getNumberOfExternalNodes() != 5 ) {
3595                 return false;
3596             }
3597             s = w.toNewHampshire( t5, true ).toString();
3598             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3599                 return false;
3600             }
3601             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3602             t6.deleteSubtree( t6.getNode( "B11" ), true );
3603             if ( t6.getNumberOfExternalNodes() != 5 ) {
3604                 return false;
3605             }
3606             s = w.toNewHampshire( t6, false ).toString();
3607             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3608                 return false;
3609             }
3610             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3611             t7.deleteSubtree( t7.getNode( "B12" ), true );
3612             if ( t7.getNumberOfExternalNodes() != 5 ) {
3613                 return false;
3614             }
3615             s = w.toNewHampshire( t7, true ).toString();
3616             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3617                 return false;
3618             }
3619             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3620             t8.deleteSubtree( t8.getNode( "B2" ), true );
3621             if ( t8.getNumberOfExternalNodes() != 5 ) {
3622                 return false;
3623             }
3624             s = w.toNewHampshire( t8, false ).toString();
3625             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3626                 return false;
3627             }
3628             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3629             t9.deleteSubtree( t9.getNode( "C" ), true );
3630             if ( t9.getNumberOfExternalNodes() != 5 ) {
3631                 return false;
3632             }
3633             s = w.toNewHampshire( t9, true ).toString();
3634             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3635                 return false;
3636             }
3637             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3638             t10.deleteSubtree( t10.getNode( "D" ), true );
3639             if ( t10.getNumberOfExternalNodes() != 5 ) {
3640                 return false;
3641             }
3642             s = w.toNewHampshire( t10, true ).toString();
3643             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3644                 return false;
3645             }
3646             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3647             t11.deleteSubtree( t11.getNode( "A" ), true );
3648             if ( t11.getNumberOfExternalNodes() != 2 ) {
3649                 return false;
3650             }
3651             s = w.toNewHampshire( t11, true ).toString();
3652             if ( !s.equals( "(B,C);" ) ) {
3653                 return false;
3654             }
3655             t11.deleteSubtree( t11.getNode( "C" ), true );
3656             if ( t11.getNumberOfExternalNodes() != 1 ) {
3657                 return false;
3658             }
3659             s = w.toNewHampshire( t11, false ).toString();
3660             if ( !s.equals( "B;" ) ) {
3661                 return false;
3662             }
3663             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3664             t12.deleteSubtree( t12.getNode( "B2" ), true );
3665             if ( t12.getNumberOfExternalNodes() != 8 ) {
3666                 return false;
3667             }
3668             s = w.toNewHampshire( t12, true ).toString();
3669             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3670                 return false;
3671             }
3672             t12.deleteSubtree( t12.getNode( "B3" ), true );
3673             if ( t12.getNumberOfExternalNodes() != 7 ) {
3674                 return false;
3675             }
3676             s = w.toNewHampshire( t12, true ).toString();
3677             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3678                 return false;
3679             }
3680             t12.deleteSubtree( t12.getNode( "C3" ), true );
3681             if ( t12.getNumberOfExternalNodes() != 6 ) {
3682                 return false;
3683             }
3684             s = w.toNewHampshire( t12, true ).toString();
3685             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3686                 return false;
3687             }
3688             t12.deleteSubtree( t12.getNode( "A1" ), true );
3689             if ( t12.getNumberOfExternalNodes() != 5 ) {
3690                 return false;
3691             }
3692             s = w.toNewHampshire( t12, true ).toString();
3693             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3694                 return false;
3695             }
3696             t12.deleteSubtree( t12.getNode( "B1" ), true );
3697             if ( t12.getNumberOfExternalNodes() != 4 ) {
3698                 return false;
3699             }
3700             s = w.toNewHampshire( t12, true ).toString();
3701             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3702                 return false;
3703             }
3704             t12.deleteSubtree( t12.getNode( "A3" ), true );
3705             if ( t12.getNumberOfExternalNodes() != 3 ) {
3706                 return false;
3707             }
3708             s = w.toNewHampshire( t12, true ).toString();
3709             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3710                 return false;
3711             }
3712             t12.deleteSubtree( t12.getNode( "A2" ), true );
3713             if ( t12.getNumberOfExternalNodes() != 2 ) {
3714                 return false;
3715             }
3716             s = w.toNewHampshire( t12, true ).toString();
3717             if ( !s.equals( "(C1,C2);" ) ) {
3718                 return false;
3719             }
3720             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3721             t13.deleteSubtree( t13.getNode( "D" ), true );
3722             if ( t13.getNumberOfExternalNodes() != 4 ) {
3723                 return false;
3724             }
3725             s = w.toNewHampshire( t13, true ).toString();
3726             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3727                 return false;
3728             }
3729             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3730             t14.deleteSubtree( t14.getNode( "E" ), true );
3731             if ( t14.getNumberOfExternalNodes() != 5 ) {
3732                 return false;
3733             }
3734             s = w.toNewHampshire( t14, true ).toString();
3735             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3736                 return false;
3737             }
3738             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3739             t15.deleteSubtree( t15.getNode( "B2" ), true );
3740             if ( t15.getNumberOfExternalNodes() != 11 ) {
3741                 return false;
3742             }
3743             t15.deleteSubtree( t15.getNode( "B1" ), true );
3744             if ( t15.getNumberOfExternalNodes() != 10 ) {
3745                 return false;
3746             }
3747             t15.deleteSubtree( t15.getNode( "B3" ), true );
3748             if ( t15.getNumberOfExternalNodes() != 9 ) {
3749                 return false;
3750             }
3751             t15.deleteSubtree( t15.getNode( "B4" ), true );
3752             if ( t15.getNumberOfExternalNodes() != 8 ) {
3753                 return false;
3754             }
3755             t15.deleteSubtree( t15.getNode( "A1" ), true );
3756             if ( t15.getNumberOfExternalNodes() != 7 ) {
3757                 return false;
3758             }
3759             t15.deleteSubtree( t15.getNode( "C4" ), true );
3760             if ( t15.getNumberOfExternalNodes() != 6 ) {
3761                 return false;
3762             }
3763         }
3764         catch ( final Exception e ) {
3765             e.printStackTrace( System.out );
3766             return false;
3767         }
3768         return true;
3769     }
3770
3771     private static boolean testDescriptiveStatistics() {
3772         try {
3773             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3774             dss1.addValue( 82 );
3775             dss1.addValue( 78 );
3776             dss1.addValue( 70 );
3777             dss1.addValue( 58 );
3778             dss1.addValue( 42 );
3779             if ( dss1.getN() != 5 ) {
3780                 return false;
3781             }
3782             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3783                 return false;
3784             }
3785             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3786                 return false;
3787             }
3788             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3789                 return false;
3790             }
3791             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3792                 return false;
3793             }
3794             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3795                 return false;
3796             }
3797             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3798                 return false;
3799             }
3800             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3801                 return false;
3802             }
3803             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3804                 return false;
3805             }
3806             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3807                 return false;
3808             }
3809             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3810                 return false;
3811             }
3812             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3813                 return false;
3814             }
3815             dss1.addValue( 123 );
3816             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3817                 return false;
3818             }
3819             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3820                 return false;
3821             }
3822             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3823                 return false;
3824             }
3825             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3826             dss2.addValue( -1.85 );
3827             dss2.addValue( 57.5 );
3828             dss2.addValue( 92.78 );
3829             dss2.addValue( 57.78 );
3830             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3831                 return false;
3832             }
3833             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3834                 return false;
3835             }
3836             final double[] a = dss2.getDataAsDoubleArray();
3837             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3838                 return false;
3839             }
3840             dss2.addValue( -100 );
3841             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3842                 return false;
3843             }
3844             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3845                 return false;
3846             }
3847             final double[] ds = new double[ 14 ];
3848             ds[ 0 ] = 34;
3849             ds[ 1 ] = 23;
3850             ds[ 2 ] = 1;
3851             ds[ 3 ] = 32;
3852             ds[ 4 ] = 11;
3853             ds[ 5 ] = 2;
3854             ds[ 6 ] = 12;
3855             ds[ 7 ] = 33;
3856             ds[ 8 ] = 13;
3857             ds[ 9 ] = 22;
3858             ds[ 10 ] = 21;
3859             ds[ 11 ] = 35;
3860             ds[ 12 ] = 24;
3861             ds[ 13 ] = 31;
3862             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3863             if ( bins.length != 4 ) {
3864                 return false;
3865             }
3866             if ( bins[ 0 ] != 2 ) {
3867                 return false;
3868             }
3869             if ( bins[ 1 ] != 3 ) {
3870                 return false;
3871             }
3872             if ( bins[ 2 ] != 4 ) {
3873                 return false;
3874             }
3875             if ( bins[ 3 ] != 5 ) {
3876                 return false;
3877             }
3878             final double[] ds1 = new double[ 9 ];
3879             ds1[ 0 ] = 10.0;
3880             ds1[ 1 ] = 19.0;
3881             ds1[ 2 ] = 9.999;
3882             ds1[ 3 ] = 0.0;
3883             ds1[ 4 ] = 39.9;
3884             ds1[ 5 ] = 39.999;
3885             ds1[ 6 ] = 30.0;
3886             ds1[ 7 ] = 19.999;
3887             ds1[ 8 ] = 30.1;
3888             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3889             if ( bins1.length != 4 ) {
3890                 return false;
3891             }
3892             if ( bins1[ 0 ] != 2 ) {
3893                 return false;
3894             }
3895             if ( bins1[ 1 ] != 3 ) {
3896                 return false;
3897             }
3898             if ( bins1[ 2 ] != 0 ) {
3899                 return false;
3900             }
3901             if ( bins1[ 3 ] != 4 ) {
3902                 return false;
3903             }
3904             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3905             if ( bins1_1.length != 3 ) {
3906                 return false;
3907             }
3908             if ( bins1_1[ 0 ] != 3 ) {
3909                 return false;
3910             }
3911             if ( bins1_1[ 1 ] != 2 ) {
3912                 return false;
3913             }
3914             if ( bins1_1[ 2 ] != 4 ) {
3915                 return false;
3916             }
3917             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3918             if ( bins1_2.length != 3 ) {
3919                 return false;
3920             }
3921             if ( bins1_2[ 0 ] != 2 ) {
3922                 return false;
3923             }
3924             if ( bins1_2[ 1 ] != 2 ) {
3925                 return false;
3926             }
3927             if ( bins1_2[ 2 ] != 2 ) {
3928                 return false;
3929             }
3930             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3931             dss3.addValue( 1 );
3932             dss3.addValue( 1 );
3933             dss3.addValue( 1 );
3934             dss3.addValue( 2 );
3935             dss3.addValue( 3 );
3936             dss3.addValue( 4 );
3937             dss3.addValue( 5 );
3938             dss3.addValue( 5 );
3939             dss3.addValue( 5 );
3940             dss3.addValue( 6 );
3941             dss3.addValue( 7 );
3942             dss3.addValue( 8 );
3943             dss3.addValue( 9 );
3944             dss3.addValue( 10 );
3945             dss3.addValue( 10 );
3946             dss3.addValue( 10 );
3947             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3948             histo.toStringBuffer( 10, '=', 40, 5 );
3949             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3950         }
3951         catch ( final Exception e ) {
3952             e.printStackTrace( System.out );
3953             return false;
3954         }
3955         return true;
3956     }
3957
3958     private static boolean testDir( final String file ) {
3959         try {
3960             final File f = new File( file );
3961             if ( !f.exists() ) {
3962                 return false;
3963             }
3964             if ( !f.isDirectory() ) {
3965                 return false;
3966             }
3967             if ( !f.canRead() ) {
3968                 return false;
3969             }
3970         }
3971         catch ( final Exception e ) {
3972             return false;
3973         }
3974         return true;
3975     }
3976
3977     private static boolean testEbiEntryRetrieval() {
3978         try {
3979             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3980             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3981                 System.out.println( entry.getAccession() );
3982                 return false;
3983             }
3984             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3985                 System.out.println( entry.getTaxonomyScientificName() );
3986                 return false;
3987             }
3988             if ( !entry.getSequenceName()
3989                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3990                 System.out.println( entry.getSequenceName() );
3991                 return false;
3992             }
3993             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3994             //     System.out.println( entry.getSequenceSymbol() );
3995             //     return false;
3996             // }
3997             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3998                 System.out.println( entry.getGeneName() );
3999                 return false;
4000             }
4001             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4002                 System.out.println( entry.getTaxonomyIdentifier() );
4003                 return false;
4004             }
4005             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4006                 System.out.println( entry.getAnnotations().first().getRefValue() );
4007                 return false;
4008             }
4009             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4010                 System.out.println( entry.getAnnotations().first().getRefSource() );
4011                 return false;
4012             }
4013             if ( entry.getCrossReferences().size() != 5 ) {
4014                 return false;
4015             }
4016             //
4017             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4018             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4019                 return false;
4020             }
4021             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4022                 System.out.println( entry1.getTaxonomyScientificName() );
4023                 return false;
4024             }
4025             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4026                 System.out.println( entry1.getSequenceName() );
4027                 return false;
4028             }
4029             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4030                 System.out.println( entry1.getTaxonomyIdentifier() );
4031                 return false;
4032             }
4033             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4034                 System.out.println( entry1.getGeneName() );
4035                 return false;
4036             }
4037             if ( entry1.getCrossReferences().size() != 6 ) {
4038                 return false;
4039             }
4040             //
4041             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4042             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4043                 return false;
4044             }
4045             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4046                 System.out.println( entry2.getTaxonomyScientificName() );
4047                 return false;
4048             }
4049             if ( !entry2.getSequenceName()
4050                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4051                 System.out.println( entry2.getSequenceName() );
4052                 return false;
4053             }
4054             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4055                 System.out.println( entry2.getTaxonomyIdentifier() );
4056                 return false;
4057             }
4058             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4059                 System.out.println( entry2.getGeneName() );
4060                 return false;
4061             }
4062             if ( entry2.getCrossReferences().size() != 3 ) {
4063                 return false;
4064             }
4065             //
4066             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4067             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4068                 return false;
4069             }
4070             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4071                 System.out.println( entry3.getTaxonomyScientificName() );
4072                 return false;
4073             }
4074             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4075                 System.out.println( entry3.getSequenceName() );
4076                 return false;
4077             }
4078             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4079                 System.out.println( entry3.getTaxonomyIdentifier() );
4080                 return false;
4081             }
4082             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4083                 System.out.println( entry3.getSequenceSymbol() );
4084                 return false;
4085             }
4086             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4087                 return false;
4088             }
4089             if ( entry3.getCrossReferences().size() != 8 ) {
4090                 return false;
4091             }
4092             //
4093             //
4094             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4095             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4096                 return false;
4097             }
4098             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4099                 System.out.println( entry4.getTaxonomyScientificName() );
4100                 return false;
4101             }
4102             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4103                 System.out.println( entry4.getSequenceName() );
4104                 return false;
4105             }
4106             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4107                 System.out.println( entry4.getTaxonomyIdentifier() );
4108                 return false;
4109             }
4110             if ( !entry4.getGeneName().equals( "ras" ) ) {
4111                 System.out.println( entry4.getGeneName() );
4112                 return false;
4113             }
4114             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4115             //     System.out.println( entry4.getChromosome() );
4116             //     return false;
4117             // }
4118             // if ( !entry4.getMap().equals( "ras" ) ) {
4119             //     System.out.println( entry4.getMap() );
4120             //     return false;
4121             // }
4122             //TODO FIXME gi...
4123             //
4124             //TODO fails:
4125             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4126             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4127             //                return false;
4128             //            }
4129             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4130             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4131                 return false;
4132             }
4133             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4134                 System.out.println( entry5.getTaxonomyScientificName() );
4135                 return false;
4136             }
4137             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4138                 System.out.println( entry5.getSequenceName() );
4139                 return false;
4140             }
4141             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4142                 System.out.println( entry5.getTaxonomyIdentifier() );
4143                 return false;
4144             }
4145         }
4146         catch ( final IOException e ) {
4147             System.out.println();
4148             System.out.println( "the following might be due to absence internet connection:" );
4149             e.printStackTrace( System.out );
4150             return true;
4151         }
4152         catch ( final Exception e ) {
4153             e.printStackTrace();
4154             return false;
4155         }
4156         return true;
4157     }
4158
4159     private static boolean testExternalNodeRelatedMethods() {
4160         try {
4161             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4162             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4163             PhylogenyNode n = t1.getNode( "A" );
4164             n = n.getNextExternalNode();
4165             if ( !n.getName().equals( "B" ) ) {
4166                 return false;
4167             }
4168             n = n.getNextExternalNode();
4169             if ( !n.getName().equals( "C" ) ) {
4170                 return false;
4171             }
4172             n = n.getNextExternalNode();
4173             if ( !n.getName().equals( "D" ) ) {
4174                 return false;
4175             }
4176             n = t1.getNode( "B" );
4177             while ( !n.isLastExternalNode() ) {
4178                 n = n.getNextExternalNode();
4179             }
4180             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4181             n = t2.getNode( "A" );
4182             n = n.getNextExternalNode();
4183             if ( !n.getName().equals( "B" ) ) {
4184                 return false;
4185             }
4186             n = n.getNextExternalNode();
4187             if ( !n.getName().equals( "C" ) ) {
4188                 return false;
4189             }
4190             n = n.getNextExternalNode();
4191             if ( !n.getName().equals( "D" ) ) {
4192                 return false;
4193             }
4194             n = t2.getNode( "B" );
4195             while ( !n.isLastExternalNode() ) {
4196                 n = n.getNextExternalNode();
4197             }
4198             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4199             n = t3.getNode( "A" );
4200             n = n.getNextExternalNode();
4201             if ( !n.getName().equals( "B" ) ) {
4202                 return false;
4203             }
4204             n = n.getNextExternalNode();
4205             if ( !n.getName().equals( "C" ) ) {
4206                 return false;
4207             }
4208             n = n.getNextExternalNode();
4209             if ( !n.getName().equals( "D" ) ) {
4210                 return false;
4211             }
4212             n = n.getNextExternalNode();
4213             if ( !n.getName().equals( "E" ) ) {
4214                 return false;
4215             }
4216             n = n.getNextExternalNode();
4217             if ( !n.getName().equals( "F" ) ) {
4218                 return false;
4219             }
4220             n = n.getNextExternalNode();
4221             if ( !n.getName().equals( "G" ) ) {
4222                 return false;
4223             }
4224             n = n.getNextExternalNode();
4225             if ( !n.getName().equals( "H" ) ) {
4226                 return false;
4227             }
4228             n = t3.getNode( "B" );
4229             while ( !n.isLastExternalNode() ) {
4230                 n = n.getNextExternalNode();
4231             }
4232             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4233             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4234                 final PhylogenyNode node = iter.next();
4235             }
4236             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4237             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4238                 final PhylogenyNode node = iter.next();
4239             }
4240             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4241             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4242             if ( !iter.next().getName().equals( "A" ) ) {
4243                 return false;
4244             }
4245             if ( !iter.next().getName().equals( "B" ) ) {
4246                 return false;
4247             }
4248             if ( !iter.next().getName().equals( "C" ) ) {
4249                 return false;
4250             }
4251             if ( !iter.next().getName().equals( "D" ) ) {
4252                 return false;
4253             }
4254             if ( !iter.next().getName().equals( "E" ) ) {
4255                 return false;
4256             }
4257             if ( !iter.next().getName().equals( "F" ) ) {
4258                 return false;
4259             }
4260             if ( iter.hasNext() ) {
4261                 return false;
4262             }
4263         }
4264         catch ( final Exception e ) {
4265             e.printStackTrace( System.out );
4266             return false;
4267         }
4268         return true;
4269     }
4270
4271     private static boolean testExtractSNFromNodeName() {
4272         try {
4273             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4274                 return false;
4275             }
4276             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4277                 return false;
4278             }
4279             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4280                 return false;
4281             }
4282             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4283                     .equals( "Mus musculus musculus" ) ) {
4284                 return false;
4285             }
4286             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4287                     .equals( "Mus musculus musculus" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4291                     .equals( "Mus musculus musculus" ) ) {
4292                 return false;
4293             }
4294             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4295                     .equals( "Mus musculus musculus" ) ) {
4296                 return false;
4297             }
4298             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4299                 return false;
4300             }
4301             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4302                     .equals( "Mus musculus musculus" ) ) {
4303                 return false;
4304             }
4305             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4306                     .equals( "Mus musculus musculus" ) ) {
4307                 return false;
4308             }
4309             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4310                 return false;
4311             }
4312             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4313                 return false;
4314             }
4315             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4316                 return false;
4317             }
4318             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4319                 return false;
4320             }
4321             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4322                     .equals( "Mus musculus musculus" ) ) {
4323                 return false;
4324             }
4325             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4326                 return false;
4327             }
4328             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4332                 return false;
4333             }
4334             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4335                 return false;
4336             }
4337             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4338                 return false;
4339             }
4340             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4341                 return false;
4342             }
4343             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4344                 return false;
4345             }
4346             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4347                 return false;
4348             }
4349             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4350                     .equals( "Mus musculus" ) ) {
4351                 return false;
4352             }
4353             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4354                     .equals( "Mus musculus" ) ) {
4355                 return false;
4356             }
4357             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4361                     .equals( "Mus musculus musculus" ) ) {
4362                 return false;
4363             }
4364             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4365                     .equals( "Mus musculus musculus" ) ) {
4366                 return false;
4367             }
4368             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4369                     .equals( "Mus musculus musculus" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4376                     .equals( "Pilostyles mexicana" ) ) {
4377                 return false;
4378             }
4379             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4380                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4381                 return false;
4382             }
4383             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4384                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4385                 return false;
4386             }
4387             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4388                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4392                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4396                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4397                 return false;
4398             }
4399             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4400                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4401                 return false;
4402             }
4403             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4404                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4405                 return false;
4406             }
4407             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4408                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4409                 return false;
4410             }
4411             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4412                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4413                 return false;
4414             }
4415             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4416                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4417                 return false;
4418             }
4419             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4420                     .equals( "Escherichia coli (strain K12)" ) ) {
4421                 return false;
4422             }
4423             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4424                     .equals( "Escherichia coli (strain K12)" ) ) {
4425                 return false;
4426             }
4427             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4428                     .equals( "Escherichia coli (str. K12)" ) ) {
4429                 return false;
4430             }
4431             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4432                     .equals( "Escherichia coli (str. K12)" ) ) {
4433                 return false;
4434             }
4435             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4436                     .equals( "Escherichia coli (str. K12)" ) ) {
4437                 return false;
4438             }
4439             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4440                     .equals( "Escherichia coli (var. K12)" ) ) {
4441                 return false;
4442             }
4443             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4444                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4445                 return false;
4446             }
4447             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4448                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4449                 return false;
4450             }
4451             if ( !ParserUtils
4452                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4453                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4454                 return false;
4455             }
4456             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4457                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4458                 return false;
4459             }
4460             if ( !ParserUtils
4461                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4462                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4463                 return false;
4464             }
4465             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4466                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4467                 return false;
4468             }
4469             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4470                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4471                 return false;
4472             }
4473             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4477                 return false;
4478             }
4479             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4480                 return false;
4481             }
4482             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4483                     .equals( "Macrocera sp." ) ) {
4484                 return false;
4485             }
4486             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4490                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4494                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4495                 return false;
4496             }
4497             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4498                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4499                 return false;
4500             }
4501             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4502                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4503                 return false;
4504             }
4505         }
4506         catch ( final Exception e ) {
4507             e.printStackTrace( System.out );
4508             return false;
4509         }
4510         return true;
4511     }
4512
4513     private static boolean testExtractTaxonomyCodeFromNodeName() {
4514         try {
4515             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4516                 return false;
4517             }
4518             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4519                     .equals( "SOYBN" ) ) {
4520                 return false;
4521             }
4522             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4523                     .equals( "ARATH" ) ) {
4524                 return false;
4525             }
4526             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4527                     .equals( "ARATH" ) ) {
4528                 return false;
4529             }
4530             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4531                 return false;
4532             }
4533             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4534                 return false;
4535             }
4536             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4537                 return false;
4538             }
4539             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4540                     .equals( "SOYBN" ) ) {
4541                 return false;
4542             }
4543             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4544                     .equals( "SOYBN" ) ) {
4545                 return false;
4546             }
4547             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4548                     .equals( "SOYBN" ) ) {
4549                 return false;
4550             }
4551             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4552                     .equals( "SOYBN" ) ) {
4553                 return false;
4554             }
4555             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4556                     .equals( "SOYBN" ) ) {
4557                 return false;
4558             }
4559             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4560                     .equals( "SOYBN" ) ) {
4561                 return false;
4562             }
4563             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4564                     .equals( "SOYBN" ) ) {
4565                 return false;
4566             }
4567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4568                     .equals( "SOYBN" ) ) {
4569                 return false;
4570             }
4571             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4572                 return false;
4573             }
4574             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4575                     .equals( "SOYBN" ) ) {
4576                 return false;
4577             }
4578             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4579                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4580                 return false;
4581             }
4582             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4583                     .equals( "9YX45" ) ) {
4584                 return false;
4585             }
4586             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4587                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4588                     .equals( "MOUSE" ) ) {
4589                 return false;
4590             }
4591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4592                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4593                     .equals( "MOUSE" ) ) {
4594                 return false;
4595             }
4596             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4597                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4598                     .equals( "MOUSE" ) ) {
4599                 return false;
4600             }
4601             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4602                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4603                 return false;
4604             }
4605             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4606                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4607                 return false;
4608             }
4609             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4610                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4611                 return false;
4612             }
4613             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4614                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4615                 return false;
4616             }
4617             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4618                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4619                 return false;
4620             }
4621             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4622                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4623                 return false;
4624             }
4625             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4626                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4627                 return false;
4628             }
4629             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4630                     .equals( "RAT" ) ) {
4631                 return false;
4632             }
4633             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4634                     .equals( "PIG" ) ) {
4635                 return false;
4636             }
4637             if ( !ParserUtils
4638                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4639                     .equals( "MOUSE" ) ) {
4640                 return false;
4641             }
4642             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4643                     .equals( "MOUSE" ) ) {
4644                 return false;
4645             }
4646             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4647                 return false;
4648             }
4649         }
4650         catch ( final Exception e ) {
4651             e.printStackTrace( System.out );
4652             return false;
4653         }
4654         return true;
4655     }
4656
4657     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4658         try {
4659             PhylogenyNode n = new PhylogenyNode();
4660             n.setName( "tr|B3RJ64" );
4661             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4662                 return false;
4663             }
4664             n.setName( "tr.B3RJ64" );
4665             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4666                 return false;
4667             }
4668             n.setName( "tr=B3RJ64" );
4669             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4670                 return false;
4671             }
4672             n.setName( "tr-B3RJ64" );
4673             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4674                 return false;
4675             }
4676             n.setName( "tr/B3RJ64" );
4677             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4678                 return false;
4679             }
4680             n.setName( "tr\\B3RJ64" );
4681             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4682                 return false;
4683             }
4684             n.setName( "tr_B3RJ64" );
4685             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4686                 return false;
4687             }
4688             n.setName( " tr|B3RJ64 " );
4689             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4690                 return false;
4691             }
4692             n.setName( "-tr|B3RJ64-" );
4693             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4694                 return false;
4695             }
4696             n.setName( "-tr=B3RJ64-" );
4697             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4698                 return false;
4699             }
4700             n.setName( "_tr=B3RJ64_" );
4701             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4702                 return false;
4703             }
4704             n.setName( " tr_tr|B3RJ64_sp|123 " );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4706                 return false;
4707             }
4708             n.setName( "B3RJ64" );
4709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4710                 return false;
4711             }
4712             n.setName( "sp|B3RJ64" );
4713             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4714                 return false;
4715             }
4716             n.setName( "sp|B3RJ64C" );
4717             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4718                 return false;
4719             }
4720             n.setName( "sp B3RJ64" );
4721             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4722                 return false;
4723             }
4724             n.setName( "sp|B3RJ6X" );
4725             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4726                 return false;
4727             }
4728             n.setName( "sp|B3RJ6" );
4729             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4730                 return false;
4731             }
4732             n.setName( "K1PYK7_CRAGI" );
4733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4734                 return false;
4735             }
4736             n.setName( "K1PYK7_PEA" );
4737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4738                 return false;
4739             }
4740             n.setName( "K1PYK7_RAT" );
4741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4742                 return false;
4743             }
4744             n.setName( "K1PYK7_PIG" );
4745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4746                 return false;
4747             }
4748             n.setName( "~K1PYK7_PIG~" );
4749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4750                 return false;
4751             }
4752             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4753             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4754                 return false;
4755             }
4756             n.setName( "K1PYKX_CRAGI" );
4757             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4758                 return false;
4759             }
4760             n.setName( "XXXXX_CRAGI" );
4761             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4762                 return false;
4763             }
4764             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4765             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4766                 return false;
4767             }
4768             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4769             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4770                 return false;
4771             }
4772             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4774                 return false;
4775             }
4776             n = new PhylogenyNode();
4777             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4778             seq.setSymbol( "K1PYK7_CRAGI" );
4779             n.getNodeData().addSequence( seq );
4780             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4781                 return false;
4782             }
4783             seq.setSymbol( "tr|B3RJ64" );
4784             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4785                 return false;
4786             }
4787             n = new PhylogenyNode();
4788             seq = new org.forester.phylogeny.data.Sequence();
4789             seq.setName( "K1PYK7_CRAGI" );
4790             n.getNodeData().addSequence( seq );
4791             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4792                 return false;
4793             }
4794             seq.setName( "tr|B3RJ64" );
4795             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4796                 return false;
4797             }
4798             n = new PhylogenyNode();
4799             seq = new org.forester.phylogeny.data.Sequence();
4800             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4801             n.getNodeData().addSequence( seq );
4802             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4803                 return false;
4804             }
4805             n = new PhylogenyNode();
4806             seq = new org.forester.phylogeny.data.Sequence();
4807             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4808             n.getNodeData().addSequence( seq );
4809             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4810                 return false;
4811             }
4812             //
4813             n = new PhylogenyNode();
4814             n.setName( "ACP19736" );
4815             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4816                 return false;
4817             }
4818             n = new PhylogenyNode();
4819             n.setName( "|ACP19736|" );
4820             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4821                 return false;
4822             }
4823         }
4824         catch ( final Exception e ) {
4825             e.printStackTrace( System.out );
4826             return false;
4827         }
4828         return true;
4829     }
4830
4831     private static boolean testFastaParser() {
4832         try {
4833             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4834                 return false;
4835             }
4836             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4837                 return false;
4838             }
4839             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4840             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4841                 return false;
4842             }
4843             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4844                 return false;
4845             }
4846             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4847                 return false;
4848             }
4849             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4850                 return false;
4851             }
4852             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4853                 return false;
4854             }
4855             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4856                 return false;
4857             }
4858         }
4859         catch ( final Exception e ) {
4860             e.printStackTrace();
4861             return false;
4862         }
4863         return true;
4864     }
4865
4866     private static boolean testGenbankAccessorParsing() {
4867         //The format for GenBank Accession numbers are:
4868         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4869         //Protein:    3 letters + 5 numerals
4870         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4871         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4872             return false;
4873         }
4874         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4875             return false;
4876         }
4877         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4878             return false;
4879         }
4880         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4881             return false;
4882         }
4883         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4884             return false;
4885         }
4886         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4887             return false;
4888         }
4889         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4890             return false;
4891         }
4892         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4893             return false;
4894         }
4895         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4896             return false;
4897         }
4898         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4899             return false;
4900         }
4901         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4902             return false;
4903         }
4904         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4905             return false;
4906         }
4907         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4908             return false;
4909         }
4910         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4911             return false;
4912         }
4913         return true;
4914     }
4915
4916     private static boolean testGeneralMsaParser() {
4917         try {
4918             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4919             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4920             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4921             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4922             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4923             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4924             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4925             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4926             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4927                 return false;
4928             }
4929             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4930                 return false;
4931             }
4932             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4933                 return false;
4934             }
4935             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4936                 return false;
4937             }
4938             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4939                 return false;
4940             }
4941             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4942                 return false;
4943             }
4944             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4945                 return false;
4946             }
4947             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4948                 return false;
4949             }
4950             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4951                 return false;
4952             }
4953             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4954                 return false;
4955             }
4956             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4957                 return false;
4958             }
4959             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4960                 return false;
4961             }
4962             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4963             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4964                 return false;
4965             }
4966             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4967                 return false;
4968             }
4969             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4970                 return false;
4971             }
4972             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4973             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4974                 return false;
4975             }
4976             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4977                 return false;
4978             }
4979             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4980                 return false;
4981             }
4982             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4983             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4984                 return false;
4985             }
4986             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4987                 return false;
4988             }
4989             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4990                 return false;
4991             }
4992         }
4993         catch ( final Exception e ) {
4994             e.printStackTrace();
4995             return false;
4996         }
4997         return true;
4998     }
4999
5000     private static boolean testGeneralTable() {
5001         try {
5002             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5003             t0.setValue( 3, 2, "23" );
5004             t0.setValue( 10, 1, "error" );
5005             t0.setValue( 10, 1, "110" );
5006             t0.setValue( 9, 1, "19" );
5007             t0.setValue( 1, 10, "101" );
5008             t0.setValue( 10, 10, "1010" );
5009             t0.setValue( 100, 10, "10100" );
5010             t0.setValue( 0, 0, "00" );
5011             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5012                 return false;
5013             }
5014             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5015                 return false;
5016             }
5017             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5018                 return false;
5019             }
5020             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5021                 return false;
5022             }
5023             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5024                 return false;
5025             }
5026             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5027                 return false;
5028             }
5029             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5030                 return false;
5031             }
5032             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5033                 return false;
5034             }
5035             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5036                 return false;
5037             }
5038             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5039             t1.setValue( "3", "2", "23" );
5040             t1.setValue( "10", "1", "error" );
5041             t1.setValue( "10", "1", "110" );
5042             t1.setValue( "9", "1", "19" );
5043             t1.setValue( "1", "10", "101" );
5044             t1.setValue( "10", "10", "1010" );
5045             t1.setValue( "100", "10", "10100" );
5046             t1.setValue( "0", "0", "00" );
5047             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5048             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5049                 return false;
5050             }
5051             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5052                 return false;
5053             }
5054             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5055                 return false;
5056             }
5057             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5058                 return false;
5059             }
5060             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5061                 return false;
5062             }
5063             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5064                 return false;
5065             }
5066             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5067                 return false;
5068             }
5069             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5070                 return false;
5071             }
5072             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5073                 return false;
5074             }
5075             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5076                 return false;
5077             }
5078         }
5079         catch ( final Exception e ) {
5080             e.printStackTrace( System.out );
5081             return false;
5082         }
5083         return true;
5084     }
5085
5086     private static boolean testGetDistance() {
5087         try {
5088             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5089             final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r",
5090                                                  new NHXParser() )[ 0 ];
5091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5095                 return false;
5096             }
5097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5098                 return false;
5099             }
5100             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5101                 return false;
5102             }
5103             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5104                 return false;
5105             }
5106             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5107                 return false;
5108             }
5109             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5110                 return false;
5111             }
5112             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5113                 return false;
5114             }
5115             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5116                 return false;
5117             }
5118             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5119                 return false;
5120             }
5121             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5122                 return false;
5123             }
5124             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5125                 return false;
5126             }
5127             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5128                 return false;
5129             }
5130             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5131                 return false;
5132             }
5133             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5134                 return false;
5135             }
5136             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5137                 return false;
5138             }
5139             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5140                 return false;
5141             }
5142             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5143                 return false;
5144             }
5145             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5146                 return false;
5147             }
5148             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5149                 return false;
5150             }
5151             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5152                 return false;
5153             }
5154             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5155                 return false;
5156             }
5157             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5158                 return false;
5159             }
5160             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5161                 return false;
5162             }
5163             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5164                 return false;
5165             }
5166             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5167                 return false;
5168             }
5169             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5170                 return false;
5171             }
5172             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5173                 return false;
5174             }
5175             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5176                 return false;
5177             }
5178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5179                 return false;
5180             }
5181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5182                 return false;
5183             }
5184             final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r",
5185                                                  new NHXParser() )[ 0 ];
5186             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5187                 return false;
5188             }
5189             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5190                 return false;
5191             }
5192             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5193                 return false;
5194             }
5195             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5196                 return false;
5197             }
5198             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5199                 return false;
5200             }
5201             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5202                 return false;
5203             }
5204             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5205                 return false;
5206             }
5207             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5208                 return false;
5209             }
5210             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5211                 return false;
5212             }
5213             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5214                 return false;
5215             }
5216             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5217                 return false;
5218             }
5219         }
5220         catch ( final Exception e ) {
5221             e.printStackTrace( System.out );
5222             return false;
5223         }
5224         return true;
5225     }
5226
5227     private static boolean testGetLCA() {
5228         try {
5229             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5230             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5231                                                  new NHXParser() )[ 0 ];
5232             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5233             if ( !A.getName().equals( "A" ) ) {
5234                 return false;
5235             }
5236             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5237             if ( !gh.getName().equals( "gh" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5241             if ( !ab.getName().equals( "ab" ) ) {
5242                 return false;
5243             }
5244             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5245             if ( !ab2.getName().equals( "ab" ) ) {
5246                 return false;
5247             }
5248             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5249             if ( !gh2.getName().equals( "gh" ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5253             if ( !gh3.getName().equals( "gh" ) ) {
5254                 return false;
5255             }
5256             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5257             if ( !abc.getName().equals( "abc" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5261             if ( !abc2.getName().equals( "abc" ) ) {
5262                 return false;
5263             }
5264             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5265             if ( !abcd.getName().equals( "abcd" ) ) {
5266                 return false;
5267             }
5268             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5269             if ( !abcd2.getName().equals( "abcd" ) ) {
5270                 return false;
5271             }
5272             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5273             if ( !abcdef.getName().equals( "abcdef" ) ) {
5274                 return false;
5275             }
5276             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5277             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5281             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5285             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5286                 return false;
5287             }
5288             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5289             if ( !abcde.getName().equals( "abcde" ) ) {
5290                 return false;
5291             }
5292             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5293             if ( !abcde2.getName().equals( "abcde" ) ) {
5294                 return false;
5295             }
5296             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5297             if ( !r.getName().equals( "abcdefgh" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5301             if ( !r2.getName().equals( "abcdefgh" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5305             if ( !r3.getName().equals( "abcdefgh" ) ) {
5306                 return false;
5307             }
5308             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5309             if ( !abcde3.getName().equals( "abcde" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5313             if ( !abcde4.getName().equals( "abcde" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5317             if ( !ab3.getName().equals( "ab" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5321             if ( !ab4.getName().equals( "ab" ) ) {
5322                 return false;
5323             }
5324             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5325             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5326             if ( !cd.getName().equals( "cd" ) ) {
5327                 return false;
5328             }
5329             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5330             if ( !cd2.getName().equals( "cd" ) ) {
5331                 return false;
5332             }
5333             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5334             if ( !cde.getName().equals( "cde" ) ) {
5335                 return false;
5336             }
5337             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5338             if ( !cde2.getName().equals( "cde" ) ) {
5339                 return false;
5340             }
5341             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5342             if ( !cdef.getName().equals( "cdef" ) ) {
5343                 return false;
5344             }
5345             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5346             if ( !cdef2.getName().equals( "cdef" ) ) {
5347                 return false;
5348             }
5349             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5350             if ( !cdef3.getName().equals( "cdef" ) ) {
5351                 return false;
5352             }
5353             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5354             if ( !rt.getName().equals( "r" ) ) {
5355                 return false;
5356             }
5357             final Phylogeny p3 = factory
5358                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5359                              new NHXParser() )[ 0 ];
5360             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5361             if ( !bc_3.getName().equals( "bc" ) ) {
5362                 return false;
5363             }
5364             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5365             if ( !ac_3.getName().equals( "abc" ) ) {
5366                 return false;
5367             }
5368             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5369             if ( !ad_3.getName().equals( "abcde" ) ) {
5370                 return false;
5371             }
5372             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5373             if ( !af_3.getName().equals( "abcdef" ) ) {
5374                 return false;
5375             }
5376             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5377             if ( !ag_3.getName().equals( "" ) ) {
5378                 return false;
5379             }
5380             if ( !ag_3.isRoot() ) {
5381                 return false;
5382             }
5383             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5384             if ( !al_3.getName().equals( "" ) ) {
5385                 return false;
5386             }
5387             if ( !al_3.isRoot() ) {
5388                 return false;
5389             }
5390             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5391             if ( !kl_3.getName().equals( "" ) ) {
5392                 return false;
5393             }
5394             if ( !kl_3.isRoot() ) {
5395                 return false;
5396             }
5397             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5398             if ( !fl_3.getName().equals( "" ) ) {
5399                 return false;
5400             }
5401             if ( !fl_3.isRoot() ) {
5402                 return false;
5403             }
5404             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5405             if ( !gk_3.getName().equals( "ghijk" ) ) {
5406                 return false;
5407             }
5408             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5409             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5410             if ( !r_4.getName().equals( "r" ) ) {
5411                 return false;
5412             }
5413             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5414             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5415             if ( !r_5.getName().equals( "root" ) ) {
5416                 return false;
5417             }
5418             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5419             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5420             if ( !r_6.getName().equals( "rot" ) ) {
5421                 return false;
5422             }
5423             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5424             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5425             if ( !r_7.getName().equals( "rott" ) ) {
5426                 return false;
5427             }
5428         }
5429         catch ( final Exception e ) {
5430             e.printStackTrace( System.out );
5431             return false;
5432         }
5433         return true;
5434     }
5435
5436     private static boolean testGetLCA2() {
5437         try {
5438             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5439             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5440             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5441             PhylogenyMethods.preOrderReId( p_a );
5442             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5443                                                                                               p_a.getNode( "a" ) );
5444             if ( !p_a_1.getName().equals( "a" ) ) {
5445                 return false;
5446             }
5447             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5448             PhylogenyMethods.preOrderReId( p_b );
5449             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5450                                                                                               p_b.getNode( "a" ) );
5451             if ( !p_b_1.getName().equals( "b" ) ) {
5452                 return false;
5453             }
5454             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5455                                                                                               p_b.getNode( "b" ) );
5456             if ( !p_b_2.getName().equals( "b" ) ) {
5457                 return false;
5458             }
5459             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5460             PhylogenyMethods.preOrderReId( p_c );
5461             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5462                                                                                               p_c.getNode( "a" ) );
5463             if ( !p_c_1.getName().equals( "b" ) ) {
5464                 return false;
5465             }
5466             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5467                                                                                               p_c.getNode( "c" ) );
5468             if ( !p_c_2.getName().equals( "c" ) ) {
5469                 System.out.println( p_c_2.getName() );
5470                 System.exit( -1 );
5471                 return false;
5472             }
5473             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5474                                                                                               p_c.getNode( "b" ) );
5475             if ( !p_c_3.getName().equals( "b" ) ) {
5476                 return false;
5477             }
5478             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5479                                                                                               p_c.getNode( "a" ) );
5480             if ( !p_c_4.getName().equals( "c" ) ) {
5481                 return false;
5482             }
5483             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5484                                                  new NHXParser() )[ 0 ];
5485             PhylogenyMethods.preOrderReId( p1 );
5486             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5487                                                                                           p1.getNode( "A" ) );
5488             if ( !A.getName().equals( "A" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5492                                                                                            p1.getNode( "gh" ) );
5493             if ( !gh.getName().equals( "gh" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5497                                                                                            p1.getNode( "B" ) );
5498             if ( !ab.getName().equals( "ab" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5502                                                                                             p1.getNode( "A" ) );
5503             if ( !ab2.getName().equals( "ab" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5507                                                                                             p1.getNode( "G" ) );
5508             if ( !gh2.getName().equals( "gh" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5512                                                                                             p1.getNode( "H" ) );
5513             if ( !gh3.getName().equals( "gh" ) ) {
5514                 return false;
5515             }
5516             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5517                                                                                             p1.getNode( "A" ) );
5518             if ( !abc.getName().equals( "abc" ) ) {
5519                 return false;
5520             }
5521             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5522                                                                                              p1.getNode( "C" ) );
5523             if ( !abc2.getName().equals( "abc" ) ) {
5524                 return false;
5525             }
5526             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5527                                                                                              p1.getNode( "D" ) );
5528             if ( !abcd.getName().equals( "abcd" ) ) {
5529                 return false;
5530             }
5531             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5532                                                                                               p1.getNode( "A" ) );
5533             if ( !abcd2.getName().equals( "abcd" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5537                                                                                                p1.getNode( "F" ) );
5538             if ( !abcdef.getName().equals( "abcdef" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5542                                                                                                 p1.getNode( "A" ) );
5543             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5544                 return false;
5545             }
5546             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5547                                                                                                 p1.getNode( "F" ) );
5548             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5552                                                                                                 p1.getNode( "ab" ) );
5553             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5554                 return false;
5555             }
5556             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5557                                                                                               p1.getNode( "E" ) );
5558             if ( !abcde.getName().equals( "abcde" ) ) {
5559                 return false;
5560             }
5561             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5562                                                                                                p1.getNode( "A" ) );
5563             if ( !abcde2.getName().equals( "abcde" ) ) {
5564                 return false;
5565             }
5566             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5567                                                                                           p1.getNode( "abcdefgh" ) );
5568             if ( !r.getName().equals( "abcdefgh" ) ) {
5569                 return false;
5570             }
5571             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5572                                                                                            p1.getNode( "H" ) );
5573             if ( !r2.getName().equals( "abcdefgh" ) ) {
5574                 return false;
5575             }
5576             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5577                                                                                            p1.getNode( "A" ) );
5578             if ( !r3.getName().equals( "abcdefgh" ) ) {
5579                 return false;
5580             }
5581             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5582                                                                                                p1.getNode( "abcde" ) );
5583             if ( !abcde3.getName().equals( "abcde" ) ) {
5584                 return false;
5585             }
5586             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5587                                                                                                p1.getNode( "E" ) );
5588             if ( !abcde4.getName().equals( "abcde" ) ) {
5589                 return false;
5590             }
5591             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5592                                                                                             p1.getNode( "B" ) );
5593             if ( !ab3.getName().equals( "ab" ) ) {
5594                 return false;
5595             }
5596             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5597                                                                                             p1.getNode( "ab" ) );
5598             if ( !ab4.getName().equals( "ab" ) ) {
5599                 return false;
5600             }
5601             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5602             PhylogenyMethods.preOrderReId( p2 );
5603             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5604                                                                                            p2.getNode( "d" ) );
5605             if ( !cd.getName().equals( "cd" ) ) {
5606                 return false;
5607             }
5608             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5609                                                                                             p2.getNode( "c" ) );
5610             if ( !cd2.getName().equals( "cd" ) ) {
5611                 return false;
5612             }
5613             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5614                                                                                             p2.getNode( "e" ) );
5615             if ( !cde.getName().equals( "cde" ) ) {
5616                 return false;
5617             }
5618             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5619                                                                                              p2.getNode( "c" ) );
5620             if ( !cde2.getName().equals( "cde" ) ) {
5621                 return false;
5622             }
5623             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5624                                                                                              p2.getNode( "f" ) );
5625             if ( !cdef.getName().equals( "cdef" ) ) {
5626                 return false;
5627             }
5628             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5629                                                                                               p2.getNode( "f" ) );
5630             if ( !cdef2.getName().equals( "cdef" ) ) {
5631                 return false;
5632             }
5633             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5634                                                                                               p2.getNode( "d" ) );
5635             if ( !cdef3.getName().equals( "cdef" ) ) {
5636                 return false;
5637             }
5638             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5639                                                                                            p2.getNode( "a" ) );
5640             if ( !rt.getName().equals( "r" ) ) {
5641                 return false;
5642             }
5643             final Phylogeny p3 = factory
5644                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5645                              new NHXParser() )[ 0 ];
5646             PhylogenyMethods.preOrderReId( p3 );
5647             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5648                                                                                              p3.getNode( "c" ) );
5649             if ( !bc_3.getName().equals( "bc" ) ) {
5650                 return false;
5651             }
5652             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5653                                                                                              p3.getNode( "c" ) );
5654             if ( !ac_3.getName().equals( "abc" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5658                                                                                              p3.getNode( "d" ) );
5659             if ( !ad_3.getName().equals( "abcde" ) ) {
5660                 return false;
5661             }
5662             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5663                                                                                              p3.getNode( "f" ) );
5664             if ( !af_3.getName().equals( "abcdef" ) ) {
5665                 return false;
5666             }
5667             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5668                                                                                              p3.getNode( "g" ) );
5669             if ( !ag_3.getName().equals( "" ) ) {
5670                 return false;
5671             }
5672             if ( !ag_3.isRoot() ) {
5673                 return false;
5674             }
5675             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5676                                                                                              p3.getNode( "l" ) );
5677             if ( !al_3.getName().equals( "" ) ) {
5678                 return false;
5679             }
5680             if ( !al_3.isRoot() ) {
5681                 return false;
5682             }
5683             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5684                                                                                              p3.getNode( "l" ) );
5685             if ( !kl_3.getName().equals( "" ) ) {
5686                 return false;
5687             }
5688             if ( !kl_3.isRoot() ) {
5689                 return false;
5690             }
5691             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5692                                                                                              p3.getNode( "l" ) );
5693             if ( !fl_3.getName().equals( "" ) ) {
5694                 return false;
5695             }
5696             if ( !fl_3.isRoot() ) {
5697                 return false;
5698             }
5699             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5700                                                                                              p3.getNode( "k" ) );
5701             if ( !gk_3.getName().equals( "ghijk" ) ) {
5702                 return false;
5703             }
5704             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5705             PhylogenyMethods.preOrderReId( p4 );
5706             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5707                                                                                             p4.getNode( "c" ) );
5708             if ( !r_4.getName().equals( "r" ) ) {
5709                 return false;
5710             }
5711             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5712             PhylogenyMethods.preOrderReId( p5 );
5713             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5714                                                                                             p5.getNode( "c" ) );
5715             if ( !r_5.getName().equals( "root" ) ) {
5716                 return false;
5717             }
5718             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5719             PhylogenyMethods.preOrderReId( p6 );
5720             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5721                                                                                             p6.getNode( "a" ) );
5722             if ( !r_6.getName().equals( "rot" ) ) {
5723                 return false;
5724             }
5725             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5726             PhylogenyMethods.preOrderReId( p7 );
5727             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5728                                                                                             p7.getNode( "e" ) );
5729             if ( !r_7.getName().equals( "rott" ) ) {
5730                 return false;
5731             }
5732             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5733                                                                                              p7.getNode( "a" ) );
5734             if ( !r_71.getName().equals( "rott" ) ) {
5735                 return false;
5736             }
5737             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5738                                                                                              p7.getNode( "rott" ) );
5739             if ( !r_72.getName().equals( "rott" ) ) {
5740                 return false;
5741             }
5742             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5743                                                                                              p7.getNode( "a" ) );
5744             if ( !r_73.getName().equals( "rott" ) ) {
5745                 return false;
5746             }
5747             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5748                                                                                              p7.getNode( "rott" ) );
5749             if ( !r_74.getName().equals( "rott" ) ) {
5750                 return false;
5751             }
5752             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5753                                                                                              p7.getNode( "e" ) );
5754             if ( !r_75.getName().equals( "e" ) ) {
5755                 return false;
5756             }
5757         }
5758         catch ( final Exception e ) {
5759             e.printStackTrace( System.out );
5760             return false;
5761         }
5762         return true;
5763     }
5764
5765     private static boolean testHmmscanOutputParser() {
5766         final String test_dir = Test.PATH_TO_TEST_DATA;
5767         try {
5768             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5769                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5770             parser1.parse();
5771             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5772                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5773             final List<Protein> proteins = parser2.parse();
5774             if ( parser2.getProteinsEncountered() != 4 ) {
5775                 return false;
5776             }
5777             if ( proteins.size() != 4 ) {
5778                 return false;
5779             }
5780             if ( parser2.getDomainsEncountered() != 69 ) {
5781                 return false;
5782             }
5783             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5784                 return false;
5785             }
5786             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5787                 return false;
5788             }
5789             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5790                 return false;
5791             }
5792             final Protein p1 = proteins.get( 0 );
5793             if ( p1.getNumberOfProteinDomains() != 15 ) {
5794                 return false;
5795             }
5796             if ( p1.getLength() != 850 ) {
5797                 return false;
5798             }
5799             final Protein p2 = proteins.get( 1 );
5800             if ( p2.getNumberOfProteinDomains() != 51 ) {
5801                 return false;
5802             }
5803             if ( p2.getLength() != 1291 ) {
5804                 return false;
5805             }
5806             final Protein p3 = proteins.get( 2 );
5807             if ( p3.getNumberOfProteinDomains() != 2 ) {
5808                 return false;
5809             }
5810             final Protein p4 = proteins.get( 3 );
5811             if ( p4.getNumberOfProteinDomains() != 1 ) {
5812                 return false;
5813             }
5814             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5815                 return false;
5816             }
5817             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5818                 return false;
5819             }
5820             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5821                 return false;
5822             }
5823             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5824                 return false;
5825             }
5826             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5827                 return false;
5828             }
5829             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5830                 return false;
5831             }
5832             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5833                 return false;
5834             }
5835         }
5836         catch ( final Exception e ) {
5837             e.printStackTrace( System.out );
5838             return false;
5839         }
5840         return true;
5841     }
5842
5843     private static boolean testLastExternalNodeMethods() {
5844         try {
5845             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5846             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5847             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5848             final PhylogenyNode n1 = t0.getNode( "A" );
5849             if ( n1.isLastExternalNode() ) {
5850                 return false;
5851             }
5852             final PhylogenyNode n2 = t0.getNode( "B" );
5853             if ( n2.isLastExternalNode() ) {
5854                 return false;
5855             }
5856             final PhylogenyNode n3 = t0.getNode( "C" );
5857             if ( n3.isLastExternalNode() ) {
5858                 return false;
5859             }
5860             final PhylogenyNode n4 = t0.getNode( "D" );
5861             if ( !n4.isLastExternalNode() ) {
5862                 return false;
5863             }
5864         }
5865         catch ( final Exception e ) {
5866             e.printStackTrace( System.out );
5867             return false;
5868         }
5869         return true;
5870     }
5871
5872     private static boolean testLevelOrderIterator() {
5873         try {
5874             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5875             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5876             PhylogenyNodeIterator it0;
5877             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5878                 it0.next();
5879             }
5880             for( it0.reset(); it0.hasNext(); ) {
5881                 it0.next();
5882             }
5883             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5884             if ( !it.next().getName().equals( "r" ) ) {
5885                 return false;
5886             }
5887             if ( !it.next().getName().equals( "ab" ) ) {
5888                 return false;
5889             }
5890             if ( !it.next().getName().equals( "cd" ) ) {
5891                 return false;
5892             }
5893             if ( !it.next().getName().equals( "A" ) ) {
5894                 return false;
5895             }
5896             if ( !it.next().getName().equals( "B" ) ) {
5897                 return false;
5898             }
5899             if ( !it.next().getName().equals( "C" ) ) {
5900                 return false;
5901             }
5902             if ( !it.next().getName().equals( "D" ) ) {
5903                 return false;
5904             }
5905             if ( it.hasNext() ) {
5906                 return false;
5907             }
5908             final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r",
5909                                                  new NHXParser() )[ 0 ];
5910             PhylogenyNodeIterator it2;
5911             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5912                 it2.next();
5913             }
5914             for( it2.reset(); it2.hasNext(); ) {
5915                 it2.next();
5916             }
5917             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5918             if ( !it3.next().getName().equals( "r" ) ) {
5919                 return false;
5920             }
5921             if ( !it3.next().getName().equals( "abc" ) ) {
5922                 return false;
5923             }
5924             if ( !it3.next().getName().equals( "defg" ) ) {
5925                 return false;
5926             }
5927             if ( !it3.next().getName().equals( "A" ) ) {
5928                 return false;
5929             }
5930             if ( !it3.next().getName().equals( "B" ) ) {
5931                 return false;
5932             }
5933             if ( !it3.next().getName().equals( "C" ) ) {
5934                 return false;
5935             }
5936             if ( !it3.next().getName().equals( "D" ) ) {
5937                 return false;
5938             }
5939             if ( !it3.next().getName().equals( "E" ) ) {
5940                 return false;
5941             }
5942             if ( !it3.next().getName().equals( "F" ) ) {
5943                 return false;
5944             }
5945             if ( !it3.next().getName().equals( "G" ) ) {
5946                 return false;
5947             }
5948             if ( !it3.next().getName().equals( "1" ) ) {
5949                 return false;
5950             }
5951             if ( !it3.next().getName().equals( "2" ) ) {
5952                 return false;
5953             }
5954             if ( !it3.next().getName().equals( "3" ) ) {
5955                 return false;
5956             }
5957             if ( !it3.next().getName().equals( "4" ) ) {
5958                 return false;
5959             }
5960             if ( !it3.next().getName().equals( "5" ) ) {
5961                 return false;
5962             }
5963             if ( !it3.next().getName().equals( "6" ) ) {
5964                 return false;
5965             }
5966             if ( !it3.next().getName().equals( "f1" ) ) {
5967                 return false;
5968             }
5969             if ( !it3.next().getName().equals( "f2" ) ) {
5970                 return false;
5971             }
5972             if ( !it3.next().getName().equals( "f3" ) ) {
5973                 return false;
5974             }
5975             if ( !it3.next().getName().equals( "a" ) ) {
5976                 return false;
5977             }
5978             if ( !it3.next().getName().equals( "b" ) ) {
5979                 return false;
5980             }
5981             if ( !it3.next().getName().equals( "f21" ) ) {
5982                 return false;
5983             }
5984             if ( !it3.next().getName().equals( "X" ) ) {
5985                 return false;
5986             }
5987             if ( !it3.next().getName().equals( "Y" ) ) {
5988                 return false;
5989             }
5990             if ( !it3.next().getName().equals( "Z" ) ) {
5991                 return false;
5992             }
5993             if ( it3.hasNext() ) {
5994                 return false;
5995             }
5996             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5997             PhylogenyNodeIterator it4;
5998             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5999                 it4.next();
6000             }
6001             for( it4.reset(); it4.hasNext(); ) {
6002                 it4.next();
6003             }
6004             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6005             if ( !it5.next().getName().equals( "r" ) ) {
6006                 return false;
6007             }
6008             if ( !it5.next().getName().equals( "A" ) ) {
6009                 return false;
6010             }
6011             if ( !it5.next().getName().equals( "B" ) ) {
6012                 return false;
6013             }
6014             if ( !it5.next().getName().equals( "C" ) ) {
6015                 return false;
6016             }
6017             if ( !it5.next().getName().equals( "D" ) ) {
6018                 return false;
6019             }
6020             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6021             PhylogenyNodeIterator it6;
6022             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6023                 it6.next();
6024             }
6025             for( it6.reset(); it6.hasNext(); ) {
6026                 it6.next();
6027             }
6028             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6029             if ( !it7.next().getName().equals( "A" ) ) {
6030                 return false;
6031             }
6032             if ( it.hasNext() ) {
6033                 return false;
6034             }
6035         }
6036         catch ( final Exception e ) {
6037             e.printStackTrace( System.out );
6038             return false;
6039         }
6040         return true;
6041     }
6042
6043     private static boolean testMafft( final String path ) {
6044         try {
6045             final List<String> opts = new ArrayList<String>();
6046             opts.add( "--maxiterate" );
6047             opts.add( "1000" );
6048             opts.add( "--localpair" );
6049             opts.add( "--quiet" );
6050             Msa msa = null;
6051             final MsaInferrer mafft = Mafft.createInstance( path );
6052             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6053             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6054                 return false;
6055             }
6056             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6057                 return false;
6058             }
6059         }
6060         catch ( final Exception e ) {
6061             e.printStackTrace( System.out );
6062             return false;
6063         }
6064         return true;
6065     }
6066
6067     private static boolean testMidpointrooting() {
6068         try {
6069             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6070             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6071             PhylogenyMethods.midpointRoot( t0 );
6072             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6073                 return false;
6074             }
6075             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6076                 return false;
6077             }
6078             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6079                            1 ) ) {
6080                 return false;
6081             }
6082             final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5",
6083                                                  new NHXParser() )[ 0 ];
6084             if ( !t1.isRooted() ) {
6085                 return false;
6086             }
6087             PhylogenyMethods.midpointRoot( t1 );
6088             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6089                 return false;
6090             }
6091             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6092                 return false;
6093             }
6094             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6095                 return false;
6096             }
6097             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6098                 return false;
6099             }
6100             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6101                 return false;
6102             }
6103             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6104                 return false;
6105             }
6106             t1.reRoot( t1.getNode( "A" ) );
6107             PhylogenyMethods.midpointRoot( t1 );
6108             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6109                 return false;
6110             }
6111             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6112                 return false;
6113             }
6114             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6115                 return false;
6116             }
6117             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6118                 return false;
6119             }
6120             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6121                 System.exit( -1 );
6122                 return false;
6123             }
6124             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6125                 return false;
6126             }
6127         }
6128         catch ( final Exception e ) {
6129             e.printStackTrace( System.out );
6130             return false;
6131         }
6132         return true;
6133     }
6134
6135     private static boolean testMsaQualityMethod() {
6136         try {
6137             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6138             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6139             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6140             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6141             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6142             l.add( s0 );
6143             l.add( s1 );
6144             l.add( s2 );
6145             l.add( s3 );
6146             final Msa msa = BasicMsa.createInstance( l );
6147             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6148                 return false;
6149             }
6150             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6151                 return false;
6152             }
6153             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6154                 return false;
6155             }
6156             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6157                 return false;
6158             }
6159             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6160                 return false;
6161             }
6162             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6163                 return false;
6164             }
6165             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6166                 return false;
6167             }
6168         }
6169         catch ( final Exception e ) {
6170             e.printStackTrace( System.out );
6171             return false;
6172         }
6173         return true;
6174     }
6175
6176     private static boolean testMsaEntropy() {
6177         try {
6178             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6179             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6180             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6181             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6182             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6183             l.add( s0 );
6184             l.add( s1 );
6185             l.add( s2 );
6186             l.add( s3 );
6187             final Msa msa = BasicMsa.createInstance( l );
6188             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6189             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6190             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6191             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6192             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6193             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6194             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6195             System.out.println();
6196             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6197             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6198             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6199             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6200             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6201             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6202             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6203             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6204             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6205             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6206             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6207             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6208             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6209             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6210             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6211             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6212             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6213             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6214             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6215             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6216             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6217             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6218             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6219             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6220             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6221             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6222             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6223             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6224             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6225             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6226             final Msa msa2 = BasicMsa.createInstance( l2 );
6227             System.out.println();
6228             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6229             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6230             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6231         }
6232         catch ( final Exception e ) {
6233             e.printStackTrace( System.out );
6234             return false;
6235         }
6236         return true;
6237     }
6238
6239     private static boolean testDeleteableMsa() {
6240         try {
6241             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6242             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6243             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6244             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6245             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6246             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6247             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6248             l0.add( s0 );
6249             l0.add( s1 );
6250             l0.add( s2 );
6251             l0.add( s3 );
6252             l0.add( s4 );
6253             l0.add( s5 );
6254             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6255             dmsa0.deleteRow( "b", false );
6256             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6257                 return false;
6258             }
6259             dmsa0.deleteRow( "e", false );
6260             dmsa0.deleteRow( "a", false );
6261             dmsa0.deleteRow( "f", false );
6262             if ( dmsa0.getLength() != 4 ) {
6263                 return false;
6264             }
6265             if ( dmsa0.getNumberOfSequences() != 2 ) {
6266                 return false;
6267             }
6268             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6269                 return false;
6270             }
6271             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6272                 return false;
6273             }
6274             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6275                 return false;
6276             }
6277             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6278                 return false;
6279             }
6280             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6281                 return false;
6282             }
6283             dmsa0.deleteRow( "c", false );
6284             dmsa0.deleteRow( "d", false );
6285             if ( dmsa0.getNumberOfSequences() != 0 ) {
6286                 return false;
6287             }
6288             //
6289             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6290             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6291             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6292             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6293             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6294             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6295             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6296             l1.add( s_0 );
6297             l1.add( s_1 );
6298             l1.add( s_2 );
6299             l1.add( s_3 );
6300             l1.add( s_4 );
6301             l1.add( s_5 );
6302             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6303             dmsa1.deleteGapOnlyColumns();
6304             dmsa1.deleteRow( "a", false );
6305             dmsa1.deleteRow( "f", false );
6306             dmsa1.deleteRow( "d", false );
6307             dmsa1.deleteGapOnlyColumns();
6308             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6309                 return false;
6310             }
6311             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6312                 return false;
6313             }
6314             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6315                 return false;
6316             }
6317             dmsa1.deleteRow( "c", false );
6318             dmsa1.deleteGapOnlyColumns();
6319             final Writer w0 = new StringWriter();
6320             dmsa1.write( w0, MSA_FORMAT.FASTA );
6321             final Writer w1 = new StringWriter();
6322             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6323             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6324                 return false;
6325             }
6326             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6327                 return false;
6328             }
6329             //
6330             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6331             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6332             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6333             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6334             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6335             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6336             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6337             l2.add( s__0 );
6338             l2.add( s__1 );
6339             l2.add( s__2 );
6340             l2.add( s__3 );
6341             l2.add( s__4 );
6342             l2.add( s__5 );
6343             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6344             dmsa2.deleteGapColumns( 0.5 );
6345             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6346                 return false;
6347             }
6348             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6349                 return false;
6350             }
6351             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6352                 return false;
6353             }
6354             dmsa2.deleteGapColumns( 0.2 );
6355             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6356                 return false;
6357             }
6358             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6359                 return false;
6360             }
6361             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6362                 return false;
6363             }
6364             dmsa2.deleteGapColumns( 0 );
6365             dmsa2.deleteRow( "a", false );
6366             dmsa2.deleteRow( "b", false );
6367             dmsa2.deleteRow( "f", false );
6368             dmsa2.deleteRow( "e", false );
6369             dmsa2.setIdentifier( 0, "new_c" );
6370             dmsa2.setIdentifier( 1, "new_d" );
6371             dmsa2.setResidueAt( 0, 0, 'x' );
6372             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6373             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6374                 return false;
6375             }
6376             final Writer w = new StringWriter();
6377             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6378             final String phylip = w.toString();
6379             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6380                 System.out.println( phylip );
6381                 return false;
6382             }
6383             final Writer w2 = new StringWriter();
6384             dmsa2.write( w2, MSA_FORMAT.FASTA );
6385             final String fasta = w2.toString();
6386             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6387                 System.out.println( fasta );
6388                 return false;
6389             }
6390         }
6391         catch ( final Exception e ) {
6392             e.printStackTrace( System.out );
6393             return false;
6394         }
6395         return true;
6396     }
6397
6398     private static boolean testNextNodeWithCollapsing() {
6399         try {
6400             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6401             PhylogenyNode n;
6402             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6403             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6404             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6405             t0.getNode( "cd" ).setCollapse( true );
6406             t0.getNode( "cde" ).setCollapse( true );
6407             n = t0.getFirstExternalNode();
6408             while ( n != null ) {
6409                 ext.add( n );
6410                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6411             }
6412             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6413                 return false;
6414             }
6415             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6416                 return false;
6417             }
6418             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6419                 return false;
6420             }
6421             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6422                 return false;
6423             }
6424             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6425                 return false;
6426             }
6427             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6428                 return false;
6429             }
6430             ext.clear();
6431             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6432             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6433             t1.getNode( "ab" ).setCollapse( true );
6434             t1.getNode( "cd" ).setCollapse( true );
6435             t1.getNode( "cde" ).setCollapse( true );
6436             n = t1.getNode( "ab" );
6437             ext = new ArrayList<PhylogenyNode>();
6438             while ( n != null ) {
6439                 ext.add( n );
6440                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6441             }
6442             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6443                 return false;
6444             }
6445             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6446                 return false;
6447             }
6448             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6449                 return false;
6450             }
6451             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6452                 return false;
6453             }
6454             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6455                 return false;
6456             }
6457             //
6458             //
6459             ext.clear();
6460             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6461             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6462             t2.getNode( "ab" ).setCollapse( true );
6463             t2.getNode( "cd" ).setCollapse( true );
6464             t2.getNode( "cde" ).setCollapse( true );
6465             t2.getNode( "c" ).setCollapse( true );
6466             t2.getNode( "d" ).setCollapse( true );
6467             t2.getNode( "e" ).setCollapse( true );
6468             t2.getNode( "gh" ).setCollapse( true );
6469             n = t2.getNode( "ab" );
6470             ext = new ArrayList<PhylogenyNode>();
6471             while ( n != null ) {
6472                 ext.add( n );
6473                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6474             }
6475             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6476                 return false;
6477             }
6478             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6479                 return false;
6480             }
6481             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6482                 return false;
6483             }
6484             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6485                 return false;
6486             }
6487             //
6488             //
6489             ext.clear();
6490             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6491             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6492             t3.getNode( "ab" ).setCollapse( true );
6493             t3.getNode( "cd" ).setCollapse( true );
6494             t3.getNode( "cde" ).setCollapse( true );
6495             t3.getNode( "c" ).setCollapse( true );
6496             t3.getNode( "d" ).setCollapse( true );
6497             t3.getNode( "e" ).setCollapse( true );
6498             t3.getNode( "gh" ).setCollapse( true );
6499             t3.getNode( "fgh" ).setCollapse( true );
6500             n = t3.getNode( "ab" );
6501             ext = new ArrayList<PhylogenyNode>();
6502             while ( n != null ) {
6503                 ext.add( n );
6504                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6505             }
6506             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6507                 return false;
6508             }
6509             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6510                 return false;
6511             }
6512             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6513                 return false;
6514             }
6515             //
6516             //
6517             ext.clear();
6518             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6519             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6520             t4.getNode( "ab" ).setCollapse( true );
6521             t4.getNode( "cd" ).setCollapse( true );
6522             t4.getNode( "cde" ).setCollapse( true );
6523             t4.getNode( "c" ).setCollapse( true );
6524             t4.getNode( "d" ).setCollapse( true );
6525             t4.getNode( "e" ).setCollapse( true );
6526             t4.getNode( "gh" ).setCollapse( true );
6527             t4.getNode( "fgh" ).setCollapse( true );
6528             t4.getNode( "abcdefgh" ).setCollapse( true );
6529             n = t4.getNode( "abcdefgh" );
6530             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6531                 return false;
6532             }
6533             //
6534             //
6535             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6536             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6537             ext.clear();
6538             n = t5.getFirstExternalNode();
6539             while ( n != null ) {
6540                 ext.add( n );
6541                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6542             }
6543             if ( ext.size() != 8 ) {
6544                 return false;
6545             }
6546             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6547                 return false;
6548             }
6549             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6550                 return false;
6551             }
6552             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6553                 return false;
6554             }
6555             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6556                 return false;
6557             }
6558             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6559                 return false;
6560             }
6561             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6562                 return false;
6563             }
6564             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6565                 return false;
6566             }
6567             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6568                 return false;
6569             }
6570             //
6571             //
6572             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6573             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6574             ext.clear();
6575             t6.getNode( "ab" ).setCollapse( true );
6576             n = t6.getNode( "ab" );
6577             while ( n != null ) {
6578                 ext.add( n );
6579                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6580             }
6581             if ( ext.size() != 7 ) {
6582                 return false;
6583             }
6584             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6585                 return false;
6586             }
6587             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6588                 return false;
6589             }
6590             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6591                 return false;
6592             }
6593             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6594                 return false;
6595             }
6596             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6597                 return false;
6598             }
6599             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6600                 return false;
6601             }
6602             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6603                 return false;
6604             }
6605             //
6606             //
6607             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6608             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6609             ext.clear();
6610             t7.getNode( "cd" ).setCollapse( true );
6611             n = t7.getNode( "a" );
6612             while ( n != null ) {
6613                 ext.add( n );
6614                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6615             }
6616             if ( ext.size() != 7 ) {
6617                 return false;
6618             }
6619             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6620                 return false;
6621             }
6622             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6623                 return false;
6624             }
6625             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6626                 return false;
6627             }
6628             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6629                 return false;
6630             }
6631             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6632                 return false;
6633             }
6634             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6635                 return false;
6636             }
6637             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6638                 return false;
6639             }
6640             //
6641             //
6642             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6643             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6644             ext.clear();
6645             t8.getNode( "cd" ).setCollapse( true );
6646             t8.getNode( "c" ).setCollapse( true );
6647             t8.getNode( "d" ).setCollapse( true );
6648             n = t8.getNode( "a" );
6649             while ( n != null ) {
6650                 ext.add( n );
6651                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6652             }
6653             if ( ext.size() != 7 ) {
6654                 return false;
6655             }
6656             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6657                 return false;
6658             }
6659             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6660                 return false;
6661             }
6662             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6663                 System.out.println( "2 fail" );
6664                 return false;
6665             }
6666             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6667                 return false;
6668             }
6669             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6670                 return false;
6671             }
6672             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6673                 return false;
6674             }
6675             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6676                 return false;
6677             }
6678             //
6679             //
6680             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6681             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6682             ext.clear();
6683             t9.getNode( "gh" ).setCollapse( true );
6684             n = t9.getNode( "a" );
6685             while ( n != null ) {
6686                 ext.add( n );
6687                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6688             }
6689             if ( ext.size() != 7 ) {
6690                 return false;
6691             }
6692             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6693                 return false;
6694             }
6695             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6696                 return false;
6697             }
6698             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6699                 return false;
6700             }
6701             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6702                 return false;
6703             }
6704             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6705                 return false;
6706             }
6707             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6708                 return false;
6709             }
6710             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6711                 return false;
6712             }
6713             //
6714             //
6715             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6716             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6717             ext.clear();
6718             t10.getNode( "gh" ).setCollapse( true );
6719             t10.getNode( "g" ).setCollapse( true );
6720             t10.getNode( "h" ).setCollapse( true );
6721             n = t10.getNode( "a" );
6722             while ( n != null ) {
6723                 ext.add( n );
6724                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6725             }
6726             if ( ext.size() != 7 ) {
6727                 return false;
6728             }
6729             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6730                 return false;
6731             }
6732             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6733                 return false;
6734             }
6735             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6736                 return false;
6737             }
6738             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6739                 return false;
6740             }
6741             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6742                 return false;
6743             }
6744             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6745                 return false;
6746             }
6747             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6748                 return false;
6749             }
6750             //
6751             //
6752             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6753             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6754             ext.clear();
6755             t11.getNode( "gh" ).setCollapse( true );
6756             t11.getNode( "fgh" ).setCollapse( true );
6757             n = t11.getNode( "a" );
6758             while ( n != null ) {
6759                 ext.add( n );
6760                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6761             }
6762             if ( ext.size() != 6 ) {
6763                 return false;
6764             }
6765             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6766                 return false;
6767             }
6768             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6769                 return false;
6770             }
6771             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6772                 return false;
6773             }
6774             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6775                 return false;
6776             }
6777             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6778                 return false;
6779             }
6780             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6781                 return false;
6782             }
6783             //
6784             //
6785             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6786             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6787             ext.clear();
6788             t12.getNode( "gh" ).setCollapse( true );
6789             t12.getNode( "fgh" ).setCollapse( true );
6790             t12.getNode( "g" ).setCollapse( true );
6791             t12.getNode( "h" ).setCollapse( true );
6792             t12.getNode( "f" ).setCollapse( true );
6793             n = t12.getNode( "a" );
6794             while ( n != null ) {
6795                 ext.add( n );
6796                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6797             }
6798             if ( ext.size() != 6 ) {
6799                 return false;
6800             }
6801             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6802                 return false;
6803             }
6804             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6805                 return false;
6806             }
6807             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6808                 return false;
6809             }
6810             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6811                 return false;
6812             }
6813             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6814                 return false;
6815             }
6816             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6817                 return false;
6818             }
6819             //
6820             //
6821             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6822             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6823             ext.clear();
6824             t13.getNode( "ab" ).setCollapse( true );
6825             t13.getNode( "b" ).setCollapse( true );
6826             t13.getNode( "fgh" ).setCollapse( true );
6827             t13.getNode( "gh" ).setCollapse( true );
6828             n = t13.getNode( "ab" );
6829             while ( n != null ) {
6830                 ext.add( n );
6831                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6832             }
6833             if ( ext.size() != 5 ) {
6834                 return false;
6835             }
6836             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6837                 return false;
6838             }
6839             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6840                 return false;
6841             }
6842             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6843                 return false;
6844             }
6845             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6846                 return false;
6847             }
6848             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6849                 return false;
6850             }
6851             //
6852             //
6853             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6854             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6855             ext.clear();
6856             t14.getNode( "ab" ).setCollapse( true );
6857             t14.getNode( "a" ).setCollapse( true );
6858             t14.getNode( "fgh" ).setCollapse( true );
6859             t14.getNode( "gh" ).setCollapse( true );
6860             n = t14.getNode( "ab" );
6861             while ( n != null ) {
6862                 ext.add( n );
6863                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6864             }
6865             if ( ext.size() != 5 ) {
6866                 return false;
6867             }
6868             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6869                 return false;
6870             }
6871             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6872                 return false;
6873             }
6874             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6875                 return false;
6876             }
6877             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6878                 return false;
6879             }
6880             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6881                 return false;
6882             }
6883             //
6884             //
6885             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" );
6886             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6887             ext.clear();
6888             t15.getNode( "ab" ).setCollapse( true );
6889             t15.getNode( "a" ).setCollapse( true );
6890             t15.getNode( "fgh" ).setCollapse( true );
6891             t15.getNode( "gh" ).setCollapse( true );
6892             n = t15.getNode( "ab" );
6893             while ( n != null ) {
6894                 ext.add( n );
6895                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6896             }
6897             if ( ext.size() != 6 ) {
6898                 return false;
6899             }
6900             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6901                 return false;
6902             }
6903             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6904                 return false;
6905             }
6906             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6907                 return false;
6908             }
6909             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6910                 return false;
6911             }
6912             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6913                 return false;
6914             }
6915             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6916                 return false;
6917             }
6918             //
6919             //
6920             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" );
6921             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6922             ext.clear();
6923             t16.getNode( "ab" ).setCollapse( true );
6924             t16.getNode( "a" ).setCollapse( true );
6925             t16.getNode( "fgh" ).setCollapse( true );
6926             t16.getNode( "gh" ).setCollapse( true );
6927             t16.getNode( "cd" ).setCollapse( true );
6928             t16.getNode( "cde" ).setCollapse( true );
6929             t16.getNode( "d" ).setCollapse( true );
6930             t16.getNode( "x" ).setCollapse( true );
6931             n = t16.getNode( "ab" );
6932             while ( n != null ) {
6933                 ext.add( n );
6934                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6935             }
6936             if ( ext.size() != 4 ) {
6937                 return false;
6938             }
6939             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6940                 return false;
6941             }
6942             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6943                 return false;
6944             }
6945             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6946                 return false;
6947             }
6948             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6949                 return false;
6950             }
6951         }
6952         catch ( final Exception e ) {
6953             e.printStackTrace( System.out );
6954             return false;
6955         }
6956         return true;
6957     }
6958
6959     private static boolean testNexusCharactersParsing() {
6960         try {
6961             final NexusCharactersParser parser = new NexusCharactersParser();
6962             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6963             parser.parse();
6964             String[] labels = parser.getCharStateLabels();
6965             if ( labels.length != 7 ) {
6966                 return false;
6967             }
6968             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6969                 return false;
6970             }
6971             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6972                 return false;
6973             }
6974             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6975                 return false;
6976             }
6977             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6978                 return false;
6979             }
6980             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6981                 return false;
6982             }
6983             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6984                 return false;
6985             }
6986             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6987                 return false;
6988             }
6989             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6990             parser.parse();
6991             labels = parser.getCharStateLabels();
6992             if ( labels.length != 7 ) {
6993                 return false;
6994             }
6995             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6996                 return false;
6997             }
6998             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6999                 return false;
7000             }
7001             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7002                 return false;
7003             }
7004             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7005                 return false;
7006             }
7007             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7008                 return false;
7009             }
7010             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7011                 return false;
7012             }
7013             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7014                 return false;
7015             }
7016         }
7017         catch ( final Exception e ) {
7018             e.printStackTrace( System.out );
7019             return false;
7020         }
7021         return true;
7022     }
7023
7024     private static boolean testNexusMatrixParsing() {
7025         try {
7026             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7027             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7028             parser.parse();
7029             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7030             if ( m.getNumberOfCharacters() != 9 ) {
7031                 return false;
7032             }
7033             if ( m.getNumberOfIdentifiers() != 5 ) {
7034                 return false;
7035             }
7036             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7037                 return false;
7038             }
7039             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7040                 return false;
7041             }
7042             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7043                 return false;
7044             }
7045             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7046                 return false;
7047             }
7048             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7049                 return false;
7050             }
7051             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7052                 return false;
7053             }
7054             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7055                 return false;
7056             }
7057             //            if ( labels.length != 7 ) {
7058             //                return false;
7059             //            }
7060             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7061             //                return false;
7062             //            }
7063             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7064             //                return false;
7065             //            }
7066             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7067             //                return false;
7068             //            }
7069             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7070             //                return false;
7071             //            }
7072             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7073             //                return false;
7074             //            }
7075             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7076             //                return false;
7077             //            }
7078             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7079             //                return false;
7080             //            }
7081             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7082             //            parser.parse();
7083             //            labels = parser.getCharStateLabels();
7084             //            if ( labels.length != 7 ) {
7085             //                return false;
7086             //            }
7087             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7088             //                return false;
7089             //            }
7090             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7091             //                return false;
7092             //            }
7093             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7094             //                return false;
7095             //            }
7096             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7097             //                return false;
7098             //            }
7099             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7100             //                return false;
7101             //            }
7102             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7103             //                return false;
7104             //            }
7105             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7106             //                return false;
7107             //            }
7108         }
7109         catch ( final Exception e ) {
7110             e.printStackTrace( System.out );
7111             return false;
7112         }
7113         return true;
7114     }
7115
7116     private static boolean testNexusTreeParsing() {
7117         try {
7118             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7119             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7120             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7121             if ( phylogenies.length != 1 ) {
7122                 return false;
7123             }
7124             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7125                 return false;
7126             }
7127             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7128                 return false;
7129             }
7130             phylogenies = null;
7131             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7132             if ( phylogenies.length != 1 ) {
7133                 return false;
7134             }
7135             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7136                 return false;
7137             }
7138             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7139                 return false;
7140             }
7141             phylogenies = null;
7142             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7143             if ( phylogenies.length != 1 ) {
7144                 return false;
7145             }
7146             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7147                 return false;
7148             }
7149             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7150                 return false;
7151             }
7152             if ( phylogenies[ 0 ].isRooted() ) {
7153                 return false;
7154             }
7155             phylogenies = null;
7156             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7157             if ( phylogenies.length != 18 ) {
7158                 return false;
7159             }
7160             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7161                 return false;
7162             }
7163             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7164                 return false;
7165             }
7166             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7167                 return false;
7168             }
7169             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7170                 return false;
7171             }
7172             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7173                 return false;
7174             }
7175             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7176                 return false;
7177             }
7178             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7179                 return false;
7180             }
7181             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7182                 return false;
7183             }
7184             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7185                 return false;
7186             }
7187             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7188                 return false;
7189             }
7190             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7191                 return false;
7192             }
7193             if ( phylogenies[ 8 ].isRooted() ) {
7194                 return false;
7195             }
7196             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7197                 return false;
7198             }
7199             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7200                 return false;
7201             }
7202             if ( !phylogenies[ 9 ].isRooted() ) {
7203                 return false;
7204             }
7205             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7206                 return false;
7207             }
7208             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7209                 return false;
7210             }
7211             if ( !phylogenies[ 10 ].isRooted() ) {
7212                 return false;
7213             }
7214             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7215                 return false;
7216             }
7217             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7218                 return false;
7219             }
7220             if ( phylogenies[ 11 ].isRooted() ) {
7221                 return false;
7222             }
7223             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7224                 return false;
7225             }
7226             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7227                 return false;
7228             }
7229             if ( !phylogenies[ 12 ].isRooted() ) {
7230                 return false;
7231             }
7232             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7233                 return false;
7234             }
7235             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7236                 return false;
7237             }
7238             if ( !phylogenies[ 13 ].isRooted() ) {
7239                 return false;
7240             }
7241             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7242                 return false;
7243             }
7244             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7245                 return false;
7246             }
7247             if ( !phylogenies[ 14 ].isRooted() ) {
7248                 return false;
7249             }
7250             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7251                 return false;
7252             }
7253             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7254                 return false;
7255             }
7256             if ( phylogenies[ 15 ].isRooted() ) {
7257                 return false;
7258             }
7259             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7260                 return false;
7261             }
7262             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7263                 return false;
7264             }
7265             if ( !phylogenies[ 16 ].isRooted() ) {
7266                 return false;
7267             }
7268             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7269                 return false;
7270             }
7271             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7272                 return false;
7273             }
7274             if ( phylogenies[ 17 ].isRooted() ) {
7275                 return false;
7276             }
7277             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7278                 return false;
7279             }
7280             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7281             phylogenies = null;
7282             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7283             if ( phylogenies.length != 9 ) {
7284                 return false;
7285             }
7286             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7287                     .getDistanceToParent() ) ) {
7288                 return false;
7289             }
7290             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7291                     .getDistanceToParent() ) ) {
7292                 return false;
7293             }
7294             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7295                 return false;
7296             }
7297             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7298                 return false;
7299             }
7300             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7301                 return false;
7302             }
7303             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7304                 return false;
7305             }
7306             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7307                 return false;
7308             }
7309         }
7310         catch ( final Exception e ) {
7311             e.printStackTrace( System.out );
7312             return false;
7313         }
7314         return true;
7315     }
7316
7317     private static boolean testNexusTreeParsingIterating() {
7318         try {
7319             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7320             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7321             if ( !p.hasNext() ) {
7322                 return false;
7323             }
7324             Phylogeny phy = p.next();
7325             if ( phy == null ) {
7326                 return false;
7327             }
7328             if ( phy.getNumberOfExternalNodes() != 25 ) {
7329                 return false;
7330             }
7331             if ( !phy.getName().equals( "" ) ) {
7332                 return false;
7333             }
7334             if ( p.hasNext() ) {
7335                 return false;
7336             }
7337             phy = p.next();
7338             if ( phy != null ) {
7339                 return false;
7340             }
7341             //
7342             p.reset();
7343             if ( !p.hasNext() ) {
7344                 return false;
7345             }
7346             phy = p.next();
7347             if ( phy == null ) {
7348                 return false;
7349             }
7350             if ( phy.getNumberOfExternalNodes() != 25 ) {
7351                 return false;
7352             }
7353             if ( !phy.getName().equals( "" ) ) {
7354                 return false;
7355             }
7356             if ( p.hasNext() ) {
7357                 return false;
7358             }
7359             phy = p.next();
7360             if ( phy != null ) {
7361                 return false;
7362             }
7363             ////
7364             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7365             if ( !p.hasNext() ) {
7366                 return false;
7367             }
7368             phy = p.next();
7369             if ( phy == null ) {
7370                 return false;
7371             }
7372             if ( phy.getNumberOfExternalNodes() != 10 ) {
7373                 return false;
7374             }
7375             if ( !phy.getName().equals( "name" ) ) {
7376                 return false;
7377             }
7378             if ( p.hasNext() ) {
7379                 return false;
7380             }
7381             phy = p.next();
7382             if ( phy != null ) {
7383                 return false;
7384             }
7385             //
7386             p.reset();
7387             if ( !p.hasNext() ) {
7388                 return false;
7389             }
7390             phy = p.next();
7391             if ( phy == null ) {
7392                 return false;
7393             }
7394             if ( phy.getNumberOfExternalNodes() != 10 ) {
7395                 return false;
7396             }
7397             if ( !phy.getName().equals( "name" ) ) {
7398                 return false;
7399             }
7400             if ( p.hasNext() ) {
7401                 return false;
7402             }
7403             phy = p.next();
7404             if ( phy != null ) {
7405                 return false;
7406             }
7407             //
7408             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7409             if ( !p.hasNext() ) {
7410                 return false;
7411             }
7412             phy = p.next();
7413             if ( phy == null ) {
7414                 return false;
7415             }
7416             if ( phy.getNumberOfExternalNodes() != 3 ) {
7417                 return false;
7418             }
7419             if ( !phy.getName().equals( "" ) ) {
7420                 return false;
7421             }
7422             if ( phy.isRooted() ) {
7423                 return false;
7424             }
7425             if ( p.hasNext() ) {
7426                 return false;
7427             }
7428             phy = p.next();
7429             if ( phy != null ) {
7430                 return false;
7431             }
7432             //
7433             p.reset();
7434             if ( !p.hasNext() ) {
7435                 return false;
7436             }
7437             phy = p.next();
7438             if ( phy == null ) {
7439                 return false;
7440             }
7441             if ( phy.getNumberOfExternalNodes() != 3 ) {
7442                 return false;
7443             }
7444             if ( !phy.getName().equals( "" ) ) {
7445                 return false;
7446             }
7447             if ( p.hasNext() ) {
7448                 return false;
7449             }
7450             phy = p.next();
7451             if ( phy != null ) {
7452                 return false;
7453             }
7454             //
7455             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7456             if ( !p.hasNext() ) {
7457                 return false;
7458             }
7459             //0
7460             phy = p.next();
7461             if ( phy == null ) {
7462                 return false;
7463             }
7464             if ( phy.getNumberOfExternalNodes() != 10 ) {
7465                 return false;
7466             }
7467             if ( !phy.getName().equals( "tree 0" ) ) {
7468                 return false;
7469             }
7470             //1
7471             if ( !p.hasNext() ) {
7472                 return false;
7473             }
7474             phy = p.next();
7475             if ( phy == null ) {
7476                 return false;
7477             }
7478             if ( phy.getNumberOfExternalNodes() != 10 ) {
7479                 return false;
7480             }
7481             if ( !phy.getName().equals( "tree 1" ) ) {
7482                 return false;
7483             }
7484             //2
7485             if ( !p.hasNext() ) {
7486                 return false;
7487             }
7488             phy = p.next();
7489             if ( phy == null ) {
7490                 return false;
7491             }
7492             if ( phy.getNumberOfExternalNodes() != 3 ) {
7493                 System.out.println( phy.toString() );
7494                 return false;
7495             }
7496             if ( !phy.getName().equals( "" ) ) {
7497                 return false;
7498             }
7499             if ( phy.isRooted() ) {
7500                 return false;
7501             }
7502             //3
7503             if ( !p.hasNext() ) {
7504                 return false;
7505             }
7506             phy = p.next();
7507             if ( phy == null ) {
7508                 return false;
7509             }
7510             if ( phy.getNumberOfExternalNodes() != 4 ) {
7511                 return false;
7512             }
7513             if ( !phy.getName().equals( "" ) ) {
7514                 return false;
7515             }
7516             if ( !phy.isRooted() ) {
7517                 return false;
7518             }
7519             //4
7520             if ( !p.hasNext() ) {
7521                 return false;
7522             }
7523             phy = p.next();
7524             if ( phy == null ) {
7525                 return false;
7526             }
7527             if ( phy.getNumberOfExternalNodes() != 5 ) {
7528                 System.out.println( phy.getNumberOfExternalNodes() );
7529                 return false;
7530             }
7531             if ( !phy.getName().equals( "" ) ) {
7532                 return false;
7533             }
7534             if ( !phy.isRooted() ) {
7535                 return false;
7536             }
7537             //5
7538             if ( !p.hasNext() ) {
7539                 return false;
7540             }
7541             phy = p.next();
7542             if ( phy == null ) {
7543                 return false;
7544             }
7545             if ( phy.getNumberOfExternalNodes() != 3 ) {
7546                 return false;
7547             }
7548             if ( !phy.getName().equals( "" ) ) {
7549                 return false;
7550             }
7551             if ( phy.isRooted() ) {
7552                 return false;
7553             }
7554             //6
7555             if ( !p.hasNext() ) {
7556                 return false;
7557             }
7558             phy = p.next();
7559             if ( phy == null ) {
7560                 return false;
7561             }
7562             if ( phy.getNumberOfExternalNodes() != 2 ) {
7563                 return false;
7564             }
7565             if ( !phy.getName().equals( "" ) ) {
7566                 return false;
7567             }
7568             if ( !phy.isRooted() ) {
7569                 return false;
7570             }
7571             //7
7572             if ( !p.hasNext() ) {
7573                 return false;
7574             }
7575             phy = p.next();
7576             if ( phy.getNumberOfExternalNodes() != 3 ) {
7577                 return false;
7578             }
7579             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7580                 return false;
7581             }
7582             if ( !phy.isRooted() ) {
7583                 return false;
7584             }
7585             //8
7586             if ( !p.hasNext() ) {
7587                 return false;
7588             }
7589             phy = p.next();
7590             if ( phy.getNumberOfExternalNodes() != 3 ) {
7591                 return false;
7592             }
7593             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7594                 return false;
7595             }
7596             if ( !phy.getName().equals( "tree 8" ) ) {
7597                 return false;
7598             }
7599             //9
7600             if ( !p.hasNext() ) {
7601                 return false;
7602             }
7603             phy = p.next();
7604             if ( phy.getNumberOfExternalNodes() != 3 ) {
7605                 return false;
7606             }
7607             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7608                 return false;
7609             }
7610             if ( !phy.getName().equals( "tree 9" ) ) {
7611                 return false;
7612             }
7613             //10
7614             if ( !p.hasNext() ) {
7615                 return false;
7616             }
7617             phy = p.next();
7618             if ( phy.getNumberOfExternalNodes() != 3 ) {
7619                 return false;
7620             }
7621             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7622                 return false;
7623             }
7624             if ( !phy.getName().equals( "tree 10" ) ) {
7625                 return false;
7626             }
7627             if ( !phy.isRooted() ) {
7628                 return false;
7629             }
7630             //11
7631             if ( !p.hasNext() ) {
7632                 return false;
7633             }
7634             phy = p.next();
7635             if ( phy.getNumberOfExternalNodes() != 3 ) {
7636                 return false;
7637             }
7638             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7639                 return false;
7640             }
7641             if ( !phy.getName().equals( "tree 11" ) ) {
7642                 return false;
7643             }
7644             if ( phy.isRooted() ) {
7645                 return false;
7646             }
7647             //12
7648             if ( !p.hasNext() ) {
7649                 return false;
7650             }
7651             phy = p.next();
7652             if ( phy.getNumberOfExternalNodes() != 3 ) {
7653                 return false;
7654             }
7655             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7656                 return false;
7657             }
7658             if ( !phy.getName().equals( "tree 12" ) ) {
7659                 return false;
7660             }
7661             if ( !phy.isRooted() ) {
7662                 return false;
7663             }
7664             //13
7665             if ( !p.hasNext() ) {
7666                 return false;
7667             }
7668             phy = p.next();
7669             if ( phy.getNumberOfExternalNodes() != 3 ) {
7670                 return false;
7671             }
7672             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7673                 return false;
7674             }
7675             if ( !phy.getName().equals( "tree 13" ) ) {
7676                 return false;
7677             }
7678             if ( !phy.isRooted() ) {
7679                 return false;
7680             }
7681             //14
7682             if ( !p.hasNext() ) {
7683                 return false;
7684             }
7685             phy = p.next();
7686             if ( phy.getNumberOfExternalNodes() != 10 ) {
7687                 System.out.println( phy.getNumberOfExternalNodes() );
7688                 return false;
7689             }
7690             if ( !phy
7691                     .toNewHampshire()
7692                     .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;" ) ) {
7693                 System.out.println( phy.toNewHampshire() );
7694                 return false;
7695             }
7696             if ( !phy.getName().equals( "tree 14" ) ) {
7697                 return false;
7698             }
7699             if ( !phy.isRooted() ) {
7700                 return false;
7701             }
7702             //15
7703             if ( !p.hasNext() ) {
7704                 return false;
7705             }
7706             phy = p.next();
7707             if ( phy.getNumberOfExternalNodes() != 10 ) {
7708                 System.out.println( phy.getNumberOfExternalNodes() );
7709                 return false;
7710             }
7711             if ( !phy
7712                     .toNewHampshire()
7713                     .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;" ) ) {
7714                 System.out.println( phy.toNewHampshire() );
7715                 return false;
7716             }
7717             if ( !phy.getName().equals( "tree 15" ) ) {
7718                 return false;
7719             }
7720             if ( phy.isRooted() ) {
7721                 return false;
7722             }
7723             //16
7724             if ( !p.hasNext() ) {
7725                 return false;
7726             }
7727             phy = p.next();
7728             if ( phy.getNumberOfExternalNodes() != 10 ) {
7729                 System.out.println( phy.getNumberOfExternalNodes() );
7730                 return false;
7731             }
7732             if ( !phy
7733                     .toNewHampshire()
7734                     .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;" ) ) {
7735                 System.out.println( phy.toNewHampshire() );
7736                 return false;
7737             }
7738             if ( !phy.getName().equals( "tree 16" ) ) {
7739                 return false;
7740             }
7741             if ( !phy.isRooted() ) {
7742                 return false;
7743             }
7744             //17
7745             if ( !p.hasNext() ) {
7746                 return false;
7747             }
7748             phy = p.next();
7749             if ( phy.getNumberOfExternalNodes() != 10 ) {
7750                 System.out.println( phy.getNumberOfExternalNodes() );
7751                 return false;
7752             }
7753             if ( !phy
7754                     .toNewHampshire()
7755                     .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;" ) ) {
7756                 System.out.println( phy.toNewHampshire() );
7757                 return false;
7758             }
7759             if ( !phy.getName().equals( "tree 17" ) ) {
7760                 return false;
7761             }
7762             if ( phy.isRooted() ) {
7763                 return false;
7764             }
7765             //
7766             if ( p.hasNext() ) {
7767                 return false;
7768             }
7769             phy = p.next();
7770             if ( phy != null ) {
7771                 return false;
7772             }
7773             p.reset();
7774             //0
7775             if ( !p.hasNext() ) {
7776                 return false;
7777             }
7778             phy = p.next();
7779             if ( phy == null ) {
7780                 return false;
7781             }
7782             if ( phy.getNumberOfExternalNodes() != 10 ) {
7783                 return false;
7784             }
7785             if ( !phy.getName().equals( "tree 0" ) ) {
7786                 return false;
7787             }
7788             //1
7789             if ( !p.hasNext() ) {
7790                 return false;
7791             }
7792             phy = p.next();
7793             if ( phy == null ) {
7794                 return false;
7795             }
7796             if ( phy.getNumberOfExternalNodes() != 10 ) {
7797                 return false;
7798             }
7799             if ( !phy.getName().equals( "tree 1" ) ) {
7800                 return false;
7801             }
7802             //2
7803             if ( !p.hasNext() ) {
7804                 return false;
7805             }
7806             phy = p.next();
7807             if ( phy == null ) {
7808                 return false;
7809             }
7810             if ( phy.getNumberOfExternalNodes() != 3 ) {
7811                 return false;
7812             }
7813             if ( !phy.getName().equals( "" ) ) {
7814                 return false;
7815             }
7816             if ( phy.isRooted() ) {
7817                 return false;
7818             }
7819             //3
7820             if ( !p.hasNext() ) {
7821                 return false;
7822             }
7823             phy = p.next();
7824             if ( phy == null ) {
7825                 return false;
7826             }
7827             if ( phy.getNumberOfExternalNodes() != 4 ) {
7828                 return false;
7829             }
7830             if ( !phy.getName().equals( "" ) ) {
7831                 return false;
7832             }
7833             if ( !phy.isRooted() ) {
7834                 return false;
7835             }
7836             //4
7837             if ( !p.hasNext() ) {
7838                 return false;
7839             }
7840             phy = p.next();
7841             if ( phy == null ) {
7842                 return false;
7843             }
7844             if ( phy.getNumberOfExternalNodes() != 5 ) {
7845                 System.out.println( phy.getNumberOfExternalNodes() );
7846                 return false;
7847             }
7848             if ( !phy.getName().equals( "" ) ) {
7849                 return false;
7850             }
7851             if ( !phy.isRooted() ) {
7852                 return false;
7853             }
7854             //5
7855             if ( !p.hasNext() ) {
7856                 return false;
7857             }
7858             phy = p.next();
7859             if ( phy == null ) {
7860                 return false;
7861             }
7862             if ( phy.getNumberOfExternalNodes() != 3 ) {
7863                 return false;
7864             }
7865             if ( !phy.getName().equals( "" ) ) {
7866                 return false;
7867             }
7868             if ( phy.isRooted() ) {
7869                 return false;
7870             }
7871             //
7872             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7873             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7874             // 0
7875             if ( !p2.hasNext() ) {
7876                 return false;
7877             }
7878             phy = p2.next();
7879             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7880                 return false;
7881             }
7882             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7883                 return false;
7884             }
7885             // 1
7886             if ( !p2.hasNext() ) {
7887                 return false;
7888             }
7889             phy = p2.next();
7890             // 2
7891             if ( !p2.hasNext() ) {
7892                 return false;
7893             }
7894             phy = p2.next();
7895             // 3
7896             if ( !p2.hasNext() ) {
7897                 return false;
7898             }
7899             phy = p2.next();
7900             // 4
7901             if ( !p2.hasNext() ) {
7902                 return false;
7903             }
7904             phy = p2.next();
7905             // 5
7906             if ( !p2.hasNext() ) {
7907                 return false;
7908             }
7909             phy = p2.next();
7910             // 6
7911             if ( !p2.hasNext() ) {
7912                 return false;
7913             }
7914             phy = p2.next();
7915             // 7
7916             if ( !p2.hasNext() ) {
7917                 return false;
7918             }
7919             phy = p2.next();
7920             // 8
7921             if ( !p2.hasNext() ) {
7922                 return false;
7923             }
7924             phy = p2.next();
7925             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7926                 return false;
7927             }
7928             if ( p2.hasNext() ) {
7929                 return false;
7930             }
7931             phy = p2.next();
7932             if ( phy != null ) {
7933                 return false;
7934             }
7935             // 0
7936             p2.reset();
7937             if ( !p2.hasNext() ) {
7938                 return false;
7939             }
7940             phy = p2.next();
7941             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7942                 return false;
7943             }
7944             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7945                 return false;
7946             }
7947         }
7948         catch ( final Exception e ) {
7949             e.printStackTrace( System.out );
7950             return false;
7951         }
7952         return true;
7953     }
7954
7955     private static boolean testNexusTreeParsingTranslating() {
7956         try {
7957             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7958             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7959             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7960             if ( phylogenies.length != 1 ) {
7961                 return false;
7962             }
7963             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7964                 return false;
7965             }
7966             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7967                 return false;
7968             }
7969             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7970                 return false;
7971             }
7972             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7973                 return false;
7974             }
7975             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7976                     .equals( "Aranaeus" ) ) {
7977                 return false;
7978             }
7979             phylogenies = null;
7980             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7981             if ( phylogenies.length != 3 ) {
7982                 return false;
7983             }
7984             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7985                 return false;
7986             }
7987             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7988                 return false;
7989             }
7990             if ( phylogenies[ 0 ].isRooted() ) {
7991                 return false;
7992             }
7993             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7994                 return false;
7995             }
7996             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7997                 return false;
7998             }
7999             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8000                     .equals( "Aranaeus" ) ) {
8001                 return false;
8002             }
8003             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8004                 return false;
8005             }
8006             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8007                 return false;
8008             }
8009             if ( phylogenies[ 1 ].isRooted() ) {
8010                 return false;
8011             }
8012             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8013                 return false;
8014             }
8015             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8016                 return false;
8017             }
8018             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8019                     .equals( "Aranaeus" ) ) {
8020                 return false;
8021             }
8022             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8023                 return false;
8024             }
8025             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8026                 return false;
8027             }
8028             if ( !phylogenies[ 2 ].isRooted() ) {
8029                 return false;
8030             }
8031             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8032                 return false;
8033             }
8034             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8035                 return false;
8036             }
8037             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8038                     .equals( "Aranaeus" ) ) {
8039                 return false;
8040             }
8041             phylogenies = null;
8042             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8043             if ( phylogenies.length != 3 ) {
8044                 return false;
8045             }
8046             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8047                 return false;
8048             }
8049             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8050                 return false;
8051             }
8052             if ( phylogenies[ 0 ].isRooted() ) {
8053                 return false;
8054             }
8055             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8056                 return false;
8057             }
8058             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8059                 return false;
8060             }
8061             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8062                     .equals( "Aranaeus" ) ) {
8063                 return false;
8064             }
8065             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8066                 return false;
8067             }
8068             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8069                 return false;
8070             }
8071             if ( phylogenies[ 1 ].isRooted() ) {
8072                 return false;
8073             }
8074             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8075                 return false;
8076             }
8077             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8078                 return false;
8079             }
8080             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8081                     .equals( "Aranaeus" ) ) {
8082                 return false;
8083             }
8084             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8085                 return false;
8086             }
8087             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8088                 return false;
8089             }
8090             if ( !phylogenies[ 2 ].isRooted() ) {
8091                 return false;
8092             }
8093             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8094                 return false;
8095             }
8096             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8097                 return false;
8098             }
8099             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8100                     .equals( "Aranaeus" ) ) {
8101                 return false;
8102             }
8103             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8104             if ( phylogenies.length != 3 ) {
8105                 return false;
8106             }
8107             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8108                            0.00100049 ) ) {
8109                 return false;
8110             }
8111         }
8112         catch ( final Exception e ) {
8113             e.printStackTrace( System.out );
8114             return false;
8115         }
8116         return true;
8117     }
8118
8119     private static boolean testNHParsing() {
8120         try {
8121             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8122             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8123             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8124                 return false;
8125             }
8126             final NHXParser nhxp = new NHXParser();
8127             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8128             nhxp.setReplaceUnderscores( true );
8129             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8130             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8131                 return false;
8132             }
8133             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8134                 return false;
8135             }
8136             final Phylogeny p1b = factory
8137                     .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 ",
8138                              new NHXParser() )[ 0 ];
8139             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8140                 return false;
8141             }
8142             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8143                 return false;
8144             }
8145             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8146             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8147             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8148             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8149             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8150             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8151             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8152             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8153             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8154             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8155             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8156                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8157                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8158                                                     new NHXParser() );
8159             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8160                 return false;
8161             }
8162             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8163                 return false;
8164             }
8165             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8166                 return false;
8167             }
8168             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8169                 return false;
8170             }
8171             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8172             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8173             final String p16_S = "((A,B),C)";
8174             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8175             if ( p16.length != 1 ) {
8176                 return false;
8177             }
8178             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8179                 return false;
8180             }
8181             final String p17_S = "(C,(A,B))";
8182             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8183             if ( p17.length != 1 ) {
8184                 return false;
8185             }
8186             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8187                 return false;
8188             }
8189             final String p18_S = "((A,B),(C,D))";
8190             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8191             if ( p18.length != 1 ) {
8192                 return false;
8193             }
8194             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8195                 return false;
8196             }
8197             final String p19_S = "(((A,B),C),D)";
8198             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8199             if ( p19.length != 1 ) {
8200                 return false;
8201             }
8202             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8203                 return false;
8204             }
8205             final String p20_S = "(A,(B,(C,D)))";
8206             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8207             if ( p20.length != 1 ) {
8208                 return false;
8209             }
8210             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8211                 return false;
8212             }
8213             final String p21_S = "(A,(B,(C,(D,E))))";
8214             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8215             if ( p21.length != 1 ) {
8216                 return false;
8217             }
8218             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8219                 return false;
8220             }
8221             final String p22_S = "((((A,B),C),D),E)";
8222             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8223             if ( p22.length != 1 ) {
8224                 return false;
8225             }
8226             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8227                 return false;
8228             }
8229             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8230             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8231             if ( p23.length != 1 ) {
8232                 System.out.println( "xl=" + p23.length );
8233                 System.exit( -1 );
8234                 return false;
8235             }
8236             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8237                 return false;
8238             }
8239             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8240             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8241             if ( p24.length != 1 ) {
8242                 return false;
8243             }
8244             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8245                 return false;
8246             }
8247             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8248             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8249             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8250             if ( p241.length != 2 ) {
8251                 return false;
8252             }
8253             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8254                 return false;
8255             }
8256             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8257                 return false;
8258             }
8259             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8260                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8261                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8262                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8263                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8264                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8265                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8266                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8267             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8268             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8269                 return false;
8270             }
8271             final String p26_S = "(A,B)ab";
8272             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8273             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8274                 return false;
8275             }
8276             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8277             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8278             if ( p27s.length != 1 ) {
8279                 System.out.println( "xxl=" + p27s.length );
8280                 System.exit( -1 );
8281                 return false;
8282             }
8283             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8284                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8285                 System.exit( -1 );
8286                 return false;
8287             }
8288             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8289                                                     new NHXParser() );
8290             if ( p27.length != 1 ) {
8291                 System.out.println( "yl=" + p27.length );
8292                 System.exit( -1 );
8293                 return false;
8294             }
8295             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8296                 System.out.println( p27[ 0 ].toNewHampshireX() );
8297                 System.exit( -1 );
8298                 return false;
8299             }
8300             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8301             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8302             final String p28_S3 = "(A,B)ab";
8303             final String p28_S4 = "((((A,B),C),D),;E;)";
8304             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8305                                                     new NHXParser() );
8306             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8307                 return false;
8308             }
8309             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8310                 return false;
8311             }
8312             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8313                 return false;
8314             }
8315             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8316                 return false;
8317             }
8318             if ( p28.length != 4 ) {
8319                 return false;
8320             }
8321             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";
8322             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8323             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8324                 return false;
8325             }
8326             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";
8327             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8328             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8329                 return false;
8330             }
8331             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8332             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8333             if ( ( p32.length != 0 ) ) {
8334                 return false;
8335             }
8336             final String p33_S = "A";
8337             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8338             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8339                 return false;
8340             }
8341             final String p34_S = "B;";
8342             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8343             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8344                 return false;
8345             }
8346             final String p35_S = "B:0.2";
8347             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8348             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8349                 return false;
8350             }
8351             final String p36_S = "(A)";
8352             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8353             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8354                 return false;
8355             }
8356             final String p37_S = "((A))";
8357             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8358             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8359                 return false;
8360             }
8361             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8362             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8363             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8364                 return false;
8365             }
8366             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8367             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8368             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8369                 return false;
8370             }
8371             final String p40_S = "(A,B,C)";
8372             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8373             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8374                 return false;
8375             }
8376             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8377             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8378             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8379                 return false;
8380             }
8381             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8382             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8383             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8384                 return false;
8385             }
8386             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)";
8387             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8388             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8389                 return false;
8390             }
8391             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)))";
8392             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8393             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8394                 return false;
8395             }
8396             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8397             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8398             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8399                 return false;
8400             }
8401             final String p46_S = "";
8402             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8403             if ( p46.length != 0 ) {
8404                 return false;
8405             }
8406             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8407             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8408                 return false;
8409             }
8410             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8411             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8412                 return false;
8413             }
8414             final Phylogeny p49 = factory
8415                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8416                              new NHXParser() )[ 0 ];
8417             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8418                 return false;
8419             }
8420             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8421             if ( p50.getNode( "A" ) == null ) {
8422                 return false;
8423             }
8424             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8425                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8426                 return false;
8427             }
8428             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8429                 return false;
8430             }
8431             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8432                     .equals( "((A,B)88:2.0,C);" ) ) {
8433                 return false;
8434             }
8435             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8436             if ( p51.getNode( "A(A" ) == null ) {
8437                 return false;
8438             }
8439             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8440             if ( p52.getNode( "A(A" ) == null ) {
8441                 return false;
8442             }
8443             final Phylogeny p53 = factory
8444                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8445                              new NHXParser() )[ 0 ];
8446             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8447                 return false;
8448             }
8449             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8450             if ( p54.getNode( "A" ) == null ) {
8451                 return false;
8452             }
8453             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8454                 return false;
8455             }
8456             final Phylogeny p55 = factory
8457                     .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);" ),
8458                              new NHXParser() )[ 0 ];
8459             if ( !p55
8460                     .toNewHampshire()
8461                     .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);" ) ) {
8462                 System.out.println( p55.toNewHampshire() );
8463                 return false;
8464             }
8465             final Phylogeny p56 = factory
8466                     .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);" ),
8467                              new NHXParser() )[ 0 ];
8468             if ( !p56
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.1:x':0.0798012);" ) ) {
8471                 System.out.println( p56.toNewHampshire() );
8472                 return false;
8473             }
8474             final Phylogeny p57 = 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 ( !p57
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 String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8484             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8485             if ( !p58.toNewHampshire().equals( s58 ) ) {
8486                 System.out.println( p58.toNewHampshire() );
8487                 return false;
8488             }
8489             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8490             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8491             if ( !p59.toNewHampshire().equals( s59 ) ) {
8492                 System.out.println( p59.toNewHampshire() );
8493                 return false;
8494             }
8495             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8496             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8497             if ( !p60.toNewHampshire().equals( s60 ) ) {
8498                 System.out.println( p60.toNewHampshire() );
8499                 return false;
8500             }
8501             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8502             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8503             if ( !p61.toNewHampshire()
8504                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8505                 System.out.println( p61.toNewHampshire() );
8506                 return false;
8507             }
8508         }
8509         catch ( final Exception e ) {
8510             e.printStackTrace( System.out );
8511             return false;
8512         }
8513         return true;
8514     }
8515
8516     private static boolean testNHParsingIter() {
8517         try {
8518             final String p0_str = "(A,B);";
8519             final NHXParser p = new NHXParser();
8520             p.setSource( p0_str );
8521             if ( !p.hasNext() ) {
8522                 return false;
8523             }
8524             final Phylogeny p0 = p.next();
8525             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8526                 System.out.println( p0.toNewHampshire() );
8527                 return false;
8528             }
8529             if ( p.hasNext() ) {
8530                 return false;
8531             }
8532             if ( p.next() != null ) {
8533                 return false;
8534             }
8535             //
8536             final String p00_str = "(A,B)root;";
8537             p.setSource( p00_str );
8538             final Phylogeny p00 = p.next();
8539             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8540                 System.out.println( p00.toNewHampshire() );
8541                 return false;
8542             }
8543             //
8544             final String p000_str = "A;";
8545             p.setSource( p000_str );
8546             final Phylogeny p000 = p.next();
8547             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8548                 System.out.println( p000.toNewHampshire() );
8549                 return false;
8550             }
8551             //
8552             final String p0000_str = "A";
8553             p.setSource( p0000_str );
8554             final Phylogeny p0000 = p.next();
8555             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8556                 System.out.println( p0000.toNewHampshire() );
8557                 return false;
8558             }
8559             //
8560             p.setSource( "(A)" );
8561             final Phylogeny p00000 = p.next();
8562             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8563                 System.out.println( p00000.toNewHampshire() );
8564                 return false;
8565             }
8566             //
8567             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8568             p.setSource( p1_str );
8569             if ( !p.hasNext() ) {
8570                 return false;
8571             }
8572             final Phylogeny p1_0 = p.next();
8573             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8574                 System.out.println( p1_0.toNewHampshire() );
8575                 return false;
8576             }
8577             if ( !p.hasNext() ) {
8578                 return false;
8579             }
8580             final Phylogeny p1_1 = p.next();
8581             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8582                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8583                 return false;
8584             }
8585             if ( !p.hasNext() ) {
8586                 return false;
8587             }
8588             final Phylogeny p1_2 = p.next();
8589             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8590                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8591                 return false;
8592             }
8593             if ( !p.hasNext() ) {
8594                 return false;
8595             }
8596             final Phylogeny p1_3 = p.next();
8597             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8598                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8599                 return false;
8600             }
8601             if ( p.hasNext() ) {
8602                 return false;
8603             }
8604             if ( p.next() != null ) {
8605                 return false;
8606             }
8607             //
8608             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8609             p.setSource( p2_str );
8610             if ( !p.hasNext() ) {
8611                 return false;
8612             }
8613             Phylogeny p2_0 = p.next();
8614             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8615                 System.out.println( p2_0.toNewHampshire() );
8616                 return false;
8617             }
8618             if ( !p.hasNext() ) {
8619                 return false;
8620             }
8621             Phylogeny p2_1 = p.next();
8622             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8623                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8624                 return false;
8625             }
8626             if ( !p.hasNext() ) {
8627                 return false;
8628             }
8629             Phylogeny p2_2 = p.next();
8630             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8631                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8632                 return false;
8633             }
8634             if ( !p.hasNext() ) {
8635                 return false;
8636             }
8637             Phylogeny p2_3 = p.next();
8638             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8639                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8640                 return false;
8641             }
8642             if ( !p.hasNext() ) {
8643                 return false;
8644             }
8645             Phylogeny p2_4 = p.next();
8646             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8647                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8648                 return false;
8649             }
8650             if ( p.hasNext() ) {
8651                 return false;
8652             }
8653             if ( p.next() != null ) {
8654                 return false;
8655             }
8656             ////
8657             p.reset();
8658             if ( !p.hasNext() ) {
8659                 return false;
8660             }
8661             p2_0 = p.next();
8662             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8663                 System.out.println( p2_0.toNewHampshire() );
8664                 return false;
8665             }
8666             if ( !p.hasNext() ) {
8667                 return false;
8668             }
8669             p2_1 = p.next();
8670             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8671                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8672                 return false;
8673             }
8674             if ( !p.hasNext() ) {
8675                 return false;
8676             }
8677             p2_2 = p.next();
8678             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8679                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8680                 return false;
8681             }
8682             if ( !p.hasNext() ) {
8683                 return false;
8684             }
8685             p2_3 = p.next();
8686             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8687                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8688                 return false;
8689             }
8690             if ( !p.hasNext() ) {
8691                 return false;
8692             }
8693             p2_4 = p.next();
8694             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8695                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8696                 return false;
8697             }
8698             if ( p.hasNext() ) {
8699                 return false;
8700             }
8701             if ( p.next() != null ) {
8702                 return false;
8703             }
8704             //
8705             final String p3_str = "((A,B),C)abc";
8706             p.setSource( p3_str );
8707             if ( !p.hasNext() ) {
8708                 return false;
8709             }
8710             final Phylogeny p3_0 = p.next();
8711             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8712                 return false;
8713             }
8714             if ( p.hasNext() ) {
8715                 return false;
8716             }
8717             if ( p.next() != null ) {
8718                 return false;
8719             }
8720             //
8721             final String p4_str = "((A,B)ab,C)abc";
8722             p.setSource( p4_str );
8723             if ( !p.hasNext() ) {
8724                 return false;
8725             }
8726             final Phylogeny p4_0 = p.next();
8727             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8728                 return false;
8729             }
8730             if ( p.hasNext() ) {
8731                 return false;
8732             }
8733             if ( p.next() != null ) {
8734                 return false;
8735             }
8736             //
8737             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8738             p.setSource( p5_str );
8739             if ( !p.hasNext() ) {
8740                 return false;
8741             }
8742             final Phylogeny p5_0 = p.next();
8743             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8744                 return false;
8745             }
8746             if ( p.hasNext() ) {
8747                 return false;
8748             }
8749             if ( p.next() != null ) {
8750                 return false;
8751             }
8752             //
8753             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8754             p.setSource( p6_str );
8755             if ( !p.hasNext() ) {
8756                 return false;
8757             }
8758             Phylogeny p6_0 = p.next();
8759             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8760                 return false;
8761             }
8762             if ( p.hasNext() ) {
8763                 return false;
8764             }
8765             if ( p.next() != null ) {
8766                 return false;
8767             }
8768             p.reset();
8769             if ( !p.hasNext() ) {
8770                 return false;
8771             }
8772             p6_0 = p.next();
8773             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8774                 return false;
8775             }
8776             if ( p.hasNext() ) {
8777                 return false;
8778             }
8779             if ( p.next() != null ) {
8780                 return false;
8781             }
8782             //
8783             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8784             p.setSource( p7_str );
8785             if ( !p.hasNext() ) {
8786                 return false;
8787             }
8788             Phylogeny p7_0 = p.next();
8789             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8790                 return false;
8791             }
8792             if ( p.hasNext() ) {
8793                 return false;
8794             }
8795             if ( p.next() != null ) {
8796                 return false;
8797             }
8798             p.reset();
8799             if ( !p.hasNext() ) {
8800                 return false;
8801             }
8802             p7_0 = p.next();
8803             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8804                 return false;
8805             }
8806             if ( p.hasNext() ) {
8807                 return false;
8808             }
8809             if ( p.next() != null ) {
8810                 return false;
8811             }
8812             //
8813             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8814             p.setSource( p8_str );
8815             if ( !p.hasNext() ) {
8816                 return false;
8817             }
8818             Phylogeny p8_0 = p.next();
8819             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8820                 return false;
8821             }
8822             if ( !p.hasNext() ) {
8823                 return false;
8824             }
8825             if ( !p.hasNext() ) {
8826                 return false;
8827             }
8828             Phylogeny p8_1 = p.next();
8829             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8830                 return false;
8831             }
8832             if ( p.hasNext() ) {
8833                 return false;
8834             }
8835             if ( p.next() != null ) {
8836                 return false;
8837             }
8838             p.reset();
8839             if ( !p.hasNext() ) {
8840                 return false;
8841             }
8842             p8_0 = p.next();
8843             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8844                 return false;
8845             }
8846             if ( !p.hasNext() ) {
8847                 return false;
8848             }
8849             p8_1 = p.next();
8850             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8851                 return false;
8852             }
8853             if ( p.hasNext() ) {
8854                 return false;
8855             }
8856             if ( p.next() != null ) {
8857                 return false;
8858             }
8859             p.reset();
8860             //
8861             p.setSource( "" );
8862             if ( p.hasNext() ) {
8863                 return false;
8864             }
8865             //
8866             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8867             if ( !p.hasNext() ) {
8868                 return false;
8869             }
8870             Phylogeny p_27 = p.next();
8871             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8872                 System.out.println( p_27.toNewHampshireX() );
8873                 System.exit( -1 );
8874                 return false;
8875             }
8876             if ( p.hasNext() ) {
8877                 return false;
8878             }
8879             if ( p.next() != null ) {
8880                 return false;
8881             }
8882             p.reset();
8883             if ( !p.hasNext() ) {
8884                 return false;
8885             }
8886             p_27 = p.next();
8887             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8888                 System.out.println( p_27.toNewHampshireX() );
8889                 System.exit( -1 );
8890                 return false;
8891             }
8892             if ( p.hasNext() ) {
8893                 return false;
8894             }
8895             if ( p.next() != null ) {
8896                 return false;
8897             }
8898             //
8899             final String p30_str = "(A,B);(C,D)";
8900             final NHXParser p30 = new NHXParser();
8901             p30.setSource( p30_str );
8902             if ( !p30.hasNext() ) {
8903                 return false;
8904             }
8905             Phylogeny phy30 = p30.next();
8906             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8907                 System.out.println( phy30.toNewHampshire() );
8908                 return false;
8909             }
8910             if ( !p30.hasNext() ) {
8911                 return false;
8912             }
8913             Phylogeny phy301 = p30.next();
8914             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8915                 System.out.println( phy301.toNewHampshire() );
8916                 return false;
8917             }
8918             if ( p30.hasNext() ) {
8919                 return false;
8920             }
8921             if ( p30.hasNext() ) {
8922                 return false;
8923             }
8924             if ( p30.next() != null ) {
8925                 return false;
8926             }
8927             if ( p30.next() != null ) {
8928                 return false;
8929             }
8930             p30.reset();
8931             if ( !p30.hasNext() ) {
8932                 return false;
8933             }
8934             phy30 = p30.next();
8935             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8936                 System.out.println( phy30.toNewHampshire() );
8937                 return false;
8938             }
8939             if ( !p30.hasNext() ) {
8940                 return false;
8941             }
8942             phy301 = p30.next();
8943             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8944                 System.out.println( phy301.toNewHampshire() );
8945                 return false;
8946             }
8947             if ( p30.hasNext() ) {
8948                 return false;
8949             }
8950             if ( p30.hasNext() ) {
8951                 return false;
8952             }
8953             if ( p30.next() != null ) {
8954                 return false;
8955             }
8956             if ( p30.next() != null ) {
8957                 return false;
8958             }
8959         }
8960         catch ( final Exception e ) {
8961             e.printStackTrace( System.out );
8962             return false;
8963         }
8964         return true;
8965     }
8966
8967     private static boolean testNHXconversion() {
8968         try {
8969             final PhylogenyNode n1 = new PhylogenyNode();
8970             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8971             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8972             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8973             final PhylogenyNode n5 = PhylogenyNode
8974                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8975             final PhylogenyNode n6 = PhylogenyNode
8976                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8977             if ( !n1.toNewHampshireX().equals( "" ) ) {
8978                 return false;
8979             }
8980             if ( !n2.toNewHampshireX().equals( "" ) ) {
8981                 return false;
8982             }
8983             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8984                 return false;
8985             }
8986             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8987                 return false;
8988             }
8989             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8990                 return false;
8991             }
8992             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8993                 System.out.println( n6.toNewHampshireX() );
8994                 return false;
8995             }
8996             final PhylogenyNode n7 = new PhylogenyNode();
8997             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8998             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8999                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9000                 System.out.println( n7
9001                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9002                 return false;
9003             }
9004         }
9005         catch ( final Exception e ) {
9006             e.printStackTrace( System.out );
9007             return false;
9008         }
9009         return true;
9010     }
9011
9012     private static boolean testNHXNodeParsing() {
9013         try {
9014             final PhylogenyNode n1 = new PhylogenyNode();
9015             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9016             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9017             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9018             final PhylogenyNode n5 = PhylogenyNode
9019                     .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]" );
9020             if ( !n3.getName().equals( "n3" ) ) {
9021                 return false;
9022             }
9023             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9024                 return false;
9025             }
9026             if ( n3.isDuplication() ) {
9027                 return false;
9028             }
9029             if ( n3.isHasAssignedEvent() ) {
9030                 return false;
9031             }
9032             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9033                 return false;
9034             }
9035             if ( !n4.getName().equals( "n4" ) ) {
9036                 return false;
9037             }
9038             if ( n4.getDistanceToParent() != 0.01 ) {
9039                 return false;
9040             }
9041             if ( !n5.getName().equals( "n5" ) ) {
9042                 return false;
9043             }
9044             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9045                 return false;
9046             }
9047             if ( n5.getDistanceToParent() != 0.1 ) {
9048                 return false;
9049             }
9050             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9051                 return false;
9052             }
9053             if ( !n5.isDuplication() ) {
9054                 return false;
9055             }
9056             if ( !n5.isHasAssignedEvent() ) {
9057                 return false;
9058             }
9059             final PhylogenyNode n8 = PhylogenyNode
9060                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9061                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9062             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9063                 return false;
9064             }
9065             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9066                 return false;
9067             }
9068             final PhylogenyNode n9 = PhylogenyNode
9069                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9070                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9071             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9072                 return false;
9073             }
9074             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9075                 return false;
9076             }
9077             final PhylogenyNode n10 = PhylogenyNode
9078                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9079             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9080                 return false;
9081             }
9082             final PhylogenyNode n20 = PhylogenyNode
9083                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9084             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9085                 return false;
9086             }
9087             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9088                 return false;
9089             }
9090             final PhylogenyNode n20x = PhylogenyNode
9091                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9092             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9093                 return false;
9094             }
9095             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9096                 return false;
9097             }
9098             final PhylogenyNode n20xx = PhylogenyNode
9099                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9100             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9101                 return false;
9102             }
9103             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9104                 return false;
9105             }
9106             final PhylogenyNode n20xxx = PhylogenyNode
9107                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9108             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9109                 return false;
9110             }
9111             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9112                 return false;
9113             }
9114             final PhylogenyNode n20xxxx = PhylogenyNode
9115                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9116             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9117                 return false;
9118             }
9119             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9120                 return false;
9121             }
9122             final PhylogenyNode n21 = PhylogenyNode
9123                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9124             if ( !n21.getName().equals( "N21_PIG" ) ) {
9125                 return false;
9126             }
9127             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9128                 return false;
9129             }
9130             final PhylogenyNode n21x = PhylogenyNode
9131                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9132             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9133                 return false;
9134             }
9135             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9136                 return false;
9137             }
9138             final PhylogenyNode n22 = PhylogenyNode
9139                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9140             if ( !n22.getName().equals( "n22/PIG" ) ) {
9141                 return false;
9142             }
9143             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9144                 return false;
9145             }
9146             final PhylogenyNode n23 = PhylogenyNode
9147                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9148             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9149                 return false;
9150             }
9151             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9152                 return false;
9153             }
9154             final PhylogenyNode a = PhylogenyNode
9155                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9156             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9157                 return false;
9158             }
9159             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9160                 return false;
9161             }
9162             final PhylogenyNode c1 = PhylogenyNode
9163                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9164                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9165             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9166                 return false;
9167             }
9168             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9169                 return false;
9170             }
9171             final PhylogenyNode c2 = PhylogenyNode
9172                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9173                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9174             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9175                 return false;
9176             }
9177             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9178                 return false;
9179             }
9180             final PhylogenyNode e3 = PhylogenyNode
9181                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9182             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9183                 return false;
9184             }
9185             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9186                 return false;
9187             }
9188             final PhylogenyNode n11 = PhylogenyNode
9189                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9190                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9191             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9192                 return false;
9193             }
9194             if ( n11.getDistanceToParent() != 0.4 ) {
9195                 return false;
9196             }
9197             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9198                 return false;
9199             }
9200             final PhylogenyNode n12 = PhylogenyNode
9201                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9202                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9203             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9204                 return false;
9205             }
9206             if ( n12.getDistanceToParent() != 0.4 ) {
9207                 return false;
9208             }
9209             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9210                 return false;
9211             }
9212             final PhylogenyNode o = PhylogenyNode
9213                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9214             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9215                 return false;
9216             }
9217             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9218                 return false;
9219             }
9220             if ( n1.getName().compareTo( "" ) != 0 ) {
9221                 return false;
9222             }
9223             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9224                 return false;
9225             }
9226             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9227                 return false;
9228             }
9229             if ( n2.getName().compareTo( "" ) != 0 ) {
9230                 return false;
9231             }
9232             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9233                 return false;
9234             }
9235             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9236                 return false;
9237             }
9238             final PhylogenyNode n00 = PhylogenyNode
9239                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9240             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9241                 return false;
9242             }
9243             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9244                 return false;
9245             }
9246             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9247             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9248                 return false;
9249             }
9250             final PhylogenyNode n13 = PhylogenyNode
9251                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9252             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9253                 return false;
9254             }
9255             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9256                 return false;
9257             }
9258             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9259                 return false;
9260             }
9261             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9262                 return false;
9263             }
9264             final PhylogenyNode n14 = PhylogenyNode
9265                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9266             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9267                 return false;
9268             }
9269             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9270                 return false;
9271             }
9272             final PhylogenyNode n15 = PhylogenyNode
9273                     .createInstanceFromNhxString( "something_wicked[123]",
9274                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9275             if ( !n15.getName().equals( "something_wicked" ) ) {
9276                 return false;
9277             }
9278             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9279                 return false;
9280             }
9281             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9282                 return false;
9283             }
9284             final PhylogenyNode n16 = PhylogenyNode
9285                     .createInstanceFromNhxString( "something_wicked2[9]",
9286                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9287             if ( !n16.getName().equals( "something_wicked2" ) ) {
9288                 return false;
9289             }
9290             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9291                 return false;
9292             }
9293             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9294                 return false;
9295             }
9296             final PhylogenyNode n17 = PhylogenyNode
9297                     .createInstanceFromNhxString( "something_wicked3[a]",
9298                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9299             if ( !n17.getName().equals( "something_wicked3" ) ) {
9300                 return false;
9301             }
9302             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9303                 return false;
9304             }
9305             final PhylogenyNode n18 = PhylogenyNode
9306                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9307             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9308                 return false;
9309             }
9310             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9311                 return false;
9312             }
9313             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9314                 return false;
9315             }
9316             final PhylogenyNode n19 = PhylogenyNode
9317                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9318             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9319                 return false;
9320             }
9321             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9322                 return false;
9323             }
9324             final PhylogenyNode n30 = PhylogenyNode
9325                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9326                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9327             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9328                 return false;
9329             }
9330             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9331                 return false;
9332             }
9333             final PhylogenyNode n31 = PhylogenyNode
9334                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9335                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9336             if ( n31.getNodeData().isHasTaxonomy() ) {
9337                 return false;
9338             }
9339             final PhylogenyNode n32 = PhylogenyNode
9340                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9341             if ( n32.getNodeData().isHasTaxonomy() ) {
9342                 return false;
9343             }
9344             final PhylogenyNode n40 = PhylogenyNode
9345                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9346             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9347                 return false;
9348             }
9349             final PhylogenyNode n41 = PhylogenyNode
9350                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9351             if ( n41.getNodeData().isHasTaxonomy() ) {
9352                 return false;
9353             }
9354             final PhylogenyNode n42 = PhylogenyNode
9355                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9356             if ( n42.getNodeData().isHasTaxonomy() ) {
9357                 return false;
9358             }
9359             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9360                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9361             if ( n43.getNodeData().isHasTaxonomy() ) {
9362                 return false;
9363             }
9364             final PhylogenyNode n44 = PhylogenyNode
9365                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9366             if ( n44.getNodeData().isHasTaxonomy() ) {
9367                 return false;
9368             }
9369         }
9370         catch ( final Exception e ) {
9371             e.printStackTrace( System.out );
9372             return false;
9373         }
9374         return true;
9375     }
9376
9377     private static boolean testNHXParsing() {
9378         try {
9379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9380             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9381             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9382                 return false;
9383             }
9384             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]";
9385             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9386             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9387                 return false;
9388             }
9389             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]";
9390             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9391             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9392                 return false;
9393             }
9394             final Phylogeny[] p3 = factory
9395                     .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]",
9396                              new NHXParser() );
9397             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9398                 return false;
9399             }
9400             final Phylogeny[] p4 = factory
9401                     .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(]",
9402                              new NHXParser() );
9403             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9404                 return false;
9405             }
9406             final Phylogeny[] p5 = factory
9407                     .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(((]",
9408                              new NHXParser() );
9409             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9410                 return false;
9411             }
9412             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)";
9413             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)";
9414             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9415             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9416                 return false;
9417             }
9418             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)))";
9419             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)))";
9420             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9421             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9422                 return false;
9423             }
9424             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])   ))[,,, ])))))))";
9425             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9426             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9427             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9428                 return false;
9429             }
9430             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9431             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9432                 return false;
9433             }
9434             final Phylogeny p10 = factory
9435                     .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]",
9436                              new NHXParser() )[ 0 ];
9437             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9438                 return false;
9439             }
9440             final Phylogeny p11 = factory
9441                     .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]",
9442                              new NHXParser() )[ 0 ];
9443             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9444                 return false;
9445             }
9446         }
9447         catch ( final Exception e ) {
9448             e.printStackTrace( System.out );
9449             return false;
9450         }
9451         return true;
9452     }
9453
9454     private static boolean testNHXParsingMB() {
9455         try {
9456             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9457             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9458                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9459                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9460                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9461                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9462                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9463                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9464                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9465                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9466             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9467                 return false;
9468             }
9469             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9470                 return false;
9471             }
9472             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9473                            0.1100000000000000e+00 ) ) {
9474                 return false;
9475             }
9476             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9477                 return false;
9478             }
9479             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9480                 return false;
9481             }
9482             final Phylogeny p2 = factory
9483                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9484                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9485                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9486                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9487                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9488                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9489                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9490                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9491                                      + "7.369400000000000e-02}])",
9492                              new NHXParser() )[ 0 ];
9493             if ( p2.getNode( "1" ) == null ) {
9494                 return false;
9495             }
9496             if ( p2.getNode( "2" ) == null ) {
9497                 return false;
9498             }
9499         }
9500         catch ( final Exception e ) {
9501             e.printStackTrace( System.out );
9502             System.exit( -1 );
9503             return false;
9504         }
9505         return true;
9506     }
9507
9508     private static boolean testNHXParsingQuotes() {
9509         try {
9510             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9511             final NHXParser p = new NHXParser();
9512             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9513             if ( phylogenies_0.length != 5 ) {
9514                 return false;
9515             }
9516             final Phylogeny phy = phylogenies_0[ 4 ];
9517             if ( phy.getNumberOfExternalNodes() != 7 ) {
9518                 return false;
9519             }
9520             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9521                 return false;
9522             }
9523             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9524                 return false;
9525             }
9526             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9527                     .getScientificName().equals( "hsapiens" ) ) {
9528                 return false;
9529             }
9530             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9531                 return false;
9532             }
9533             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9534                 return false;
9535             }
9536             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9537                 return false;
9538             }
9539             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9540                 return false;
9541             }
9542             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9543                 return false;
9544             }
9545             final NHXParser p1p = new NHXParser();
9546             p1p.setIgnoreQuotes( true );
9547             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9548             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9549                 return false;
9550             }
9551             final NHXParser p2p = new NHXParser();
9552             p1p.setIgnoreQuotes( false );
9553             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9554             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9555                 return false;
9556             }
9557             final NHXParser p3p = new NHXParser();
9558             p3p.setIgnoreQuotes( false );
9559             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9560             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9561                 return false;
9562             }
9563             final NHXParser p4p = new NHXParser();
9564             p4p.setIgnoreQuotes( false );
9565             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9566             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9567                 return false;
9568             }
9569             final Phylogeny p10 = factory
9570                     .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]",
9571                              new NHXParser() )[ 0 ];
9572             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]";
9573             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9574                 return false;
9575             }
9576             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9577             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9578                 return false;
9579             }
9580             final Phylogeny p12 = factory
9581                     .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]",
9582                              new NHXParser() )[ 0 ];
9583             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]";
9584             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9585                 return false;
9586             }
9587             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9588             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9589                 return false;
9590             }
9591             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;";
9592             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9593                 return false;
9594             }
9595             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9596             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9597                 return false;
9598             }
9599         }
9600         catch ( final Exception e ) {
9601             e.printStackTrace( System.out );
9602             return false;
9603         }
9604         return true;
9605     }
9606
9607     private static boolean testNodeRemoval() {
9608         try {
9609             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9610             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9611             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9612             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9613                 return false;
9614             }
9615             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9616             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9617             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9618                 return false;
9619             }
9620             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9621             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9622             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9623                 return false;
9624             }
9625         }
9626         catch ( final Exception e ) {
9627             e.printStackTrace( System.out );
9628             return false;
9629         }
9630         return true;
9631     }
9632
9633     private static boolean testPhylogenyBranch() {
9634         try {
9635             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9636             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9637             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9638             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9639             if ( !a1b1.equals( a1b1 ) ) {
9640                 return false;
9641             }
9642             if ( !a1b1.equals( b1a1 ) ) {
9643                 return false;
9644             }
9645             if ( !b1a1.equals( a1b1 ) ) {
9646                 return false;
9647             }
9648             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9649             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9650             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9651             if ( a1_b1.equals( b1_a1 ) ) {
9652                 return false;
9653             }
9654             if ( a1_b1.equals( a1_b1_ ) ) {
9655                 return false;
9656             }
9657             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9658             if ( !a1_b1.equals( b1_a1_ ) ) {
9659                 return false;
9660             }
9661             if ( a1_b1_.equals( b1_a1_ ) ) {
9662                 return false;
9663             }
9664             if ( !a1_b1_.equals( b1_a1 ) ) {
9665                 return false;
9666             }
9667         }
9668         catch ( final Exception e ) {
9669             e.printStackTrace( System.out );
9670             return false;
9671         }
9672         return true;
9673     }
9674
9675     private static boolean testPhyloXMLparsingOfDistributionElement() {
9676         try {
9677             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9678             PhyloXmlParser xml_parser = null;
9679             try {
9680                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9681             }
9682             catch ( final Exception e ) {
9683                 // Do nothing -- means were not running from jar.
9684             }
9685             if ( xml_parser == null ) {
9686                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9687                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9688                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9689                 }
9690                 else {
9691                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9692                 }
9693             }
9694             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9695                                                               xml_parser );
9696             if ( xml_parser.getErrorCount() > 0 ) {
9697                 System.out.println( xml_parser.getErrorMessages().toString() );
9698                 return false;
9699             }
9700             if ( phylogenies_0.length != 1 ) {
9701                 return false;
9702             }
9703             final Phylogeny t1 = phylogenies_0[ 0 ];
9704             PhylogenyNode n = null;
9705             Distribution d = null;
9706             n = t1.getNode( "root node" );
9707             if ( !n.getNodeData().isHasDistribution() ) {
9708                 return false;
9709             }
9710             if ( n.getNodeData().getDistributions().size() != 1 ) {
9711                 return false;
9712             }
9713             d = n.getNodeData().getDistribution();
9714             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9715                 return false;
9716             }
9717             if ( d.getPoints().size() != 1 ) {
9718                 return false;
9719             }
9720             if ( d.getPolygons() != null ) {
9721                 return false;
9722             }
9723             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9724                 return false;
9725             }
9726             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9727                 return false;
9728             }
9729             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9730                 return false;
9731             }
9732             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9733                 return false;
9734             }
9735             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9736                 return false;
9737             }
9738             n = t1.getNode( "node a" );
9739             if ( !n.getNodeData().isHasDistribution() ) {
9740                 return false;
9741             }
9742             if ( n.getNodeData().getDistributions().size() != 2 ) {
9743                 return false;
9744             }
9745             d = n.getNodeData().getDistribution( 1 );
9746             if ( !d.getDesc().equals( "San Diego" ) ) {
9747                 return false;
9748             }
9749             if ( d.getPoints().size() != 1 ) {
9750                 return false;
9751             }
9752             if ( d.getPolygons() != null ) {
9753                 return false;
9754             }
9755             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9756                 return false;
9757             }
9758             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9759                 return false;
9760             }
9761             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9762                 return false;
9763             }
9764             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9765                 return false;
9766             }
9767             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9768                 return false;
9769             }
9770             n = t1.getNode( "node bb" );
9771             if ( !n.getNodeData().isHasDistribution() ) {
9772                 return false;
9773             }
9774             if ( n.getNodeData().getDistributions().size() != 1 ) {
9775                 return false;
9776             }
9777             d = n.getNodeData().getDistribution( 0 );
9778             if ( d.getPoints().size() != 3 ) {
9779                 return false;
9780             }
9781             if ( d.getPolygons().size() != 2 ) {
9782                 return false;
9783             }
9784             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9785                 return false;
9786             }
9787             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9788                 return false;
9789             }
9790             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9797                 return false;
9798             }
9799             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9800                 return false;
9801             }
9802             Polygon p = d.getPolygons().get( 0 );
9803             if ( p.getPoints().size() != 3 ) {
9804                 return false;
9805             }
9806             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9807                 return false;
9808             }
9809             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9810                 return false;
9811             }
9812             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9813                 return false;
9814             }
9815             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9816                 return false;
9817             }
9818             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9819                 return false;
9820             }
9821             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9822                 return false;
9823             }
9824             p = d.getPolygons().get( 1 );
9825             if ( p.getPoints().size() != 3 ) {
9826                 return false;
9827             }
9828             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9829                 return false;
9830             }
9831             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9832                 return false;
9833             }
9834             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9835                 return false;
9836             }
9837             // Roundtrip:
9838             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9839             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9840             if ( rt.length != 1 ) {
9841                 return false;
9842             }
9843             final Phylogeny t1_rt = rt[ 0 ];
9844             n = t1_rt.getNode( "root node" );
9845             if ( !n.getNodeData().isHasDistribution() ) {
9846                 return false;
9847             }
9848             if ( n.getNodeData().getDistributions().size() != 1 ) {
9849                 return false;
9850             }
9851             d = n.getNodeData().getDistribution();
9852             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9853                 return false;
9854             }
9855             if ( d.getPoints().size() != 1 ) {
9856                 return false;
9857             }
9858             if ( d.getPolygons() != null ) {
9859                 return false;
9860             }
9861             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9862                 return false;
9863             }
9864             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9865                 return false;
9866             }
9867             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9868                 return false;
9869             }
9870             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9871                 return false;
9872             }
9873             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9874                 return false;
9875             }
9876             n = t1_rt.getNode( "node a" );
9877             if ( !n.getNodeData().isHasDistribution() ) {
9878                 return false;
9879             }
9880             if ( n.getNodeData().getDistributions().size() != 2 ) {
9881                 return false;
9882             }
9883             d = n.getNodeData().getDistribution( 1 );
9884             if ( !d.getDesc().equals( "San Diego" ) ) {
9885                 return false;
9886             }
9887             if ( d.getPoints().size() != 1 ) {
9888                 return false;
9889             }
9890             if ( d.getPolygons() != null ) {
9891                 return false;
9892             }
9893             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9894                 return false;
9895             }
9896             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9897                 return false;
9898             }
9899             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9900                 return false;
9901             }
9902             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9903                 return false;
9904             }
9905             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9906                 return false;
9907             }
9908             n = t1_rt.getNode( "node bb" );
9909             if ( !n.getNodeData().isHasDistribution() ) {
9910                 return false;
9911             }
9912             if ( n.getNodeData().getDistributions().size() != 1 ) {
9913                 return false;
9914             }
9915             d = n.getNodeData().getDistribution( 0 );
9916             if ( d.getPoints().size() != 3 ) {
9917                 return false;
9918             }
9919             if ( d.getPolygons().size() != 2 ) {
9920                 return false;
9921             }
9922             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9923                 return false;
9924             }
9925             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9926                 return false;
9927             }
9928             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9929                 return false;
9930             }
9931             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9935                 return false;
9936             }
9937             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9938                 return false;
9939             }
9940             p = d.getPolygons().get( 0 );
9941             if ( p.getPoints().size() != 3 ) {
9942                 return false;
9943             }
9944             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9945                 return false;
9946             }
9947             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9948                 return false;
9949             }
9950             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9951                 return false;
9952             }
9953             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9954                 return false;
9955             }
9956             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9957                 return false;
9958             }
9959             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9960                 return false;
9961             }
9962             p = d.getPolygons().get( 1 );
9963             if ( p.getPoints().size() != 3 ) {
9964                 return false;
9965             }
9966             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9967                 return false;
9968             }
9969             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9970                 return false;
9971             }
9972             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9973                 return false;
9974             }
9975         }
9976         catch ( final Exception e ) {
9977             e.printStackTrace( System.out );
9978             return false;
9979         }
9980         return true;
9981     }
9982
9983     private static boolean testPostOrderIterator() {
9984         try {
9985             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9986             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9987             PhylogenyNodeIterator it0;
9988             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9989                 it0.next();
9990             }
9991             for( it0.reset(); it0.hasNext(); ) {
9992                 it0.next();
9993             }
9994             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9995             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9996             if ( !it.next().getName().equals( "A" ) ) {
9997                 return false;
9998             }
9999             if ( !it.next().getName().equals( "B" ) ) {
10000                 return false;
10001             }
10002             if ( !it.next().getName().equals( "ab" ) ) {
10003                 return false;
10004             }
10005             if ( !it.next().getName().equals( "C" ) ) {
10006                 return false;
10007             }
10008             if ( !it.next().getName().equals( "D" ) ) {
10009                 return false;
10010             }
10011             if ( !it.next().getName().equals( "cd" ) ) {
10012                 return false;
10013             }
10014             if ( !it.next().getName().equals( "abcd" ) ) {
10015                 return false;
10016             }
10017             if ( !it.next().getName().equals( "E" ) ) {
10018                 return false;
10019             }
10020             if ( !it.next().getName().equals( "F" ) ) {
10021                 return false;
10022             }
10023             if ( !it.next().getName().equals( "ef" ) ) {
10024                 return false;
10025             }
10026             if ( !it.next().getName().equals( "G" ) ) {
10027                 return false;
10028             }
10029             if ( !it.next().getName().equals( "H" ) ) {
10030                 return false;
10031             }
10032             if ( !it.next().getName().equals( "gh" ) ) {
10033                 return false;
10034             }
10035             if ( !it.next().getName().equals( "efgh" ) ) {
10036                 return false;
10037             }
10038             if ( !it.next().getName().equals( "r" ) ) {
10039                 return false;
10040             }
10041             if ( it.hasNext() ) {
10042                 return false;
10043             }
10044         }
10045         catch ( final Exception e ) {
10046             e.printStackTrace( System.out );
10047             return false;
10048         }
10049         return true;
10050     }
10051
10052     private static boolean testPreOrderIterator() {
10053         try {
10054             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10055             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10056             PhylogenyNodeIterator it0;
10057             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10058                 it0.next();
10059             }
10060             for( it0.reset(); it0.hasNext(); ) {
10061                 it0.next();
10062             }
10063             PhylogenyNodeIterator it = t0.iteratorPreorder();
10064             if ( !it.next().getName().equals( "r" ) ) {
10065                 return false;
10066             }
10067             if ( !it.next().getName().equals( "ab" ) ) {
10068                 return false;
10069             }
10070             if ( !it.next().getName().equals( "A" ) ) {
10071                 return false;
10072             }
10073             if ( !it.next().getName().equals( "B" ) ) {
10074                 return false;
10075             }
10076             if ( !it.next().getName().equals( "cd" ) ) {
10077                 return false;
10078             }
10079             if ( !it.next().getName().equals( "C" ) ) {
10080                 return false;
10081             }
10082             if ( !it.next().getName().equals( "D" ) ) {
10083                 return false;
10084             }
10085             if ( it.hasNext() ) {
10086                 return false;
10087             }
10088             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10089             it = t1.iteratorPreorder();
10090             if ( !it.next().getName().equals( "r" ) ) {
10091                 return false;
10092             }
10093             if ( !it.next().getName().equals( "abcd" ) ) {
10094                 return false;
10095             }
10096             if ( !it.next().getName().equals( "ab" ) ) {
10097                 return false;
10098             }
10099             if ( !it.next().getName().equals( "A" ) ) {
10100                 return false;
10101             }
10102             if ( !it.next().getName().equals( "B" ) ) {
10103                 return false;
10104             }
10105             if ( !it.next().getName().equals( "cd" ) ) {
10106                 return false;
10107             }
10108             if ( !it.next().getName().equals( "C" ) ) {
10109                 return false;
10110             }
10111             if ( !it.next().getName().equals( "D" ) ) {
10112                 return false;
10113             }
10114             if ( !it.next().getName().equals( "efgh" ) ) {
10115                 return false;
10116             }
10117             if ( !it.next().getName().equals( "ef" ) ) {
10118                 return false;
10119             }
10120             if ( !it.next().getName().equals( "E" ) ) {
10121                 return false;
10122             }
10123             if ( !it.next().getName().equals( "F" ) ) {
10124                 return false;
10125             }
10126             if ( !it.next().getName().equals( "gh" ) ) {
10127                 return false;
10128             }
10129             if ( !it.next().getName().equals( "G" ) ) {
10130                 return false;
10131             }
10132             if ( !it.next().getName().equals( "H" ) ) {
10133                 return false;
10134             }
10135             if ( it.hasNext() ) {
10136                 return false;
10137             }
10138         }
10139         catch ( final Exception e ) {
10140             e.printStackTrace( System.out );
10141             return false;
10142         }
10143         return true;
10144     }
10145
10146     private static boolean testPropertiesMap() {
10147         try {
10148             final PropertiesMap pm = new PropertiesMap();
10149             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10150             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10151             final Property p2 = new Property( "something:else",
10152                                               "?",
10153                                               "improbable:research",
10154                                               "xsd:decimal",
10155                                               AppliesTo.NODE );
10156             pm.addProperty( p0 );
10157             pm.addProperty( p1 );
10158             pm.addProperty( p2 );
10159             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10160                 return false;
10161             }
10162             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10163                 return false;
10164             }
10165             if ( pm.getProperties().size() != 3 ) {
10166                 return false;
10167             }
10168             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10169                 return false;
10170             }
10171             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10172                 return false;
10173             }
10174             if ( pm.getProperties().size() != 3 ) {
10175                 return false;
10176             }
10177             pm.removeProperty( "dimensions:diameter" );
10178             if ( pm.getProperties().size() != 2 ) {
10179                 return false;
10180             }
10181             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10182                 return false;
10183             }
10184             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10185                 return false;
10186             }
10187         }
10188         catch ( final Exception e ) {
10189             e.printStackTrace( System.out );
10190             return false;
10191         }
10192         return true;
10193     }
10194
10195     private static boolean testProteinId() {
10196         try {
10197             final ProteinId id1 = new ProteinId( "a" );
10198             final ProteinId id2 = new ProteinId( "a" );
10199             final ProteinId id3 = new ProteinId( "A" );
10200             final ProteinId id4 = new ProteinId( "b" );
10201             if ( !id1.equals( id1 ) ) {
10202                 return false;
10203             }
10204             if ( id1.getId().equals( "x" ) ) {
10205                 return false;
10206             }
10207             if ( id1.getId().equals( null ) ) {
10208                 return false;
10209             }
10210             if ( !id1.equals( id2 ) ) {
10211                 return false;
10212             }
10213             if ( id1.equals( id3 ) ) {
10214                 return false;
10215             }
10216             if ( id1.hashCode() != id1.hashCode() ) {
10217                 return false;
10218             }
10219             if ( id1.hashCode() != id2.hashCode() ) {
10220                 return false;
10221             }
10222             if ( id1.hashCode() == id3.hashCode() ) {
10223                 return false;
10224             }
10225             if ( id1.compareTo( id1 ) != 0 ) {
10226                 return false;
10227             }
10228             if ( id1.compareTo( id2 ) != 0 ) {
10229                 return false;
10230             }
10231             if ( id1.compareTo( id3 ) != 0 ) {
10232                 return false;
10233             }
10234             if ( id1.compareTo( id4 ) >= 0 ) {
10235                 return false;
10236             }
10237             if ( id4.compareTo( id1 ) <= 0 ) {
10238                 return false;
10239             }
10240             if ( !id4.getId().equals( "b" ) ) {
10241                 return false;
10242             }
10243             final ProteinId id5 = new ProteinId( " C " );
10244             if ( !id5.getId().equals( "C" ) ) {
10245                 return false;
10246             }
10247             if ( id5.equals( id1 ) ) {
10248                 return false;
10249             }
10250         }
10251         catch ( final Exception e ) {
10252             e.printStackTrace( System.out );
10253             return false;
10254         }
10255         return true;
10256     }
10257
10258     private static boolean testReIdMethods() {
10259         try {
10260             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10261             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10262             final long count = PhylogenyNode.getNodeCount();
10263             p.levelOrderReID();
10264             if ( p.getNode( "r" ).getId() != count ) {
10265                 return false;
10266             }
10267             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10268                 return false;
10269             }
10270             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10271                 return false;
10272             }
10273             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10274                 return false;
10275             }
10276             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10277                 return false;
10278             }
10279             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10280                 return false;
10281             }
10282             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10283                 return false;
10284             }
10285             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10286                 return false;
10287             }
10288             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10289                 return false;
10290             }
10291             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10292                 return false;
10293             }
10294             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10295                 return false;
10296             }
10297             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10298                 return false;
10299             }
10300             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10301                 return false;
10302             }
10303             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10304                 return false;
10305             }
10306             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10307                 return false;
10308             }
10309         }
10310         catch ( final Exception e ) {
10311             e.printStackTrace( System.out );
10312             return false;
10313         }
10314         return true;
10315     }
10316
10317     private static boolean testRerooting() {
10318         try {
10319             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10320             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",
10321                                                  new NHXParser() )[ 0 ];
10322             if ( !t1.isRooted() ) {
10323                 return false;
10324             }
10325             t1.reRoot( t1.getNode( "D" ) );
10326             t1.reRoot( t1.getNode( "CD" ) );
10327             t1.reRoot( t1.getNode( "A" ) );
10328             t1.reRoot( t1.getNode( "B" ) );
10329             t1.reRoot( t1.getNode( "AB" ) );
10330             t1.reRoot( t1.getNode( "D" ) );
10331             t1.reRoot( t1.getNode( "C" ) );
10332             t1.reRoot( t1.getNode( "CD" ) );
10333             t1.reRoot( t1.getNode( "A" ) );
10334             t1.reRoot( t1.getNode( "B" ) );
10335             t1.reRoot( t1.getNode( "AB" ) );
10336             t1.reRoot( t1.getNode( "D" ) );
10337             t1.reRoot( t1.getNode( "D" ) );
10338             t1.reRoot( t1.getNode( "C" ) );
10339             t1.reRoot( t1.getNode( "A" ) );
10340             t1.reRoot( t1.getNode( "B" ) );
10341             t1.reRoot( t1.getNode( "AB" ) );
10342             t1.reRoot( t1.getNode( "C" ) );
10343             t1.reRoot( t1.getNode( "D" ) );
10344             t1.reRoot( t1.getNode( "CD" ) );
10345             t1.reRoot( t1.getNode( "D" ) );
10346             t1.reRoot( t1.getNode( "A" ) );
10347             t1.reRoot( t1.getNode( "B" ) );
10348             t1.reRoot( t1.getNode( "AB" ) );
10349             t1.reRoot( t1.getNode( "C" ) );
10350             t1.reRoot( t1.getNode( "D" ) );
10351             t1.reRoot( t1.getNode( "CD" ) );
10352             t1.reRoot( t1.getNode( "D" ) );
10353             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10354                 return false;
10355             }
10356             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10357                 return false;
10358             }
10359             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10360                 return false;
10361             }
10362             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10363                 return false;
10364             }
10365             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10366                 return false;
10367             }
10368             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10369                 return false;
10370             }
10371             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",
10372                                                  new NHXParser() )[ 0 ];
10373             t2.reRoot( t2.getNode( "A" ) );
10374             t2.reRoot( t2.getNode( "D" ) );
10375             t2.reRoot( t2.getNode( "ABC" ) );
10376             t2.reRoot( t2.getNode( "A" ) );
10377             t2.reRoot( t2.getNode( "B" ) );
10378             t2.reRoot( t2.getNode( "D" ) );
10379             t2.reRoot( t2.getNode( "C" ) );
10380             t2.reRoot( t2.getNode( "ABC" ) );
10381             t2.reRoot( t2.getNode( "A" ) );
10382             t2.reRoot( t2.getNode( "B" ) );
10383             t2.reRoot( t2.getNode( "AB" ) );
10384             t2.reRoot( t2.getNode( "AB" ) );
10385             t2.reRoot( t2.getNode( "D" ) );
10386             t2.reRoot( t2.getNode( "C" ) );
10387             t2.reRoot( t2.getNode( "B" ) );
10388             t2.reRoot( t2.getNode( "AB" ) );
10389             t2.reRoot( t2.getNode( "D" ) );
10390             t2.reRoot( t2.getNode( "D" ) );
10391             t2.reRoot( t2.getNode( "ABC" ) );
10392             t2.reRoot( t2.getNode( "A" ) );
10393             t2.reRoot( t2.getNode( "B" ) );
10394             t2.reRoot( t2.getNode( "AB" ) );
10395             t2.reRoot( t2.getNode( "D" ) );
10396             t2.reRoot( t2.getNode( "C" ) );
10397             t2.reRoot( t2.getNode( "ABC" ) );
10398             t2.reRoot( t2.getNode( "A" ) );
10399             t2.reRoot( t2.getNode( "B" ) );
10400             t2.reRoot( t2.getNode( "AB" ) );
10401             t2.reRoot( t2.getNode( "D" ) );
10402             t2.reRoot( t2.getNode( "D" ) );
10403             t2.reRoot( t2.getNode( "C" ) );
10404             t2.reRoot( t2.getNode( "A" ) );
10405             t2.reRoot( t2.getNode( "B" ) );
10406             t2.reRoot( t2.getNode( "AB" ) );
10407             t2.reRoot( t2.getNode( "C" ) );
10408             t2.reRoot( t2.getNode( "D" ) );
10409             t2.reRoot( t2.getNode( "ABC" ) );
10410             t2.reRoot( t2.getNode( "D" ) );
10411             t2.reRoot( t2.getNode( "A" ) );
10412             t2.reRoot( t2.getNode( "B" ) );
10413             t2.reRoot( t2.getNode( "AB" ) );
10414             t2.reRoot( t2.getNode( "C" ) );
10415             t2.reRoot( t2.getNode( "D" ) );
10416             t2.reRoot( t2.getNode( "ABC" ) );
10417             t2.reRoot( t2.getNode( "D" ) );
10418             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10419                 return false;
10420             }
10421             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10422                 return false;
10423             }
10424             t2.reRoot( t2.getNode( "ABC" ) );
10425             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10426                 return false;
10427             }
10428             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10429                 return false;
10430             }
10431             t2.reRoot( t2.getNode( "AB" ) );
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(), 55 ) ) {
10436                 return false;
10437             }
10438             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10439                 return false;
10440             }
10441             t2.reRoot( t2.getNode( "AB" ) );
10442             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10443                 return false;
10444             }
10445             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10446                 return false;
10447             }
10448             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10449                 return false;
10450             }
10451             t2.reRoot( t2.getNode( "D" ) );
10452             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10453                 return false;
10454             }
10455             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10456                 return false;
10457             }
10458             t2.reRoot( t2.getNode( "ABC" ) );
10459             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10460                 return false;
10461             }
10462             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10463                 return false;
10464             }
10465             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10466                                                  new NHXParser() )[ 0 ];
10467             t3.reRoot( t3.getNode( "B" ) );
10468             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10469                 return false;
10470             }
10471             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10472                 return false;
10473             }
10474             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10475                 return false;
10476             }
10477             t3.reRoot( t3.getNode( "B" ) );
10478             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10479                 return false;
10480             }
10481             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10482                 return false;
10483             }
10484             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10485                 return false;
10486             }
10487             t3.reRoot( t3.getRoot() );
10488             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10489                 return false;
10490             }
10491             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10492                 return false;
10493             }
10494             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10495                 return false;
10496             }
10497         }
10498         catch ( final Exception e ) {
10499             e.printStackTrace( System.out );
10500             return false;
10501         }
10502         return true;
10503     }
10504
10505     private static boolean testSDIse() {
10506         try {
10507             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10508             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10509             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10510             gene1.setRooted( true );
10511             species1.setRooted( true );
10512             final SDI sdi = new SDI( gene1, species1 );
10513             if ( !gene1.getRoot().isDuplication() ) {
10514                 return false;
10515             }
10516             final Phylogeny species2 = factory
10517                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10518                              new NHXParser() )[ 0 ];
10519             final Phylogeny gene2 = factory
10520                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10521                              new NHXParser() )[ 0 ];
10522             species2.setRooted( true );
10523             gene2.setRooted( true );
10524             final SDI sdi2 = new SDI( gene2, species2 );
10525             if ( sdi2.getDuplicationsSum() != 0 ) {
10526                 return false;
10527             }
10528             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10529                 return false;
10530             }
10531             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10532                 return false;
10533             }
10534             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10535                 return false;
10536             }
10537             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10538                 return false;
10539             }
10540             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10541                 return false;
10542             }
10543             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10544                 return false;
10545             }
10546             final Phylogeny species3 = factory
10547                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10548                              new NHXParser() )[ 0 ];
10549             final Phylogeny gene3 = factory
10550                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10551                              new NHXParser() )[ 0 ];
10552             species3.setRooted( true );
10553             gene3.setRooted( true );
10554             final SDI sdi3 = new SDI( gene3, species3 );
10555             if ( sdi3.getDuplicationsSum() != 1 ) {
10556                 return false;
10557             }
10558             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10559                 return false;
10560             }
10561             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10562                 return false;
10563             }
10564             final Phylogeny species4 = factory
10565                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10566                              new NHXParser() )[ 0 ];
10567             final Phylogeny gene4 = factory
10568                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10569                              new NHXParser() )[ 0 ];
10570             species4.setRooted( true );
10571             gene4.setRooted( true );
10572             final SDI sdi4 = new SDI( gene4, species4 );
10573             if ( sdi4.getDuplicationsSum() != 1 ) {
10574                 return false;
10575             }
10576             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10577                 return false;
10578             }
10579             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10580                 return false;
10581             }
10582             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10583                 return false;
10584             }
10585             if ( species4.getNumberOfExternalNodes() != 6 ) {
10586                 return false;
10587             }
10588             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10589                 return false;
10590             }
10591             final Phylogeny species5 = factory
10592                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10593                              new NHXParser() )[ 0 ];
10594             final Phylogeny gene5 = factory
10595                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10596                              new NHXParser() )[ 0 ];
10597             species5.setRooted( true );
10598             gene5.setRooted( true );
10599             final SDI sdi5 = new SDI( gene5, species5 );
10600             if ( sdi5.getDuplicationsSum() != 2 ) {
10601                 return false;
10602             }
10603             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10604                 return false;
10605             }
10606             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10607                 return false;
10608             }
10609             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10610                 return false;
10611             }
10612             if ( species5.getNumberOfExternalNodes() != 6 ) {
10613                 return false;
10614             }
10615             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10616                 return false;
10617             }
10618             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10619             // Conjecture for Comparing Molecular Phylogenies"
10620             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10621             final Phylogeny species6 = factory
10622                     .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,"
10623                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10624                              new NHXParser() )[ 0 ];
10625             final Phylogeny gene6 = factory
10626                     .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,"
10627                                      + "((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,"
10628                                      + "(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;",
10629                              new NHXParser() )[ 0 ];
10630             species6.setRooted( true );
10631             gene6.setRooted( true );
10632             final SDI sdi6 = new SDI( gene6, species6 );
10633             if ( sdi6.getDuplicationsSum() != 3 ) {
10634                 return false;
10635             }
10636             if ( !gene6.getNode( "r" ).isDuplication() ) {
10637                 return false;
10638             }
10639             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10640                 return false;
10641             }
10642             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10643                 return false;
10644             }
10645             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10646                 return false;
10647             }
10648             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10649                 return false;
10650             }
10651             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10652                 return false;
10653             }
10654             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10655                 return false;
10656             }
10657             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10658                 return false;
10659             }
10660             sdi6.computeMappingCostL();
10661             if ( sdi6.computeMappingCostL() != 17 ) {
10662                 return false;
10663             }
10664             if ( species6.getNumberOfExternalNodes() != 9 ) {
10665                 return false;
10666             }
10667             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10668                 return false;
10669             }
10670             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10671                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10672                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10673                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10674                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10675             species7.setRooted( true );
10676             final Phylogeny gene7_1 = Test
10677                     .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])" );
10678             gene7_1.setRooted( true );
10679             final SDI sdi7 = new SDI( gene7_1, species7 );
10680             if ( sdi7.getDuplicationsSum() != 0 ) {
10681                 return false;
10682             }
10683             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10684                 return false;
10685             }
10686             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10687                 return false;
10688             }
10689             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10690                 return false;
10691             }
10692             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10693                 return false;
10694             }
10695             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10696                 return false;
10697             }
10698             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10699                 return false;
10700             }
10701             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10702                 return false;
10703             }
10704             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10705                 return false;
10706             }
10707             final Phylogeny gene7_2 = Test
10708                     .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])" );
10709             gene7_2.setRooted( true );
10710             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10711             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10712                 return false;
10713             }
10714             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10715                 return false;
10716             }
10717             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10718                 return false;
10719             }
10720             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10721                 return false;
10722             }
10723             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10724                 return false;
10725             }
10726             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10727                 return false;
10728             }
10729             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10730                 return false;
10731             }
10732             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10733                 return false;
10734             }
10735             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10736                 return false;
10737             }
10738             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10739                 return false;
10740             }
10741         }
10742         catch ( final Exception e ) {
10743             return false;
10744         }
10745         return true;
10746     }
10747
10748     private static boolean testSDIunrooted() {
10749         try {
10750             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10751             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10752             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10753             final Iterator<PhylogenyBranch> iter = l.iterator();
10754             PhylogenyBranch br = iter.next();
10755             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10756                 return false;
10757             }
10758             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10759                 return false;
10760             }
10761             br = iter.next();
10762             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10763                 return false;
10764             }
10765             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10766                 return false;
10767             }
10768             br = iter.next();
10769             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10770                 return false;
10771             }
10772             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10773                 return false;
10774             }
10775             br = iter.next();
10776             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10777                 return false;
10778             }
10779             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10780                 return false;
10781             }
10782             br = iter.next();
10783             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10784                 return false;
10785             }
10786             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10787                 return false;
10788             }
10789             br = iter.next();
10790             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10791                 return false;
10792             }
10793             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10794                 return false;
10795             }
10796             br = iter.next();
10797             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10798                 return false;
10799             }
10800             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10801                 return false;
10802             }
10803             br = iter.next();
10804             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10805                 return false;
10806             }
10807             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10808                 return false;
10809             }
10810             br = iter.next();
10811             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10812                 return false;
10813             }
10814             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10815                 return false;
10816             }
10817             br = iter.next();
10818             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10819                 return false;
10820             }
10821             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10822                 return false;
10823             }
10824             br = iter.next();
10825             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10826                 return false;
10827             }
10828             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10829                 return false;
10830             }
10831             br = iter.next();
10832             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10833                 return false;
10834             }
10835             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10836                 return false;
10837             }
10838             br = iter.next();
10839             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10840                 return false;
10841             }
10842             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10843                 return false;
10844             }
10845             br = iter.next();
10846             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10847                 return false;
10848             }
10849             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10850                 return false;
10851             }
10852             br = iter.next();
10853             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10854                 return false;
10855             }
10856             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10857                 return false;
10858             }
10859             if ( iter.hasNext() ) {
10860                 return false;
10861             }
10862             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10863             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10864             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10865             br = iter1.next();
10866             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10867                 return false;
10868             }
10869             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10870                 return false;
10871             }
10872             br = iter1.next();
10873             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10874                 return false;
10875             }
10876             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10877                 return false;
10878             }
10879             br = iter1.next();
10880             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10881                 return false;
10882             }
10883             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10884                 return false;
10885             }
10886             if ( iter1.hasNext() ) {
10887                 return false;
10888             }
10889             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10890             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10891             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10892             br = iter2.next();
10893             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10894                 return false;
10895             }
10896             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10897                 return false;
10898             }
10899             br = iter2.next();
10900             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10901                 return false;
10902             }
10903             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10904                 return false;
10905             }
10906             br = iter2.next();
10907             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10908                 return false;
10909             }
10910             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10911                 return false;
10912             }
10913             if ( iter2.hasNext() ) {
10914                 return false;
10915             }
10916             final Phylogeny species0 = factory
10917                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10918                              new NHXParser() )[ 0 ];
10919             final Phylogeny gene1 = factory
10920                     .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])",
10921                              new NHXParser() )[ 0 ];
10922             species0.setRooted( true );
10923             gene1.setRooted( true );
10924             final SDIR sdi_unrooted = new SDIR();
10925             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10926             if ( sdi_unrooted.getCount() != 1 ) {
10927                 return false;
10928             }
10929             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10930                 return false;
10931             }
10932             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10933                 return false;
10934             }
10935             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10936                 return false;
10937             }
10938             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10939                 return false;
10940             }
10941             final Phylogeny gene2 = factory
10942                     .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])",
10943                              new NHXParser() )[ 0 ];
10944             gene2.setRooted( true );
10945             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10946             if ( sdi_unrooted.getCount() != 1 ) {
10947                 return false;
10948             }
10949             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10950                 return false;
10951             }
10952             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10953                 return false;
10954             }
10955             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10956                 return false;
10957             }
10958             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10959                 return false;
10960             }
10961             final Phylogeny species6 = factory
10962                     .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,"
10963                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10964                              new NHXParser() )[ 0 ];
10965             final Phylogeny gene6 = factory
10966                     .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],"
10967                                      + "(((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],"
10968                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10969                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10970                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10971                              new NHXParser() )[ 0 ];
10972             species6.setRooted( true );
10973             gene6.setRooted( true );
10974             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10975             if ( sdi_unrooted.getCount() != 1 ) {
10976                 return false;
10977             }
10978             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10979                 return false;
10980             }
10981             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10982                 return false;
10983             }
10984             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10985                 return false;
10986             }
10987             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10988                 return false;
10989             }
10990             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10991                 return false;
10992             }
10993             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10994                 return false;
10995             }
10996             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10997                 return false;
10998             }
10999             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11000                 return false;
11001             }
11002             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11003                 return false;
11004             }
11005             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11006                 return false;
11007             }
11008             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11009                 return false;
11010             }
11011             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11012                 return false;
11013             }
11014             p6 = null;
11015             final Phylogeny species7 = factory
11016                     .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,"
11017                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11018                              new NHXParser() )[ 0 ];
11019             final Phylogeny gene7 = factory
11020                     .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],"
11021                                      + "(((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],"
11022                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11023                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11024                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11025                              new NHXParser() )[ 0 ];
11026             species7.setRooted( true );
11027             gene7.setRooted( true );
11028             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11029             if ( sdi_unrooted.getCount() != 1 ) {
11030                 return false;
11031             }
11032             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11033                 return false;
11034             }
11035             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11036                 return false;
11037             }
11038             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11039                 return false;
11040             }
11041             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11042                 return false;
11043             }
11044             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11045                 return false;
11046             }
11047             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11048                 return false;
11049             }
11050             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11051                 return false;
11052             }
11053             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11054                 return false;
11055             }
11056             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11057                 return false;
11058             }
11059             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11060                 return false;
11061             }
11062             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11063                 return false;
11064             }
11065             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11066                 return false;
11067             }
11068             p7 = null;
11069             final Phylogeny species8 = factory
11070                     .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,"
11071                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11072                              new NHXParser() )[ 0 ];
11073             final Phylogeny gene8 = factory
11074                     .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],"
11075                                      + "(((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],"
11076                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11077                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11078                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11079                              new NHXParser() )[ 0 ];
11080             species8.setRooted( true );
11081             gene8.setRooted( true );
11082             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11083             if ( sdi_unrooted.getCount() != 1 ) {
11084                 return false;
11085             }
11086             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11087                 return false;
11088             }
11089             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11090                 return false;
11091             }
11092             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11093                 return false;
11094             }
11095             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11096                 return false;
11097             }
11098             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11099                 return false;
11100             }
11101             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11102                 return false;
11103             }
11104             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11105                 return false;
11106             }
11107             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11108                 return false;
11109             }
11110             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11111                 return false;
11112             }
11113             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11114                 return false;
11115             }
11116             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11117                 return false;
11118             }
11119             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11120                 return false;
11121             }
11122             p8 = null;
11123         }
11124         catch ( final Exception e ) {
11125             e.printStackTrace( System.out );
11126             return false;
11127         }
11128         return true;
11129     }
11130
11131     private static boolean testSequenceDbWsTools1() {
11132         try {
11133             final PhylogenyNode n = new PhylogenyNode();
11134             n.setName( "NP_001025424" );
11135             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11136             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11137                     || !acc.getValue().equals( "NP_001025424" ) ) {
11138                 return false;
11139             }
11140             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11141             acc = SequenceDbWsTools.obtainSeqAccession( n );
11142             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11143                     || !acc.getValue().equals( "NP_001025424" ) ) {
11144                 return false;
11145             }
11146             n.setName( "NP_001025424.1" );
11147             acc = SequenceDbWsTools.obtainSeqAccession( n );
11148             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11149                     || !acc.getValue().equals( "NP_001025424" ) ) {
11150                 return false;
11151             }
11152             n.setName( "NM_001030253" );
11153             acc = SequenceDbWsTools.obtainSeqAccession( n );
11154             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11155                     || !acc.getValue().equals( "NM_001030253" ) ) {
11156                 return false;
11157             }
11158             n.setName( "BCL2_HUMAN" );
11159             acc = SequenceDbWsTools.obtainSeqAccession( n );
11160             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11161                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11162                 System.out.println( acc.toString() );
11163                 return false;
11164             }
11165             n.setName( "P10415" );
11166             acc = SequenceDbWsTools.obtainSeqAccession( n );
11167             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11168                     || !acc.getValue().equals( "P10415" ) ) {
11169                 System.out.println( acc.toString() );
11170                 return false;
11171             }
11172             n.setName( " P10415 " );
11173             acc = SequenceDbWsTools.obtainSeqAccession( n );
11174             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11175                     || !acc.getValue().equals( "P10415" ) ) {
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( "AY695820" );
11187             acc = SequenceDbWsTools.obtainSeqAccession( n );
11188             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11189                     || !acc.getValue().equals( "AY695820" ) ) {
11190                 System.out.println( acc.toString() );
11191                 return false;
11192             }
11193             n.setName( "_AY695820_" );
11194             acc = SequenceDbWsTools.obtainSeqAccession( n );
11195             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11196                     || !acc.getValue().equals( "AY695820" ) ) {
11197                 System.out.println( acc.toString() );
11198                 return false;
11199             }
11200             n.setName( "AAA59452" );
11201             acc = SequenceDbWsTools.obtainSeqAccession( n );
11202             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11203                     || !acc.getValue().equals( "AAA59452" ) ) {
11204                 System.out.println( acc.toString() );
11205                 return false;
11206             }
11207             n.setName( "_AAA59452_" );
11208             acc = SequenceDbWsTools.obtainSeqAccession( n );
11209             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11210                     || !acc.getValue().equals( "AAA59452" ) ) {
11211                 System.out.println( acc.toString() );
11212                 return false;
11213             }
11214             n.setName( "AAA59452.1" );
11215             acc = SequenceDbWsTools.obtainSeqAccession( n );
11216             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11217                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11218                 System.out.println( acc.toString() );
11219                 return false;
11220             }
11221             n.setName( "_AAA59452.1_" );
11222             acc = SequenceDbWsTools.obtainSeqAccession( n );
11223             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11224                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11225                 System.out.println( acc.toString() );
11226                 return false;
11227             }
11228             n.setName( "GI:94894583" );
11229             acc = SequenceDbWsTools.obtainSeqAccession( n );
11230             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11231                     || !acc.getValue().equals( "94894583" ) ) {
11232                 System.out.println( acc.toString() );
11233                 return false;
11234             }
11235             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11236             acc = SequenceDbWsTools.obtainSeqAccession( n );
11237             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11238                     || !acc.getValue().equals( "71845847" ) ) {
11239                 System.out.println( acc.toString() );
11240                 return false;
11241             }
11242             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11243             acc = SequenceDbWsTools.obtainSeqAccession( n );
11244             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11245                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11246                 System.out.println( acc.toString() );
11247                 return false;
11248             }
11249         }
11250         catch ( final Exception e ) {
11251             return false;
11252         }
11253         return true;
11254     }
11255
11256     private static boolean testSequenceDbWsTools2() {
11257         try {
11258             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11259             SequenceDbWsTools.obtainSeqInformation( n1 );
11260             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11261                 return false;
11262             }
11263             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11264                 return false;
11265             }
11266             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11267                 return false;
11268             }
11269             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11270                 return false;
11271             }
11272             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11273             SequenceDbWsTools.obtainSeqInformation( n2 );
11274             if ( !n2.getNodeData().getSequence().getName()
11275                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11276                 return false;
11277             }
11278             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11279                 return false;
11280             }
11281             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11282                 return false;
11283             }
11284             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11285                 return false;
11286             }
11287             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11288             SequenceDbWsTools.obtainSeqInformation( n3 );
11289             if ( !n3.getNodeData().getSequence().getName()
11290                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11291                 return false;
11292             }
11293             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11294                 return false;
11295             }
11296             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11297                 return false;
11298             }
11299             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11300                 return false;
11301             }
11302         }
11303         catch ( final IOException e ) {
11304             System.out.println();
11305             System.out.println( "the following might be due to absence internet connection:" );
11306             e.printStackTrace( System.out );
11307             return true;
11308         }
11309         catch ( final Exception e ) {
11310             e.printStackTrace();
11311             return false;
11312         }
11313         return true;
11314     }
11315
11316     private static boolean testSequenceIdParsing() {
11317         try {
11318             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11319             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11320                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11321                 if ( id != null ) {
11322                     System.out.println( "value   =" + id.getValue() );
11323                     System.out.println( "provider=" + id.getSource() );
11324                 }
11325                 return false;
11326             }
11327             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11328             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11329                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11330                 if ( id != null ) {
11331                     System.out.println( "value   =" + id.getValue() );
11332                     System.out.println( "provider=" + id.getSource() );
11333                 }
11334                 return false;
11335             }
11336             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11337             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11338                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11339                 if ( id != null ) {
11340                     System.out.println( "value   =" + id.getValue() );
11341                     System.out.println( "provider=" + id.getSource() );
11342                 }
11343                 return false;
11344             }
11345             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11346             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11347                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11348                 if ( id != null ) {
11349                     System.out.println( "value   =" + id.getValue() );
11350                     System.out.println( "provider=" + id.getSource() );
11351                 }
11352                 return false;
11353             }
11354             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11355             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11356                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11357                 if ( id != null ) {
11358                     System.out.println( "value   =" + id.getValue() );
11359                     System.out.println( "provider=" + id.getSource() );
11360                 }
11361                 return false;
11362             }
11363             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11364             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11365                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11366                 if ( id != null ) {
11367                     System.out.println( "value   =" + id.getValue() );
11368                     System.out.println( "provider=" + id.getSource() );
11369                 }
11370                 return false;
11371             }
11372             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11373             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11374                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11375                 if ( id != null ) {
11376                     System.out.println( "value   =" + id.getValue() );
11377                     System.out.println( "provider=" + id.getSource() );
11378                 }
11379                 return false;
11380             }
11381             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11382             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11383                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11384                 if ( id != null ) {
11385                     System.out.println( "value   =" + id.getValue() );
11386                     System.out.println( "provider=" + id.getSource() );
11387                 }
11388                 return false;
11389             }
11390             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11391             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11392                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11393                 if ( id != null ) {
11394                     System.out.println( "value   =" + id.getValue() );
11395                     System.out.println( "provider=" + id.getSource() );
11396                 }
11397                 return false;
11398             }
11399             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11400             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11401                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11402                 if ( id != null ) {
11403                     System.out.println( "value   =" + id.getValue() );
11404                     System.out.println( "provider=" + id.getSource() );
11405                 }
11406                 return false;
11407             }
11408             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11409             if ( id != null ) {
11410                 System.out.println( "value   =" + id.getValue() );
11411                 System.out.println( "provider=" + id.getSource() );
11412                 return false;
11413             }
11414             //
11415             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11416             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11417                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11418                 if ( id != null ) {
11419                     System.out.println( "value   =" + id.getValue() );
11420                     System.out.println( "provider=" + id.getSource() );
11421                 }
11422                 return false;
11423             }
11424             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11425             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11426                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11427                 if ( id != null ) {
11428                     System.out.println( "value   =" + id.getValue() );
11429                     System.out.println( "provider=" + id.getSource() );
11430                 }
11431                 return false;
11432             }
11433             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11434             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11435                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11436                 if ( id != null ) {
11437                     System.out.println( "value   =" + id.getValue() );
11438                     System.out.println( "provider=" + id.getSource() );
11439                 }
11440                 return false;
11441             }
11442             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11443             if ( id != null ) {
11444                 System.out.println( "value   =" + id.getValue() );
11445                 System.out.println( "provider=" + id.getSource() );
11446                 return false;
11447             }
11448         }
11449         catch ( final Exception e ) {
11450             e.printStackTrace( System.out );
11451             return false;
11452         }
11453         return true;
11454     }
11455
11456     private static boolean testSequenceWriter() {
11457         try {
11458             final String n = ForesterUtil.LINE_SEPARATOR;
11459             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11460                 return false;
11461             }
11462             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11463                 return false;
11464             }
11465             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11466                 return false;
11467             }
11468             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11469                 return false;
11470             }
11471             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11472                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11473                 return false;
11474             }
11475             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11476                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11477                 return false;
11478             }
11479         }
11480         catch ( final Exception e ) {
11481             e.printStackTrace();
11482             return false;
11483         }
11484         return true;
11485     }
11486
11487     private static boolean testSpecies() {
11488         try {
11489             final Species s1 = new BasicSpecies( "a" );
11490             final Species s2 = new BasicSpecies( "a" );
11491             final Species s3 = new BasicSpecies( "A" );
11492             final Species s4 = new BasicSpecies( "b" );
11493             if ( !s1.equals( s1 ) ) {
11494                 return false;
11495             }
11496             if ( s1.getSpeciesId().equals( "x" ) ) {
11497                 return false;
11498             }
11499             if ( s1.getSpeciesId().equals( null ) ) {
11500                 return false;
11501             }
11502             if ( !s1.equals( s2 ) ) {
11503                 return false;
11504             }
11505             if ( s1.equals( s3 ) ) {
11506                 return false;
11507             }
11508             if ( s1.hashCode() != s1.hashCode() ) {
11509                 return false;
11510             }
11511             if ( s1.hashCode() != s2.hashCode() ) {
11512                 return false;
11513             }
11514             if ( s1.hashCode() == s3.hashCode() ) {
11515                 return false;
11516             }
11517             if ( s1.compareTo( s1 ) != 0 ) {
11518                 return false;
11519             }
11520             if ( s1.compareTo( s2 ) != 0 ) {
11521                 return false;
11522             }
11523             if ( s1.compareTo( s3 ) != 0 ) {
11524                 return false;
11525             }
11526             if ( s1.compareTo( s4 ) >= 0 ) {
11527                 return false;
11528             }
11529             if ( s4.compareTo( s1 ) <= 0 ) {
11530                 return false;
11531             }
11532             if ( !s4.getSpeciesId().equals( "b" ) ) {
11533                 return false;
11534             }
11535             final Species s5 = new BasicSpecies( " C " );
11536             if ( !s5.getSpeciesId().equals( "C" ) ) {
11537                 return false;
11538             }
11539             if ( s5.equals( s1 ) ) {
11540                 return false;
11541             }
11542         }
11543         catch ( final Exception e ) {
11544             e.printStackTrace( System.out );
11545             return false;
11546         }
11547         return true;
11548     }
11549
11550     private static boolean testSplit() {
11551         try {
11552             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11553             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11554             //Archaeopteryx.createApplication( p0 );
11555             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11556             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11557             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11558             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11559             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11560             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11561             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11562             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11563             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11564             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11565             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11566             // System.out.println( s0.toString() );
11567             //
11568             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11571             if ( s0.match( query_nodes ) ) {
11572                 return false;
11573             }
11574             query_nodes = new HashSet<PhylogenyNode>();
11575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11582             if ( !s0.match( query_nodes ) ) {
11583                 return false;
11584             }
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             if ( !s0.match( query_nodes ) ) {
11591                 return false;
11592             }
11593             //
11594             query_nodes = new HashSet<PhylogenyNode>();
11595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11599             if ( !s0.match( query_nodes ) ) {
11600                 return false;
11601             }
11602             //
11603             query_nodes = new HashSet<PhylogenyNode>();
11604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11608             if ( !s0.match( query_nodes ) ) {
11609                 return false;
11610             }
11611             //
11612             query_nodes = new HashSet<PhylogenyNode>();
11613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11616             if ( !s0.match( query_nodes ) ) {
11617                 return false;
11618             }
11619             //
11620             query_nodes = new HashSet<PhylogenyNode>();
11621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11623             if ( !s0.match( query_nodes ) ) {
11624                 return false;
11625             }
11626             //
11627             query_nodes = new HashSet<PhylogenyNode>();
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11633             if ( !s0.match( query_nodes ) ) {
11634                 return false;
11635             }
11636             //
11637             query_nodes = new HashSet<PhylogenyNode>();
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11641             if ( !s0.match( query_nodes ) ) {
11642                 return false;
11643             }
11644             //
11645             query_nodes = new HashSet<PhylogenyNode>();
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11650             if ( !s0.match( query_nodes ) ) {
11651                 return false;
11652             }
11653             //
11654             query_nodes = new HashSet<PhylogenyNode>();
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11657             if ( s0.match( query_nodes ) ) {
11658                 return false;
11659             }
11660             //
11661             query_nodes = new HashSet<PhylogenyNode>();
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11666             if ( s0.match( query_nodes ) ) {
11667                 return false;
11668             }
11669             //
11670             query_nodes = new HashSet<PhylogenyNode>();
11671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11676             if ( s0.match( query_nodes ) ) {
11677                 return false;
11678             }
11679             //
11680             query_nodes = new HashSet<PhylogenyNode>();
11681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11684             if ( s0.match( query_nodes ) ) {
11685                 return false;
11686             }
11687             //
11688             query_nodes = new HashSet<PhylogenyNode>();
11689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11691             if ( s0.match( query_nodes ) ) {
11692                 return false;
11693             }
11694             //
11695             query_nodes = new HashSet<PhylogenyNode>();
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11698             if ( s0.match( query_nodes ) ) {
11699                 return false;
11700             }
11701             //
11702             query_nodes = new HashSet<PhylogenyNode>();
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11705             if ( s0.match( query_nodes ) ) {
11706                 return false;
11707             }
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             //
11716             query_nodes = new HashSet<PhylogenyNode>();
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11719             if ( s0.match( query_nodes ) ) {
11720                 return false;
11721             }
11722             //
11723             query_nodes = new HashSet<PhylogenyNode>();
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11726             if ( s0.match( query_nodes ) ) {
11727                 return false;
11728             }
11729             //
11730             query_nodes = new HashSet<PhylogenyNode>();
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11734             if ( s0.match( query_nodes ) ) {
11735                 return false;
11736             }
11737             //
11738             query_nodes = new HashSet<PhylogenyNode>();
11739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11742             if ( s0.match( query_nodes ) ) {
11743                 return false;
11744             }
11745             //
11746             query_nodes = new HashSet<PhylogenyNode>();
11747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11750             if ( s0.match( query_nodes ) ) {
11751                 return false;
11752             }
11753             //
11754             query_nodes = new HashSet<PhylogenyNode>();
11755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11759             if ( s0.match( query_nodes ) ) {
11760                 return false;
11761             }
11762             /////////
11763             //            query_nodes = new HashSet<PhylogenyNode>();
11764             //            query_nodes.add( new PhylogenyNode( "X" ) );
11765             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11766             //            query_nodes.add( new PhylogenyNode( "A" ) );
11767             //            query_nodes.add( new PhylogenyNode( "B" ) );
11768             //            query_nodes.add( new PhylogenyNode( "C" ) );
11769             //            query_nodes.add( new PhylogenyNode( "D" ) );
11770             //            query_nodes.add( new PhylogenyNode( "E" ) );
11771             //            query_nodes.add( new PhylogenyNode( "F" ) );
11772             //            query_nodes.add( new PhylogenyNode( "G" ) );
11773             //            if ( !s0.match( query_nodes ) ) {
11774             //                return false;
11775             //            }
11776             //            query_nodes = new HashSet<PhylogenyNode>();
11777             //            query_nodes.add( new PhylogenyNode( "X" ) );
11778             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11779             //            query_nodes.add( new PhylogenyNode( "A" ) );
11780             //            query_nodes.add( new PhylogenyNode( "B" ) );
11781             //            query_nodes.add( new PhylogenyNode( "C" ) );
11782             //            if ( !s0.match( query_nodes ) ) {
11783             //                return false;
11784             //            }
11785             //            //
11786             //            query_nodes = new HashSet<PhylogenyNode>();
11787             //            query_nodes.add( new PhylogenyNode( "X" ) );
11788             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11789             //            query_nodes.add( new PhylogenyNode( "D" ) );
11790             //            query_nodes.add( new PhylogenyNode( "E" ) );
11791             //            query_nodes.add( new PhylogenyNode( "F" ) );
11792             //            query_nodes.add( new PhylogenyNode( "G" ) );
11793             //            if ( !s0.match( query_nodes ) ) {
11794             //                return false;
11795             //            }
11796             //            //
11797             //            query_nodes = new HashSet<PhylogenyNode>();
11798             //            query_nodes.add( new PhylogenyNode( "X" ) );
11799             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11800             //            query_nodes.add( new PhylogenyNode( "A" ) );
11801             //            query_nodes.add( new PhylogenyNode( "B" ) );
11802             //            query_nodes.add( new PhylogenyNode( "C" ) );
11803             //            query_nodes.add( new PhylogenyNode( "D" ) );
11804             //            if ( !s0.match( query_nodes ) ) {
11805             //                return false;
11806             //            }
11807             //            //
11808             //            query_nodes = new HashSet<PhylogenyNode>();
11809             //            query_nodes.add( new PhylogenyNode( "X" ) );
11810             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11811             //            query_nodes.add( new PhylogenyNode( "E" ) );
11812             //            query_nodes.add( new PhylogenyNode( "F" ) );
11813             //            query_nodes.add( new PhylogenyNode( "G" ) );
11814             //            if ( !s0.match( query_nodes ) ) {
11815             //                return false;
11816             //            }
11817             //            //
11818             //            query_nodes = new HashSet<PhylogenyNode>();
11819             //            query_nodes.add( new PhylogenyNode( "X" ) );
11820             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11821             //            query_nodes.add( new PhylogenyNode( "F" ) );
11822             //            query_nodes.add( new PhylogenyNode( "G" ) );
11823             //            if ( !s0.match( query_nodes ) ) {
11824             //                return false;
11825             //            }
11826             //
11827             query_nodes = new HashSet<PhylogenyNode>();
11828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11832             if ( s0.match( query_nodes ) ) {
11833                 return false;
11834             }
11835             //
11836             query_nodes = new HashSet<PhylogenyNode>();
11837             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11841             if ( s0.match( query_nodes ) ) {
11842                 return false;
11843             }
11844             ///////////////////////////
11845             //
11846             query_nodes = new HashSet<PhylogenyNode>();
11847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11851             if ( s0.match( query_nodes ) ) {
11852                 return false;
11853             }
11854             //
11855             query_nodes = new HashSet<PhylogenyNode>();
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11860             if ( s0.match( query_nodes ) ) {
11861                 return false;
11862             }
11863             //
11864             query_nodes = new HashSet<PhylogenyNode>();
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11869             if ( s0.match( query_nodes ) ) {
11870                 return false;
11871             }
11872             //
11873             query_nodes = new HashSet<PhylogenyNode>();
11874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11878             if ( s0.match( query_nodes ) ) {
11879                 return false;
11880             }
11881             //
11882             query_nodes = new HashSet<PhylogenyNode>();
11883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11887             if ( s0.match( query_nodes ) ) {
11888                 return false;
11889             }
11890             //
11891             query_nodes = new HashSet<PhylogenyNode>();
11892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11895             if ( s0.match( query_nodes ) ) {
11896                 return false;
11897             }
11898             //
11899             query_nodes = new HashSet<PhylogenyNode>();
11900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11905             if ( s0.match( query_nodes ) ) {
11906                 return false;
11907             }
11908             //
11909             query_nodes = new HashSet<PhylogenyNode>();
11910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11915             if ( s0.match( query_nodes ) ) {
11916                 return false;
11917             }
11918             //
11919             query_nodes = new HashSet<PhylogenyNode>();
11920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11925             if ( s0.match( query_nodes ) ) {
11926                 return false;
11927             }
11928             //
11929             query_nodes = new HashSet<PhylogenyNode>();
11930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11936             if ( s0.match( query_nodes ) ) {
11937                 return false;
11938             }
11939         }
11940         catch ( final Exception e ) {
11941             e.printStackTrace();
11942             return false;
11943         }
11944         return true;
11945     }
11946
11947     private static boolean testSplitStrict() {
11948         try {
11949             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11950             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11951             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11952             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11953             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11954             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11955             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11956             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11957             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11958             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11959             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11960             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11963             if ( s0.match( query_nodes ) ) {
11964                 return false;
11965             }
11966             query_nodes = new HashSet<PhylogenyNode>();
11967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11974             if ( !s0.match( query_nodes ) ) {
11975                 return false;
11976             }
11977             //
11978             query_nodes = new HashSet<PhylogenyNode>();
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11982             if ( !s0.match( query_nodes ) ) {
11983                 return false;
11984             }
11985             //
11986             query_nodes = new HashSet<PhylogenyNode>();
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11991             if ( !s0.match( query_nodes ) ) {
11992                 return false;
11993             }
11994             //
11995             query_nodes = new HashSet<PhylogenyNode>();
11996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12000             if ( !s0.match( query_nodes ) ) {
12001                 return false;
12002             }
12003             //
12004             query_nodes = new HashSet<PhylogenyNode>();
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12008             if ( !s0.match( query_nodes ) ) {
12009                 return false;
12010             }
12011             //
12012             query_nodes = new HashSet<PhylogenyNode>();
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12015             if ( !s0.match( query_nodes ) ) {
12016                 return false;
12017             }
12018             //
12019             query_nodes = new HashSet<PhylogenyNode>();
12020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12025             if ( !s0.match( query_nodes ) ) {
12026                 return false;
12027             }
12028             //
12029             query_nodes = new HashSet<PhylogenyNode>();
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12033             if ( !s0.match( query_nodes ) ) {
12034                 return false;
12035             }
12036             //
12037             query_nodes = new HashSet<PhylogenyNode>();
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12042             if ( !s0.match( query_nodes ) ) {
12043                 return false;
12044             }
12045             //
12046             query_nodes = new HashSet<PhylogenyNode>();
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12049             if ( s0.match( query_nodes ) ) {
12050                 return false;
12051             }
12052             //
12053             query_nodes = new HashSet<PhylogenyNode>();
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12058             if ( s0.match( query_nodes ) ) {
12059                 return false;
12060             }
12061             //
12062             query_nodes = new HashSet<PhylogenyNode>();
12063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12068             if ( s0.match( query_nodes ) ) {
12069                 return false;
12070             }
12071             //
12072             query_nodes = new HashSet<PhylogenyNode>();
12073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12076             if ( s0.match( query_nodes ) ) {
12077                 return false;
12078             }
12079             //
12080             query_nodes = new HashSet<PhylogenyNode>();
12081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12083             if ( s0.match( query_nodes ) ) {
12084                 return false;
12085             }
12086             //
12087             query_nodes = new HashSet<PhylogenyNode>();
12088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12090             if ( s0.match( query_nodes ) ) {
12091                 return false;
12092             }
12093             //
12094             query_nodes = new HashSet<PhylogenyNode>();
12095             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12097             if ( s0.match( query_nodes ) ) {
12098                 return false;
12099             }
12100             //
12101             query_nodes = new HashSet<PhylogenyNode>();
12102             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12104             if ( s0.match( query_nodes ) ) {
12105                 return false;
12106             }
12107             //
12108             query_nodes = new HashSet<PhylogenyNode>();
12109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12111             if ( s0.match( query_nodes ) ) {
12112                 return false;
12113             }
12114             //
12115             query_nodes = new HashSet<PhylogenyNode>();
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12118             if ( s0.match( query_nodes ) ) {
12119                 return false;
12120             }
12121             //
12122             query_nodes = new HashSet<PhylogenyNode>();
12123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12126             if ( s0.match( query_nodes ) ) {
12127                 return false;
12128             }
12129             //
12130             query_nodes = new HashSet<PhylogenyNode>();
12131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12134             if ( s0.match( query_nodes ) ) {
12135                 return false;
12136             }
12137             //
12138             query_nodes = new HashSet<PhylogenyNode>();
12139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12142             if ( s0.match( query_nodes ) ) {
12143                 return false;
12144             }
12145             //
12146             query_nodes = new HashSet<PhylogenyNode>();
12147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12151             if ( s0.match( query_nodes ) ) {
12152                 return false;
12153             }
12154         }
12155         catch ( final Exception e ) {
12156             e.printStackTrace();
12157             return false;
12158         }
12159         return true;
12160     }
12161
12162     private static boolean testSubtreeDeletion() {
12163         try {
12164             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12165             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12166             t1.deleteSubtree( t1.getNode( "A" ), false );
12167             if ( t1.getNumberOfExternalNodes() != 5 ) {
12168                 return false;
12169             }
12170             t1.toNewHampshireX();
12171             t1.deleteSubtree( t1.getNode( "E" ), false );
12172             if ( t1.getNumberOfExternalNodes() != 4 ) {
12173                 return false;
12174             }
12175             t1.toNewHampshireX();
12176             t1.deleteSubtree( t1.getNode( "F" ), false );
12177             if ( t1.getNumberOfExternalNodes() != 3 ) {
12178                 return false;
12179             }
12180             t1.toNewHampshireX();
12181             t1.deleteSubtree( t1.getNode( "D" ), false );
12182             t1.toNewHampshireX();
12183             if ( t1.getNumberOfExternalNodes() != 3 ) {
12184                 return false;
12185             }
12186             t1.deleteSubtree( t1.getNode( "def" ), false );
12187             t1.toNewHampshireX();
12188             if ( t1.getNumberOfExternalNodes() != 2 ) {
12189                 return false;
12190             }
12191             t1.deleteSubtree( t1.getNode( "B" ), false );
12192             t1.toNewHampshireX();
12193             if ( t1.getNumberOfExternalNodes() != 1 ) {
12194                 return false;
12195             }
12196             t1.deleteSubtree( t1.getNode( "C" ), false );
12197             t1.toNewHampshireX();
12198             if ( t1.getNumberOfExternalNodes() != 1 ) {
12199                 return false;
12200             }
12201             t1.deleteSubtree( t1.getNode( "abc" ), false );
12202             t1.toNewHampshireX();
12203             if ( t1.getNumberOfExternalNodes() != 1 ) {
12204                 return false;
12205             }
12206             t1.deleteSubtree( t1.getNode( "r" ), false );
12207             if ( t1.getNumberOfExternalNodes() != 0 ) {
12208                 return false;
12209             }
12210             if ( !t1.isEmpty() ) {
12211                 return false;
12212             }
12213             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12214             t2.deleteSubtree( t2.getNode( "A" ), false );
12215             t2.toNewHampshireX();
12216             if ( t2.getNumberOfExternalNodes() != 5 ) {
12217                 return false;
12218             }
12219             t2.deleteSubtree( t2.getNode( "abc" ), false );
12220             t2.toNewHampshireX();
12221             if ( t2.getNumberOfExternalNodes() != 3 ) {
12222                 return false;
12223             }
12224             t2.deleteSubtree( t2.getNode( "def" ), false );
12225             t2.toNewHampshireX();
12226             if ( t2.getNumberOfExternalNodes() != 1 ) {
12227                 return false;
12228             }
12229         }
12230         catch ( final Exception e ) {
12231             e.printStackTrace( System.out );
12232             return false;
12233         }
12234         return true;
12235     }
12236
12237     private static boolean testSupportCount() {
12238         try {
12239             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12240             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12241             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12242                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12243                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12244                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12245                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12246                                                               new NHXParser() );
12247             SupportCount.count( t0_1, phylogenies_1, true, false );
12248             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12249             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12250                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12251                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12252                                                                       + "(((((A,B),C),D),E),(F,G))"
12253                                                                       + "(((((A,B),C),D),E),(F,G))"
12254                                                                       + "(((((A,B),C),D),E),(F,G))"
12255                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12256                                                                       + "(((((A,B),C),D),E),(F,G))"
12257                                                                       + "((((((A,B),C),D),E),F),G)"
12258                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12259                                                               new NHXParser() );
12260             SupportCount.count( t0_2, phylogenies_2, true, false );
12261             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12262             while ( it.hasNext() ) {
12263                 final PhylogenyNode n = it.next();
12264                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12265                     return false;
12266                 }
12267             }
12268             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12269             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12270                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12271             SupportCount.count( t0_3, phylogenies_3, true, false );
12272             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12273             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12274                 return false;
12275             }
12276             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12277                 return false;
12278             }
12279             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12280                 return false;
12281             }
12282             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12283                 return false;
12284             }
12285             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12286                 return false;
12287             }
12288             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12289                 return false;
12290             }
12291             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12292                 return false;
12293             }
12294             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12295                 return false;
12296             }
12297             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12298                 return false;
12299             }
12300             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12301                 return false;
12302             }
12303             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12304             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12305                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12306             SupportCount.count( t0_4, phylogenies_4, true, false );
12307             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12308             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12309                 return false;
12310             }
12311             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12312                 return false;
12313             }
12314             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12315                 return false;
12316             }
12317             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12318                 return false;
12319             }
12320             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12321                 return false;
12322             }
12323             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12324                 return false;
12325             }
12326             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12327                 return false;
12328             }
12329             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12330                 return false;
12331             }
12332             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12333                 return false;
12334             }
12335             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12336                 return false;
12337             }
12338             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12339             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12340             double d = SupportCount.compare( b1, a, true, true, true );
12341             if ( !Test.isEqual( d, 5.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 b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12346             d = SupportCount.compare( b2, a, true, true, true );
12347             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12348                 return false;
12349             }
12350             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12351             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12352             d = SupportCount.compare( b3, a, true, true, true );
12353             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12354                 return false;
12355             }
12356             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12357             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12358             d = SupportCount.compare( b4, a, true, true, false );
12359             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12360                 return false;
12361             }
12362         }
12363         catch ( final Exception e ) {
12364             e.printStackTrace( System.out );
12365             return false;
12366         }
12367         return true;
12368     }
12369
12370     private static boolean testSupportTransfer() {
12371         try {
12372             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12373             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)",
12374                                                  new NHXParser() )[ 0 ];
12375             final Phylogeny p2 = factory
12376                     .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 ];
12377             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12378                 return false;
12379             }
12380             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12381                 return false;
12382             }
12383             support_transfer.moveBranchLengthsToBootstrap( p1 );
12384             support_transfer.transferSupportValues( p1, p2 );
12385             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12386                 return false;
12387             }
12388             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12389                 return false;
12390             }
12391             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12392                 return false;
12393             }
12394             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12395                 return false;
12396             }
12397             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12398                 return false;
12399             }
12400             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12401                 return false;
12402             }
12403             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12404                 return false;
12405             }
12406             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12407                 return false;
12408             }
12409         }
12410         catch ( final Exception e ) {
12411             e.printStackTrace( System.out );
12412             return false;
12413         }
12414         return true;
12415     }
12416
12417     private static boolean testTaxonomyExtraction() {
12418         try {
12419             final PhylogenyNode n0 = PhylogenyNode
12420                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12421             if ( n0.getNodeData().isHasTaxonomy() ) {
12422                 return false;
12423             }
12424             final PhylogenyNode n1 = PhylogenyNode
12425                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12426             if ( n1.getNodeData().isHasTaxonomy() ) {
12427                 System.out.println( n1.toString() );
12428                 return false;
12429             }
12430             final PhylogenyNode n2x = PhylogenyNode
12431                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12432             if ( n2x.getNodeData().isHasTaxonomy() ) {
12433                 return false;
12434             }
12435             final PhylogenyNode n3 = PhylogenyNode
12436                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12437             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12438                 System.out.println( n3.toString() );
12439                 return false;
12440             }
12441             final PhylogenyNode n4 = PhylogenyNode
12442                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12443             if ( n4.getNodeData().isHasTaxonomy() ) {
12444                 System.out.println( n4.toString() );
12445                 return false;
12446             }
12447             final PhylogenyNode n5 = PhylogenyNode
12448                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12449             if ( n5.getNodeData().isHasTaxonomy() ) {
12450                 System.out.println( n5.toString() );
12451                 return false;
12452             }
12453             final PhylogenyNode n6 = PhylogenyNode
12454                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12455             if ( n6.getNodeData().isHasTaxonomy() ) {
12456                 System.out.println( n6.toString() );
12457                 return false;
12458             }
12459             final PhylogenyNode n7 = PhylogenyNode
12460                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12461             if ( n7.getNodeData().isHasTaxonomy() ) {
12462                 System.out.println( n7.toString() );
12463                 return false;
12464             }
12465             final PhylogenyNode n8 = PhylogenyNode
12466                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12467             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12468                 System.out.println( n8.toString() );
12469                 return false;
12470             }
12471             final PhylogenyNode n9 = PhylogenyNode
12472                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12473             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12474                 System.out.println( n9.toString() );
12475                 return false;
12476             }
12477             final PhylogenyNode n10x = PhylogenyNode
12478                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12479             if ( n10x.getNodeData().isHasTaxonomy() ) {
12480                 System.out.println( n10x.toString() );
12481                 return false;
12482             }
12483             final PhylogenyNode n10xx = PhylogenyNode
12484                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12485             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12486                 System.out.println( n10xx.toString() );
12487                 return false;
12488             }
12489             final PhylogenyNode n10 = PhylogenyNode
12490                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12491             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12492                 System.out.println( n10.toString() );
12493                 return false;
12494             }
12495             final PhylogenyNode n11 = PhylogenyNode
12496                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12497             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12498                 System.out.println( n11.toString() );
12499                 return false;
12500             }
12501             final PhylogenyNode n12 = PhylogenyNode
12502                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12503                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12504             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12505                 System.out.println( n12.toString() );
12506                 return false;
12507             }
12508             final PhylogenyNode n13 = PhylogenyNode
12509                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12510             if ( n13.getNodeData().isHasTaxonomy() ) {
12511                 System.out.println( n13.toString() );
12512                 return false;
12513             }
12514             final PhylogenyNode n14 = PhylogenyNode
12515                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12516             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12517                 System.out.println( n14.toString() );
12518                 return false;
12519             }
12520             final PhylogenyNode n15 = PhylogenyNode
12521                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12522             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12523                 System.out.println( n15.toString() );
12524                 return false;
12525             }
12526             final PhylogenyNode n16 = PhylogenyNode
12527                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12528             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12529                 System.out.println( n16.toString() );
12530                 return false;
12531             }
12532             final PhylogenyNode n17 = PhylogenyNode
12533                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12534             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12535                 System.out.println( n17.toString() );
12536                 return false;
12537             }
12538             //
12539             final PhylogenyNode n18 = PhylogenyNode
12540                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12541             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12542                 System.out.println( n18.toString() );
12543                 return false;
12544             }
12545             final PhylogenyNode n19 = PhylogenyNode
12546                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12547                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12548             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12549                 System.out.println( n19.toString() );
12550                 return false;
12551             }
12552             final PhylogenyNode n20 = PhylogenyNode
12553                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12554             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12555                 System.out.println( n20.toString() );
12556                 return false;
12557             }
12558             final PhylogenyNode n21 = PhylogenyNode
12559                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12560                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12561             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12562                 System.out.println( n21.toString() );
12563                 return false;
12564             }
12565             final PhylogenyNode n22 = PhylogenyNode
12566                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12567                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12568             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12569                 System.out.println( n22.toString() );
12570                 return false;
12571             }
12572             final PhylogenyNode n23 = PhylogenyNode
12573                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12574                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12576                 System.out.println( n23.toString() );
12577                 return false;
12578             }
12579             final PhylogenyNode n24 = PhylogenyNode
12580                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12581             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12582                 System.out.println( n24.toString() );
12583                 return false;
12584             }
12585             //
12586             final PhylogenyNode n25 = PhylogenyNode
12587                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12588                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12589             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12590                 System.out.println( n25.toString() );
12591                 return false;
12592             }
12593             final PhylogenyNode n26 = PhylogenyNode
12594                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12595                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12596             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12597                 System.out.println( n26.toString() );
12598                 return false;
12599             }
12600             final PhylogenyNode n27 = PhylogenyNode
12601                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12602             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12603                 System.out.println( n27.toString() );
12604                 return false;
12605             }
12606         }
12607         catch ( final Exception e ) {
12608             e.printStackTrace( System.out );
12609             return false;
12610         }
12611         return true;
12612     }
12613
12614     private static boolean testTreeCopy() {
12615         try {
12616             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12617             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12618             final Phylogeny t1 = t0.copy();
12619             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12620                 return false;
12621             }
12622             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12623                 return false;
12624             }
12625             t0.deleteSubtree( t0.getNode( "c" ), true );
12626             t0.deleteSubtree( t0.getNode( "a" ), true );
12627             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12628             t0.getNode( "b" ).setName( "Bee" );
12629             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12630                 return false;
12631             }
12632             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12633                 return false;
12634             }
12635             t0.deleteSubtree( t0.getNode( "e" ), true );
12636             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12637             t0.deleteSubtree( t0.getNode( "d" ), true );
12638             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12639                 return false;
12640             }
12641         }
12642         catch ( final Exception e ) {
12643             e.printStackTrace();
12644             return false;
12645         }
12646         return true;
12647     }
12648
12649     private static boolean testTreeMethods() {
12650         try {
12651             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12652             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12653             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12654             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12655                 System.out.println( t0.toNewHampshireX() );
12656                 return false;
12657             }
12658             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12659             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12660             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12661                 return false;
12662             }
12663             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12664                 return false;
12665             }
12666             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12667                 return false;
12668             }
12669         }
12670         catch ( final Exception e ) {
12671             e.printStackTrace( System.out );
12672             return false;
12673         }
12674         return true;
12675     }
12676
12677     private static boolean testUniprotEntryRetrieval() {
12678         try {
12679             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12680             if ( !entry.getAccession().equals( "P12345" ) ) {
12681                 return false;
12682             }
12683             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12684                 return false;
12685             }
12686             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12687                 return false;
12688             }
12689             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12690                 return false;
12691             }
12692             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12693                 return false;
12694             }
12695             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12696                 return false;
12697             }
12698         }
12699         catch ( final IOException e ) {
12700             System.out.println();
12701             System.out.println( "the following might be due to absence internet connection:" );
12702             e.printStackTrace( System.out );
12703             return true;
12704         }
12705         catch ( final Exception e ) {
12706             return false;
12707         }
12708         return true;
12709     }
12710
12711     private static boolean testUniprotTaxonomySearch() {
12712         try {
12713             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12714                                                                                                  10 );
12715             if ( results.size() != 1 ) {
12716                 return false;
12717             }
12718             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12719                 return false;
12720             }
12721             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12722                 return false;
12723             }
12724             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12725                 return false;
12726             }
12727             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12728                 return false;
12729             }
12730             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12731                 return false;
12732             }
12733             results = null;
12734             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12735             if ( results.size() != 1 ) {
12736                 return false;
12737             }
12738             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12739                 return false;
12740             }
12741             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12742                 return false;
12743             }
12744             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12745                 return false;
12746             }
12747             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12748                 return false;
12749             }
12750             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12751                 return false;
12752             }
12753             results = null;
12754             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12755             if ( results.size() != 1 ) {
12756                 return false;
12757             }
12758             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12759                 return false;
12760             }
12761             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12762                 return false;
12763             }
12764             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12765                 return false;
12766             }
12767             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12771                 return false;
12772             }
12773             results = null;
12774             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12775             if ( results.size() != 1 ) {
12776                 return false;
12777             }
12778             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12779                 return false;
12780             }
12781             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12782                 return false;
12783             }
12784             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12785                 return false;
12786             }
12787             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12788                 return false;
12789             }
12790             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12791                 return false;
12792             }
12793             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12794                 return false;
12795             }
12796             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12797                 return false;
12798             }
12799             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12800                     .equals( "Nematostella vectensis" ) ) {
12801                 System.out.println( results.get( 0 ).getLineage() );
12802                 return false;
12803             }
12804             //
12805             results = null;
12806             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12807             if ( results.size() != 1 ) {
12808                 return false;
12809             }
12810             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12811                 return false;
12812             }
12813             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12814                 return false;
12815             }
12816             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12817                 return false;
12818             }
12819             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12820                 return false;
12821             }
12822             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12823                 return false;
12824             }
12825             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12826                     .equals( "Xenopus tropicalis" ) ) {
12827                 System.out.println( results.get( 0 ).getLineage() );
12828                 return false;
12829             }
12830             //
12831             results = null;
12832             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12833             if ( results.size() != 1 ) {
12834                 return false;
12835             }
12836             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12837                 return false;
12838             }
12839             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12840                 return false;
12841             }
12842             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12843                 return false;
12844             }
12845             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12846                 return false;
12847             }
12848             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12849                 return false;
12850             }
12851             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12852                     .equals( "Xenopus tropicalis" ) ) {
12853                 System.out.println( results.get( 0 ).getLineage() );
12854                 return false;
12855             }
12856             //
12857             results = null;
12858             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12859             if ( results.size() != 1 ) {
12860                 return false;
12861             }
12862             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12863                 return false;
12864             }
12865             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12866                 return false;
12867             }
12868             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12869                 return false;
12870             }
12871             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12872                 return false;
12873             }
12874             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12875                 return false;
12876             }
12877             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12878                     .equals( "Xenopus tropicalis" ) ) {
12879                 System.out.println( results.get( 0 ).getLineage() );
12880                 return false;
12881             }
12882         }
12883         catch ( final IOException e ) {
12884             System.out.println();
12885             System.out.println( "the following might be due to absence internet connection:" );
12886             e.printStackTrace( System.out );
12887             return true;
12888         }
12889         catch ( final Exception e ) {
12890             return false;
12891         }
12892         return true;
12893     }
12894
12895     private static boolean testWabiTxSearch() {
12896         try {
12897             String result = "";
12898             result = TxSearch.searchSimple( "nematostella" );
12899             result = TxSearch.getTxId( "nematostella" );
12900             if ( !result.equals( "45350" ) ) {
12901                 return false;
12902             }
12903             result = TxSearch.getTxName( "45350" );
12904             if ( !result.equals( "Nematostella" ) ) {
12905                 return false;
12906             }
12907             result = TxSearch.getTxId( "nematostella vectensis" );
12908             if ( !result.equals( "45351" ) ) {
12909                 return false;
12910             }
12911             result = TxSearch.getTxName( "45351" );
12912             if ( !result.equals( "Nematostella vectensis" ) ) {
12913                 return false;
12914             }
12915             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12916             if ( !result.equals( "536089" ) ) {
12917                 return false;
12918             }
12919             result = TxSearch.getTxName( "536089" );
12920             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12921                 return false;
12922             }
12923             final List<String> queries = new ArrayList<String>();
12924             queries.add( "Campylobacter coli" );
12925             queries.add( "Escherichia coli" );
12926             queries.add( "Arabidopsis" );
12927             queries.add( "Trichoplax" );
12928             queries.add( "Samanea saman" );
12929             queries.add( "Kluyveromyces marxianus" );
12930             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12931             queries.add( "Bornavirus parrot/PDD/2008" );
12932             final List<RANKS> ranks = new ArrayList<RANKS>();
12933             ranks.add( RANKS.SUPERKINGDOM );
12934             ranks.add( RANKS.KINGDOM );
12935             ranks.add( RANKS.FAMILY );
12936             ranks.add( RANKS.GENUS );
12937             ranks.add( RANKS.TRIBE );
12938             result = TxSearch.searchLineage( queries, ranks );
12939             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12940             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12941         }
12942         catch ( final Exception e ) {
12943             System.out.println();
12944             System.out.println( "the following might be due to absence internet connection:" );
12945             e.printStackTrace( System.out );
12946             return false;
12947         }
12948         return true;
12949     }
12950 }