0dd12a5987c29039c2980c0572e29ad2d8e395a2
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesMap;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.MolecularSequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128 import org.forester.ws.wabi.TxSearch;
129 import org.forester.ws.wabi.TxSearch.RANKS;
130 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
131 import org.forester.ws.wabi.TxSearch.TAX_RANK;
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137                                                                    + ForesterUtil.getFileSeparator() + "resources"
138                                                                    + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140                                                                    + ForesterUtil.getFileSeparator() + "test_data"
141                                                                    + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = true;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
146                                                                    + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
149                                                                    + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     public static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                 + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         System.out.print( "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 data extraction: " );
302         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "Taxonomy code extraction: " );
311         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "SN extraction: " );
320         if ( Test.testExtractSNFromNodeName() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Taxonomy extraction (general): " );
329         if ( Test.testTaxonomyExtraction() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Uri for Aptx web sequence accession: " );
338         if ( Test.testCreateUriForSeqWeb() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "Basic node construction and parsing of NHX (node level): " );
347         if ( Test.testNHXNodeParsing() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NHX parsing iterating: " );
356         if ( Test.testNHParsingIter() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "NH parsing: " );
365         if ( Test.testNHParsing() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "Conversion to NHX (node level): " );
374         if ( Test.testNHXconversion() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing: " );
383         if ( Test.testNHXParsing() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing with quotes: " );
392         if ( Test.testNHXParsingQuotes() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "NHX parsing (MrBayes): " );
401         if ( Test.testNHXParsingMB() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus characters parsing: " );
410         if ( Test.testNexusCharactersParsing() ) {
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 iterating: " );
419         if ( Test.testNexusTreeParsingIterating() ) {
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: " );
428         if ( Test.testNexusTreeParsing() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus tree parsing (translating): " );
437         if ( Test.testNexusTreeParsingTranslating() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Nexus matrix parsing: " );
446         if ( Test.testNexusMatrixParsing() ) {
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: " );
455         if ( Test.testBasicPhyloXMLparsing() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Basic phyloXML parsing (validating against schema): " );
464         if ( testBasicPhyloXMLparsingValidating() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
473         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "phyloXML Distribution Element: " );
482         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Tol XML parsing: " );
491         if ( Test.testBasicTolXMLparsing() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Copying of node data: " );
500         if ( Test.testCopyOfNodeData() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Tree copy: " );
509         if ( Test.testTreeCopy() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Basic tree methods: " );
518         if ( Test.testBasicTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Tree methods: " );
527         if ( Test.testTreeMethods() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Postorder Iterator: " );
536         if ( Test.testPostOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Preorder Iterator: " );
545         if ( Test.testPreOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Levelorder Iterator: " );
554         if ( Test.testLevelOrderIterator() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Re-id methods: " );
563         if ( Test.testReIdMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on last external nodes: " );
572         if ( Test.testLastExternalNodeMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Methods on external nodes: " );
581         if ( Test.testExternalNodeRelatedMethods() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Deletion of external nodes: " );
590         if ( Test.testDeletionOfExternalNodes() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Subtree deletion: " );
599         if ( Test.testSubtreeDeletion() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Phylogeny branch: " );
608         if ( Test.testPhylogenyBranch() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Rerooting: " );
617         if ( Test.testRerooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Mipoint rooting: " );
626         if ( Test.testMidpointrooting() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Node removal: " );
635         if ( Test.testNodeRemoval() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support count: " );
644         if ( Test.testSupportCount() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Support transfer: " );
653         if ( Test.testSupportTransfer() ) {
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: " );
662         if ( Test.testGetLCA() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Finding of LCA 2: " );
671         if ( Test.testGetLCA2() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Calculation of distance between nodes: " );
680         if ( Test.testGetDistance() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Descriptive statistics: " );
689         if ( Test.testDescriptiveStatistics() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Data objects and methods: " );
698         if ( Test.testDataObjects() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "Properties map: " );
707         if ( Test.testPropertiesMap() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIse: " );
716         if ( Test.testSDIse() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "SDIunrooted: " );
725         if ( Test.testSDIunrooted() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "GSDI: " );
734         if ( TestGSDI.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "RIO: " );
743         if ( TestRIO.test() ) {
744             System.out.println( "OK." );
745             succeeded++;
746         }
747         else {
748             System.out.println( "failed." );
749             failed++;
750         }
751         System.out.print( "Phylogeny reconstruction:" );
752         System.out.println();
753         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "Analysis of domain architectures: " );
762         System.out.println();
763         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "GO: " );
772         System.out.println();
773         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Modeling tools: " );
782         if ( TestPccx.test() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix strict: " );
791         if ( Test.testSplitStrict() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Split Matrix: " );
800         if ( Test.testSplit() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Confidence Assessor: " );
809         if ( Test.testConfidenceAssessor() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "Basic table: " );
818         if ( Test.testBasicTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "General table: " );
827         if ( Test.testGeneralTable() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "Amino acid sequence: " );
836         if ( Test.testAminoAcidSequence() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "General MSA parser: " );
845         if ( Test.testGeneralMsaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Fasta parser for msa: " );
854         if ( Test.testFastaParser() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Creation of balanced phylogeny: " );
863         if ( Test.testCreateBalancedPhylogeny() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         System.out.print( "Genbank accessor parsing: " );
872         if ( Test.testGenbankAccessorParsing() ) {
873             System.out.println( "OK." );
874             succeeded++;
875         }
876         else {
877             System.out.println( "failed." );
878             failed++;
879         }
880         String path = "";
881         final String os = ForesterUtil.OS_NAME.toLowerCase();
882         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
883             path = "/usr/local/bin/mafft";
884         }
885         else if ( os.indexOf( "win" ) >= 0 ) {
886             path = "C:\\Program Files\\mafft-win\\mafft.bat";
887         }
888         else {
889             path = "mafft";
890             if ( !MsaInferrer.isInstalled( path ) ) {
891                 path = "/usr/bin/mafft";
892             }
893             if ( !MsaInferrer.isInstalled( path ) ) {
894                 path = "/usr/local/bin/mafft";
895             }
896         }
897         if ( MsaInferrer.isInstalled( path ) ) {
898             System.out.print( "MAFFT (external program): " );
899             if ( Test.testMafft( path ) ) {
900                 System.out.println( "OK." );
901                 succeeded++;
902             }
903             else {
904                 System.out.println( "failed [will not count towards failed tests]" );
905             }
906         }
907         System.out.print( "Next nodes with collapsed: " );
908         if ( Test.testNextNodeWithCollapsing() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Simple MSA quality: " );
917         if ( Test.testMsaQualityMethod() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         System.out.print( "Deleteable MSA: " );
926         if ( Test.testDeleteableMsa() ) {
927             System.out.println( "OK." );
928             succeeded++;
929         }
930         else {
931             System.out.println( "failed." );
932             failed++;
933         }
934         if ( PERFORM_DB_TESTS ) {
935             System.out.print( "Uniprot Entry Retrieval: " );
936             if ( Test.testUniprotEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Ebi Entry Retrieval: " );
945             if ( Test.testEbiEntryRetrieval() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953             System.out.print( "Sequence DB tools 2: " );
954             if ( testSequenceDbWsTools2() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961                 System.exit( -1 );
962             }
963             System.out.print( "Uniprot Taxonomy Search: " );
964             if ( Test.testUniprotTaxonomySearch() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972         }
973         if ( PERFORM_WEB_TREE_ACCESS ) {
974             System.out.print( "NHX parsing from URL: " );
975             if ( Test.testNHXparsingFromURL() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "NHX parsing from URL 2: " );
984             if ( Test.testNHXparsingFromURL2() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             System.out.print( "phyloXML parsing from URL: " );
993             if ( Test.testPhyloXMLparsingFromURL() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             System.out.print( "TreeBase acccess: " );
1002             if ( Test.testTreeBaseReading() ) {
1003                 System.out.println( "OK." );
1004                 succeeded++;
1005             }
1006             else {
1007                 System.out.println( "failed." );
1008                 failed++;
1009             }
1010             //
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             //
1021             System.out.print( "TreeFam access: " );
1022             if ( Test.testTreeFamReading() ) {
1023                 System.out.println( "OK." );
1024                 succeeded++;
1025             }
1026             else {
1027                 System.out.println( "failed." );
1028                 failed++;
1029             }
1030             //
1031             //
1032             System.out.print( "Pfam tree access: " );
1033             if ( Test.testPfamTreeReading() ) {
1034                 System.out.println( "OK." );
1035                 succeeded++;
1036             }
1037             else {
1038                 System.out.println( "failed." );
1039                 failed++;
1040             }
1041         }
1042         System.out.println();
1043         final Runtime rt = java.lang.Runtime.getRuntime();
1044         final long free_memory = rt.freeMemory() / 1000000;
1045         final long total_memory = rt.totalMemory() / 1000000;
1046         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1047                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1048         System.out.println();
1049         System.out.println( "Successful tests: " + succeeded );
1050         System.out.println( "Failed     tests: " + failed );
1051         System.out.println();
1052         if ( failed < 1 ) {
1053             System.out.println( "OK." );
1054         }
1055         else {
1056             System.out.println( "Not OK." );
1057         }
1058     }
1059
1060     public static boolean testEngulfingOverlapRemoval() {
1061         try {
1062             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1063             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1064             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1065             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1067             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1068             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1069             final List<Boolean> covered = new ArrayList<Boolean>();
1070             covered.add( true ); // 0
1071             covered.add( false ); // 1
1072             covered.add( true ); // 2
1073             covered.add( false ); // 3
1074             covered.add( true ); // 4
1075             covered.add( true ); // 5
1076             covered.add( false ); // 6
1077             covered.add( true ); // 7
1078             covered.add( true ); // 8
1079             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1083                 return false;
1084             }
1085             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1086                 return false;
1087             }
1088             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1089                 return false;
1090             }
1091             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1092                 return false;
1093             }
1094             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1095                 return false;
1096             }
1097             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1098                 return false;
1099             }
1100             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1101             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1102             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1103             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1104             abc.addProteinDomain( a );
1105             abc.addProteinDomain( b );
1106             abc.addProteinDomain( c );
1107             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1108             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1109             if ( abc.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1113                 return false;
1114             }
1115             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1116                 return false;
1117             }
1118             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1119                 return false;
1120             }
1121             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1122                 return false;
1123             }
1124             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1126             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1127             final Protein def = new BasicProtein( "def", "nemve", 0 );
1128             def.addProteinDomain( d );
1129             def.addProteinDomain( e );
1130             def.addProteinDomain( f );
1131             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1132             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1133             if ( def.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1140                 return false;
1141             }
1142             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1146                 return false;
1147             }
1148             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1149                 return false;
1150             }
1151         }
1152         catch ( final Exception e ) {
1153             e.printStackTrace( System.out );
1154             return false;
1155         }
1156         return true;
1157     }
1158
1159     public static final boolean testNHXparsingFromURL2() {
1160         try {
1161             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1162             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1163                                                                       false,
1164                                                                       false,
1165                                                                       false,
1166                                                                       TAXONOMY_EXTRACTION.NO,
1167                                                                       false );
1168             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1169                 return false;
1170             }
1171             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1172                 System.out.println( phys[ 0 ].toNewHampshire() );
1173                 return false;
1174             }
1175             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1176                 System.out.println( phys[ 1 ].toNewHampshire() );
1177                 return false;
1178             }
1179             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1180                                                                        false,
1181                                                                        false,
1182                                                                        false,
1183                                                                        TAXONOMY_EXTRACTION.NO,
1184                                                                        false );
1185             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1186                 return false;
1187             }
1188             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1189                 System.out.println( phys2[ 0 ].toNewHampshire() );
1190                 return false;
1191             }
1192             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1193                 System.out.println( phys2[ 1 ].toNewHampshire() );
1194                 return false;
1195             }
1196             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1197                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1198             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1199                 return false;
1200             }
1201             if ( !phys3[ 0 ]
1202                     .toNewHampshire()
1203                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1204                 System.out.println( phys3[ 0 ].toNewHampshire() );
1205                 return false;
1206             }
1207             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1208                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1209             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1210                 return false;
1211             }
1212             if ( !phys4[ 0 ]
1213                     .toNewHampshire()
1214                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1215                 System.out.println( phys4[ 0 ].toNewHampshire() );
1216                 return false;
1217             }
1218         }
1219         catch ( final Exception e ) {
1220             e.printStackTrace();
1221         }
1222         return true;
1223     }
1224
1225     public static final boolean testNHXparsingFromURL() {
1226         try {
1227             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1228             final URL u = new URL( s );
1229             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1230             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1231             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1232                 return false;
1233             }
1234             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1235                 System.out.println( phys[ 0 ].toNewHampshire() );
1236                 return false;
1237             }
1238             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1239                 System.out.println( phys[ 1 ].toNewHampshire() );
1240                 return false;
1241             }
1242             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1243             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1244                 return false;
1245             }
1246             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1247                 System.out.println( phys2[ 0 ].toNewHampshire() );
1248                 return false;
1249             }
1250             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1251             final NHXParser p = new NHXParser();
1252             final URL u2 = new URL( s );
1253             p.setSource( u2 );
1254             if ( !p.hasNext() ) {
1255                 return false;
1256             }
1257             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1258                 return false;
1259             }
1260             if ( !p.hasNext() ) {
1261                 return false;
1262             }
1263             p.reset();
1264             if ( !p.hasNext() ) {
1265                 return false;
1266             }
1267             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1268                 return false;
1269             }
1270             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1271                 return false;
1272             }
1273             p.reset();
1274             if ( !p.hasNext() ) {
1275                 return false;
1276             }
1277             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1278                 return false;
1279             }
1280             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1281                 return false;
1282             }
1283         }
1284         catch ( final Exception e ) {
1285             e.printStackTrace();
1286         }
1287         return true;
1288     }
1289
1290     public static boolean testOverlapRemoval() {
1291         try {
1292             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1293             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1294             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1295             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1296             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1297             final List<Boolean> covered = new ArrayList<Boolean>();
1298             covered.add( true ); // 0
1299             covered.add( false ); // 1
1300             covered.add( true ); // 2
1301             covered.add( false ); // 3
1302             covered.add( true ); // 4
1303             covered.add( true ); // 5
1304             covered.add( false ); // 6
1305             covered.add( true ); // 7
1306             covered.add( true ); // 8
1307             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1308                 return false;
1309             }
1310             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1311                 return false;
1312             }
1313             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1314                 return false;
1315             }
1316             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1317                 return false;
1318             }
1319             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1320                 return false;
1321             }
1322             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1323             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1324             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1325             ab.addProteinDomain( a );
1326             ab.addProteinDomain( b );
1327             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1328             if ( ab.getNumberOfProteinDomains() != 2 ) {
1329                 return false;
1330             }
1331             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1332                 return false;
1333             }
1334             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1335                 return false;
1336             }
1337             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1338             if ( ab.getNumberOfProteinDomains() != 2 ) {
1339                 return false;
1340             }
1341             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1342                 return false;
1343             }
1344             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1345             final Domain d = new BasicDomain( "d",
1346                                               ( short ) 10000,
1347                                               ( short ) 10500,
1348                                               ( short ) 1,
1349                                               ( short ) 1,
1350                                               0.0000001,
1351                                               1 );
1352             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1353             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1354             cde.addProteinDomain( c );
1355             cde.addProteinDomain( d );
1356             cde.addProteinDomain( e );
1357             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1358             if ( cde.getNumberOfProteinDomains() != 3 ) {
1359                 return false;
1360             }
1361             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1362                 return false;
1363             }
1364             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1365             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1366             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1367             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1368             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1369             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1370             fghi.addProteinDomain( f );
1371             fghi.addProteinDomain( g );
1372             fghi.addProteinDomain( h );
1373             fghi.addProteinDomain( i );
1374             fghi.addProteinDomain( i );
1375             fghi.addProteinDomain( i );
1376             fghi.addProteinDomain( i2 );
1377             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1378             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1379                 return false;
1380             }
1381             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1382                 return false;
1383             }
1384             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1385                 return false;
1386             }
1387             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1388             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1389                 return false;
1390             }
1391             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1392                 return false;
1393             }
1394             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1395             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1396             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1397             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1398             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1399             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1400             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1401             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1402             jklm.addProteinDomain( j );
1403             jklm.addProteinDomain( k );
1404             jklm.addProteinDomain( l );
1405             jklm.addProteinDomain( m );
1406             jklm.addProteinDomain( m0 );
1407             jklm.addProteinDomain( m1 );
1408             jklm.addProteinDomain( m2 );
1409             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1410             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1411                 return false;
1412             }
1413             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1414                 return false;
1415             }
1416             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1417                 return false;
1418             }
1419             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1420             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1421                 return false;
1422             }
1423             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1424                 return false;
1425             }
1426             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1427             final Protein od = new BasicProtein( "od", "varanus", 0 );
1428             od.addProteinDomain( only );
1429             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1430             if ( od.getNumberOfProteinDomains() != 1 ) {
1431                 return false;
1432             }
1433             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1434                 return false;
1435             }
1436         }
1437         catch ( final Exception e ) {
1438             e.printStackTrace( System.out );
1439             return false;
1440         }
1441         return true;
1442     }
1443
1444     public static final boolean testPfamTreeReading() {
1445         try {
1446             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1447             final NHXParser parser = new NHXParser();
1448             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1449             parser.setReplaceUnderscores( false );
1450             parser.setGuessRootedness( true );
1451             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1452             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1453             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1454                 return false;
1455             }
1456             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1457                 return false;
1458             }
1459         }
1460         catch ( final Exception e ) {
1461             e.printStackTrace();
1462         }
1463         return true;
1464     }
1465
1466     public static final boolean testPhyloXMLparsingFromURL() {
1467         try {
1468             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1469             final URL u = new URL( s );
1470             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1471             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1472             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1473                 return false;
1474             }
1475         }
1476         catch ( final Exception e ) {
1477             e.printStackTrace();
1478         }
1479         return true;
1480     }
1481
1482     public static final boolean testToLReading() {
1483         try {
1484             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1485             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1486             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1487             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1488                 return false;
1489             }
1490             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1491                 return false;
1492             }
1493             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1494                 return false;
1495             }
1496             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1497                 return false;
1498             }
1499         }
1500         catch ( final Exception e ) {
1501             e.printStackTrace();
1502         }
1503         return true;
1504     }
1505
1506     public static final boolean testTreeBaseReading() {
1507         try {
1508             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1509             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1510             parser.setReplaceUnderscores( true );
1511             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1512             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1513             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1514                 return false;
1515             }
1516             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1517             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1518             parser2.setReplaceUnderscores( true );
1519             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1520             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1521             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1522                 return false;
1523             }
1524         }
1525         catch ( final Exception e ) {
1526             e.printStackTrace();
1527         }
1528         return true;
1529     }
1530
1531     public static final boolean testTreeFamReading() {
1532         try {
1533             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1534             final NHXParser parser = new NHXParser();
1535             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1536             parser.setReplaceUnderscores( false );
1537             parser.setGuessRootedness( true );
1538             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1539             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1540             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1541                 return false;
1542             }
1543             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1544                 return false;
1545             }
1546         }
1547         catch ( final Exception e ) {
1548             e.printStackTrace();
1549         }
1550         return true;
1551     }
1552
1553     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1554         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1555         return p;
1556     }
1557
1558     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1559         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1560     }
1561
1562     private static boolean testAminoAcidSequence() {
1563         try {
1564             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1565             if ( aa1.getLength() != 13 ) {
1566                 return false;
1567             }
1568             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1569                 return false;
1570             }
1571             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1572                 return false;
1573             }
1574             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1575                 return false;
1576             }
1577             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1578             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1579                 return false;
1580             }
1581             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1582             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1583                 return false;
1584             }
1585             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1586             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1587                 return false;
1588             }
1589         }
1590         catch ( final Exception e ) {
1591             e.printStackTrace();
1592             return false;
1593         }
1594         return true;
1595     }
1596
1597     private static boolean testBasicDomain() {
1598         try {
1599             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1600             if ( !pd.getDomainId().equals( "id" ) ) {
1601                 return false;
1602             }
1603             if ( pd.getNumber() != 1 ) {
1604                 return false;
1605             }
1606             if ( pd.getTotalCount() != 4 ) {
1607                 return false;
1608             }
1609             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1610                 return false;
1611             }
1612             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1613             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1614             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1615             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1616             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1617             if ( !a1.equals( a1 ) ) {
1618                 return false;
1619             }
1620             if ( !a1.equals( a1_copy ) ) {
1621                 return false;
1622             }
1623             if ( !a1.equals( a1_equal ) ) {
1624                 return false;
1625             }
1626             if ( !a1.equals( a2 ) ) {
1627                 return false;
1628             }
1629             if ( a1.equals( a3 ) ) {
1630                 return false;
1631             }
1632             if ( a1.compareTo( a1 ) != 0 ) {
1633                 return false;
1634             }
1635             if ( a1.compareTo( a1_copy ) != 0 ) {
1636                 return false;
1637             }
1638             if ( a1.compareTo( a1_equal ) != 0 ) {
1639                 return false;
1640             }
1641             if ( a1.compareTo( a2 ) != 0 ) {
1642                 return false;
1643             }
1644             if ( a1.compareTo( a3 ) == 0 ) {
1645                 return false;
1646             }
1647         }
1648         catch ( final Exception e ) {
1649             e.printStackTrace( System.out );
1650             return false;
1651         }
1652         return true;
1653     }
1654
1655     private static boolean testBasicNodeMethods() {
1656         try {
1657             if ( PhylogenyNode.getNodeCount() != 0 ) {
1658                 return false;
1659             }
1660             final PhylogenyNode n1 = new PhylogenyNode();
1661             final PhylogenyNode n2 = PhylogenyNode
1662                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1663             final PhylogenyNode n3 = PhylogenyNode
1664                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1665             final PhylogenyNode n4 = PhylogenyNode
1666                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1667             if ( n1.isHasAssignedEvent() ) {
1668                 return false;
1669             }
1670             if ( PhylogenyNode.getNodeCount() != 4 ) {
1671                 return false;
1672             }
1673             if ( n3.getIndicator() != 0 ) {
1674                 return false;
1675             }
1676             if ( n3.getNumberOfExternalNodes() != 1 ) {
1677                 return false;
1678             }
1679             if ( !n3.isExternal() ) {
1680                 return false;
1681             }
1682             if ( !n3.isRoot() ) {
1683                 return false;
1684             }
1685             if ( !n4.getName().equals( "n4" ) ) {
1686                 return false;
1687             }
1688         }
1689         catch ( final Exception e ) {
1690             e.printStackTrace( System.out );
1691             return false;
1692         }
1693         return true;
1694     }
1695
1696     private static boolean testBasicPhyloXMLparsing() {
1697         try {
1698             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1699             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1700             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1701                                                               xml_parser );
1702             if ( xml_parser.getErrorCount() > 0 ) {
1703                 System.out.println( xml_parser.getErrorMessages().toString() );
1704                 return false;
1705             }
1706             if ( phylogenies_0.length != 4 ) {
1707                 return false;
1708             }
1709             final Phylogeny t1 = phylogenies_0[ 0 ];
1710             final Phylogeny t2 = phylogenies_0[ 1 ];
1711             final Phylogeny t3 = phylogenies_0[ 2 ];
1712             final Phylogeny t4 = phylogenies_0[ 3 ];
1713             if ( t1.getNumberOfExternalNodes() != 1 ) {
1714                 return false;
1715             }
1716             if ( !t1.isRooted() ) {
1717                 return false;
1718             }
1719             if ( t1.isRerootable() ) {
1720                 return false;
1721             }
1722             if ( !t1.getType().equals( "gene_tree" ) ) {
1723                 return false;
1724             }
1725             if ( t2.getNumberOfExternalNodes() != 2 ) {
1726                 return false;
1727             }
1728             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1729                 return false;
1730             }
1731             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1732                 return false;
1733             }
1734             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1735                 return false;
1736             }
1737             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1738                 return false;
1739             }
1740             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1741                 return false;
1742             }
1743             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1744                 return false;
1745             }
1746             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1747                     .startsWith( "actgtgggggt" ) ) {
1748                 return false;
1749             }
1750             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1751                     .startsWith( "ctgtgatgcat" ) ) {
1752                 return false;
1753             }
1754             if ( t3.getNumberOfExternalNodes() != 4 ) {
1755                 return false;
1756             }
1757             if ( !t1.getName().equals( "t1" ) ) {
1758                 return false;
1759             }
1760             if ( !t2.getName().equals( "t2" ) ) {
1761                 return false;
1762             }
1763             if ( !t3.getName().equals( "t3" ) ) {
1764                 return false;
1765             }
1766             if ( !t4.getName().equals( "t4" ) ) {
1767                 return false;
1768             }
1769             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1770                 return false;
1771             }
1772             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1773                 return false;
1774             }
1775             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1776                 return false;
1777             }
1778             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1779                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1780                 return false;
1781             }
1782             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1783                 return false;
1784             }
1785             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1786                 return false;
1787             }
1788             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1789                 return false;
1790             }
1791             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1792                     .equals( "apoptosis" ) ) {
1793                 return false;
1794             }
1795             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1796                     .equals( "GO:0006915" ) ) {
1797                 return false;
1798             }
1799             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1800                     .equals( "UniProtKB" ) ) {
1801                 return false;
1802             }
1803             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1804                     .equals( "experimental" ) ) {
1805                 return false;
1806             }
1807             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1808                     .equals( "function" ) ) {
1809                 return false;
1810             }
1811             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1812                     .getValue() != 1 ) {
1813                 return false;
1814             }
1815             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1816                     .getType().equals( "ml" ) ) {
1817                 return false;
1818             }
1819             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1820                     .equals( "apoptosis" ) ) {
1821                 return false;
1822             }
1823             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1824                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1825                 return false;
1826             }
1827             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1828                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1829                 return false;
1830             }
1831             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1832                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1833                 return false;
1834             }
1835             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1836                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1837                 return false;
1838             }
1839             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1840                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1841                 return false;
1842             }
1843             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1844                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1845                 return false;
1846             }
1847             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1848                     .equals( "GO:0005829" ) ) {
1849                 return false;
1850             }
1851             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1852                     .equals( "intracellular organelle" ) ) {
1853                 return false;
1854             }
1855             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1856                 return false;
1857             }
1858             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1859                     .equals( "UniProt link" ) ) ) {
1860                 return false;
1861             }
1862             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1863                 return false;
1864             }
1865             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1866             if ( x.size() != 4 ) {
1867                 return false;
1868             }
1869             int c = 0;
1870             for( final Accession acc : x ) {
1871                 if ( c == 0 ) {
1872                     if ( !acc.getSource().equals( "KEGG" ) ) {
1873                         return false;
1874                     }
1875                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1876                         return false;
1877                     }
1878                 }
1879                 c++;
1880             }
1881         }
1882         catch ( final Exception e ) {
1883             e.printStackTrace( System.out );
1884             return false;
1885         }
1886         return true;
1887     }
1888
1889     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1890         try {
1891             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1892             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1893             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1894                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1895             }
1896             else {
1897                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1898             }
1899             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1900                                                               xml_parser );
1901             if ( xml_parser.getErrorCount() > 0 ) {
1902                 System.out.println( xml_parser.getErrorMessages().toString() );
1903                 return false;
1904             }
1905             if ( phylogenies_0.length != 4 ) {
1906                 return false;
1907             }
1908             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1909             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1910             if ( phylogenies_t1.length != 1 ) {
1911                 return false;
1912             }
1913             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1914             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1915                 return false;
1916             }
1917             if ( !t1_rt.isRooted() ) {
1918                 return false;
1919             }
1920             if ( t1_rt.isRerootable() ) {
1921                 return false;
1922             }
1923             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1924                 return false;
1925             }
1926             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1927             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1928             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1929             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1930                 return false;
1931             }
1932             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1933                 return false;
1934             }
1935             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1936                 return false;
1937             }
1938             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1939                 return false;
1940             }
1941             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1942                     .startsWith( "actgtgggggt" ) ) {
1943                 return false;
1944             }
1945             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1946                     .startsWith( "ctgtgatgcat" ) ) {
1947                 return false;
1948             }
1949             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1950             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1951             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1952             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1953             if ( phylogenies_1.length != 1 ) {
1954                 return false;
1955             }
1956             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1957             if ( !t3_rt.getName().equals( "t3" ) ) {
1958                 return false;
1959             }
1960             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1961                 return false;
1962             }
1963             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1964                 return false;
1965             }
1966             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1967                 return false;
1968             }
1969             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1970                 return false;
1971             }
1972             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1973                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1974                 return false;
1975             }
1976             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1977                 return false;
1978             }
1979             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1980                 return false;
1981             }
1982             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1983                     .equals( "UniProtKB" ) ) {
1984                 return false;
1985             }
1986             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1987                     .equals( "apoptosis" ) ) {
1988                 return false;
1989             }
1990             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1991                     .equals( "GO:0006915" ) ) {
1992                 return false;
1993             }
1994             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1995                     .equals( "UniProtKB" ) ) {
1996                 return false;
1997             }
1998             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1999                     .equals( "experimental" ) ) {
2000                 return false;
2001             }
2002             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2003                     .equals( "function" ) ) {
2004                 return false;
2005             }
2006             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2007                     .getValue() != 1 ) {
2008                 return false;
2009             }
2010             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2011                     .getType().equals( "ml" ) ) {
2012                 return false;
2013             }
2014             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2015                     .equals( "apoptosis" ) ) {
2016                 return false;
2017             }
2018             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2019                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2020                 return false;
2021             }
2022             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2023                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2024                 return false;
2025             }
2026             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2027                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2028                 return false;
2029             }
2030             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2031                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2032                 return false;
2033             }
2034             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2035                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2036                 return false;
2037             }
2038             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2039                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2040                 return false;
2041             }
2042             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2043                     .equals( "GO:0005829" ) ) {
2044                 return false;
2045             }
2046             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2047                     .equals( "intracellular organelle" ) ) {
2048                 return false;
2049             }
2050             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2051                 return false;
2052             }
2053             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2054                     .equals( "UniProt link" ) ) ) {
2055                 return false;
2056             }
2057             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2058                 return false;
2059             }
2060             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2061                 return false;
2062             }
2063             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2064                     .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." ) ) ) {
2065                 return false;
2066             }
2067             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2068                 return false;
2069             }
2070             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2071                 return false;
2072             }
2073             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2074                 return false;
2075             }
2076             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2077                 return false;
2078             }
2079             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2080                     .equals( "ncbi" ) ) {
2081                 return false;
2082             }
2083             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2087                     .getName().equals( "B" ) ) {
2088                 return false;
2089             }
2090             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2091                     .getFrom() != 21 ) {
2092                 return false;
2093             }
2094             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2095                 return false;
2096             }
2097             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2098                     .getLength() != 24 ) {
2099                 return false;
2100             }
2101             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2102                     .getConfidence() != 2144 ) {
2103                 return false;
2104             }
2105             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2106                     .equals( "pfam" ) ) {
2107                 return false;
2108             }
2109             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2110                 return false;
2111             }
2112             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2113                 return false;
2114             }
2115             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2116                 return false;
2117             }
2118             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2119                 return false;
2120             }
2121             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2122             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2123                 return false;
2124             }
2125             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2126                 return false;
2127             }
2128             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2129                 return false;
2130             }
2131             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2132                 return false;
2133             }
2134             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2135                 return false;
2136             }
2137             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2138                 return false;
2139             }
2140             if ( taxbb.getSynonyms().size() != 2 ) {
2141                 return false;
2142             }
2143             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2144                 return false;
2145             }
2146             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2147                 return false;
2148             }
2149             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2150                 return false;
2151             }
2152             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2153                 return false;
2154             }
2155             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2156                 return false;
2157             }
2158             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2159                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2160                 return false;
2161             }
2162             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2163                 return false;
2164             }
2165             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2166                 return false;
2167             }
2168             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2169                 return false;
2170             }
2171             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2172                 return false;
2173             }
2174             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2175                 return false;
2176             }
2177             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2178                 return false;
2179             }
2180             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2181                 return false;
2182             }
2183             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2184                 return false;
2185             }
2186             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2187                     .equalsIgnoreCase( "435" ) ) {
2188                 return false;
2189             }
2190             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2191                 return false;
2192             }
2193             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2194                     .equalsIgnoreCase( "443.7" ) ) {
2195                 return false;
2196             }
2197             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2198                 return false;
2199             }
2200             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2201                 return false;
2202             }
2203             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2204                     .equalsIgnoreCase( "433" ) ) {
2205                 return false;
2206             }
2207             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2208                     .getCrossReferences();
2209             if ( x.size() != 4 ) {
2210                 return false;
2211             }
2212             int c = 0;
2213             for( final Accession acc : x ) {
2214                 if ( c == 0 ) {
2215                     if ( !acc.getSource().equals( "KEGG" ) ) {
2216                         return false;
2217                     }
2218                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2219                         return false;
2220                     }
2221                 }
2222                 c++;
2223             }
2224         }
2225         catch ( final Exception e ) {
2226             e.printStackTrace( System.out );
2227             return false;
2228         }
2229         return true;
2230     }
2231
2232     private static boolean testBasicPhyloXMLparsingValidating() {
2233         try {
2234             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2235             PhyloXmlParser xml_parser = null;
2236             try {
2237                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2238             }
2239             catch ( final Exception e ) {
2240                 // Do nothing -- means were not running from jar.
2241             }
2242             if ( xml_parser == null ) {
2243                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2244                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2245                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2246                 }
2247                 else {
2248                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2249                 }
2250             }
2251             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2252                                                               xml_parser );
2253             if ( xml_parser.getErrorCount() > 0 ) {
2254                 System.out.println( xml_parser.getErrorMessages().toString() );
2255                 return false;
2256             }
2257             if ( phylogenies_0.length != 4 ) {
2258                 return false;
2259             }
2260             final Phylogeny t1 = phylogenies_0[ 0 ];
2261             final Phylogeny t2 = phylogenies_0[ 1 ];
2262             final Phylogeny t3 = phylogenies_0[ 2 ];
2263             final Phylogeny t4 = phylogenies_0[ 3 ];
2264             if ( !t1.getName().equals( "t1" ) ) {
2265                 return false;
2266             }
2267             if ( !t2.getName().equals( "t2" ) ) {
2268                 return false;
2269             }
2270             if ( !t3.getName().equals( "t3" ) ) {
2271                 return false;
2272             }
2273             if ( !t4.getName().equals( "t4" ) ) {
2274                 return false;
2275             }
2276             if ( t1.getNumberOfExternalNodes() != 1 ) {
2277                 return false;
2278             }
2279             if ( t2.getNumberOfExternalNodes() != 2 ) {
2280                 return false;
2281             }
2282             if ( t3.getNumberOfExternalNodes() != 4 ) {
2283                 return false;
2284             }
2285             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2286             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2287             if ( xml_parser.getErrorCount() > 0 ) {
2288                 System.out.println( "errors:" );
2289                 System.out.println( xml_parser.getErrorMessages().toString() );
2290                 return false;
2291             }
2292             if ( phylogenies_1.length != 4 ) {
2293                 return false;
2294             }
2295             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2296                                                               xml_parser );
2297             if ( xml_parser.getErrorCount() > 0 ) {
2298                 System.out.println( "errors:" );
2299                 System.out.println( xml_parser.getErrorMessages().toString() );
2300                 return false;
2301             }
2302             if ( phylogenies_2.length != 1 ) {
2303                 return false;
2304             }
2305             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2306                 return false;
2307             }
2308             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2309                                                               xml_parser );
2310             if ( xml_parser.getErrorCount() > 0 ) {
2311                 System.out.println( xml_parser.getErrorMessages().toString() );
2312                 return false;
2313             }
2314             if ( phylogenies_3.length != 2 ) {
2315                 return false;
2316             }
2317             final Phylogeny a = phylogenies_3[ 0 ];
2318             if ( !a.getName().equals( "tree 4" ) ) {
2319                 return false;
2320             }
2321             if ( a.getNumberOfExternalNodes() != 3 ) {
2322                 return false;
2323             }
2324             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2325                 return false;
2326             }
2327             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2328                 return false;
2329             }
2330             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2331                                                               xml_parser );
2332             if ( xml_parser.getErrorCount() > 0 ) {
2333                 System.out.println( xml_parser.getErrorMessages().toString() );
2334                 return false;
2335             }
2336             if ( phylogenies_4.length != 1 ) {
2337                 return false;
2338             }
2339             final Phylogeny s = phylogenies_4[ 0 ];
2340             if ( s.getNumberOfExternalNodes() != 6 ) {
2341                 return false;
2342             }
2343             s.getNode( "first" );
2344             s.getNode( "<>" );
2345             s.getNode( "\"<a'b&c'd\">\"" );
2346             s.getNode( "'''\"" );
2347             s.getNode( "\"\"\"" );
2348             s.getNode( "dick & doof" );
2349         }
2350         catch ( final Exception e ) {
2351             e.printStackTrace( System.out );
2352             return false;
2353         }
2354         return true;
2355     }
2356
2357     private static boolean testBasicProtein() {
2358         try {
2359             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2360             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             p0.addProteinDomain( y );
2368             p0.addProteinDomain( e );
2369             p0.addProteinDomain( b );
2370             p0.addProteinDomain( c );
2371             p0.addProteinDomain( d );
2372             p0.addProteinDomain( a );
2373             p0.addProteinDomain( x );
2374             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2375                 return false;
2376             }
2377             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2378                 return false;
2379             }
2380             //
2381             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2382             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2383             aa0.addProteinDomain( a1 );
2384             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2385                 return false;
2386             }
2387             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2388                 return false;
2389             }
2390             //
2391             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2392             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2393             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2394             aa1.addProteinDomain( a11 );
2395             aa1.addProteinDomain( a12 );
2396             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2397                 return false;
2398             }
2399             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2400                 return false;
2401             }
2402             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2403             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2404                 return false;
2405             }
2406             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2407                 return false;
2408             }
2409             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2410                 return false;
2411             }
2412             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2413             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2414                 return false;
2415             }
2416             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2417                 return false;
2418             }
2419             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2420                 return false;
2421             }
2422             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2423                 return false;
2424             }
2425             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2426             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2427                 return false;
2428             }
2429             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2430                 return false;
2431             }
2432             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2433                 return false;
2434             }
2435             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2436                 return false;
2437             }
2438             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2439             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2440                 return false;
2441             }
2442             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2443                 return false;
2444             }
2445             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2446                 return false;
2447             }
2448             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2449                 return false;
2450             }
2451             //
2452             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2453             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2454             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2455             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2456             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2457             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2458             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2459             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2460             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2461             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2462             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2463             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2464             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2465             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2466             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2467             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2468             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2469             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2470             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2471             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2472             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2473             p00.addProteinDomain( y0 );
2474             p00.addProteinDomain( e0 );
2475             p00.addProteinDomain( b0 );
2476             p00.addProteinDomain( c0 );
2477             p00.addProteinDomain( d0 );
2478             p00.addProteinDomain( a0 );
2479             p00.addProteinDomain( x0 );
2480             p00.addProteinDomain( y1 );
2481             p00.addProteinDomain( y2 );
2482             p00.addProteinDomain( y3 );
2483             p00.addProteinDomain( e1 );
2484             p00.addProteinDomain( e2 );
2485             p00.addProteinDomain( e3 );
2486             p00.addProteinDomain( e4 );
2487             p00.addProteinDomain( e5 );
2488             p00.addProteinDomain( z0 );
2489             p00.addProteinDomain( z1 );
2490             p00.addProteinDomain( z2 );
2491             p00.addProteinDomain( zz0 );
2492             p00.addProteinDomain( zz1 );
2493             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2494                 return false;
2495             }
2496             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2497                 return false;
2498             }
2499             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2500                 return false;
2501             }
2502             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2503                 return false;
2504             }
2505             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" ) ) {
2506                 return false;
2507             }
2508             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2509             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2510             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2511             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2512             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2513             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2514             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2515             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2516             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2517             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2518             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2519             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2520             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2521             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2522             p.addProteinDomain( B15 );
2523             p.addProteinDomain( C50 );
2524             p.addProteinDomain( A60 );
2525             p.addProteinDomain( A30 );
2526             p.addProteinDomain( C70 );
2527             p.addProteinDomain( B35 );
2528             p.addProteinDomain( B40 );
2529             p.addProteinDomain( A0 );
2530             p.addProteinDomain( A10 );
2531             p.addProteinDomain( A20 );
2532             p.addProteinDomain( B25 );
2533             p.addProteinDomain( D80 );
2534             List<String> domains_ids = new ArrayList<String>();
2535             domains_ids.add( "A" );
2536             domains_ids.add( "B" );
2537             domains_ids.add( "C" );
2538             if ( !p.contains( domains_ids, false ) ) {
2539                 return false;
2540             }
2541             if ( !p.contains( domains_ids, true ) ) {
2542                 return false;
2543             }
2544             domains_ids.add( "X" );
2545             if ( p.contains( domains_ids, false ) ) {
2546                 return false;
2547             }
2548             if ( p.contains( domains_ids, true ) ) {
2549                 return false;
2550             }
2551             domains_ids = new ArrayList<String>();
2552             domains_ids.add( "A" );
2553             domains_ids.add( "C" );
2554             domains_ids.add( "D" );
2555             if ( !p.contains( domains_ids, false ) ) {
2556                 return false;
2557             }
2558             if ( !p.contains( domains_ids, true ) ) {
2559                 return false;
2560             }
2561             domains_ids = new ArrayList<String>();
2562             domains_ids.add( "A" );
2563             domains_ids.add( "D" );
2564             domains_ids.add( "C" );
2565             if ( !p.contains( domains_ids, false ) ) {
2566                 return false;
2567             }
2568             if ( p.contains( domains_ids, true ) ) {
2569                 return false;
2570             }
2571             domains_ids = new ArrayList<String>();
2572             domains_ids.add( "A" );
2573             domains_ids.add( "A" );
2574             domains_ids.add( "B" );
2575             if ( !p.contains( domains_ids, false ) ) {
2576                 return false;
2577             }
2578             if ( !p.contains( domains_ids, true ) ) {
2579                 return false;
2580             }
2581             domains_ids = new ArrayList<String>();
2582             domains_ids.add( "A" );
2583             domains_ids.add( "A" );
2584             domains_ids.add( "A" );
2585             domains_ids.add( "B" );
2586             domains_ids.add( "B" );
2587             if ( !p.contains( domains_ids, false ) ) {
2588                 return false;
2589             }
2590             if ( !p.contains( domains_ids, true ) ) {
2591                 return false;
2592             }
2593             domains_ids = new ArrayList<String>();
2594             domains_ids.add( "A" );
2595             domains_ids.add( "A" );
2596             domains_ids.add( "B" );
2597             domains_ids.add( "A" );
2598             domains_ids.add( "B" );
2599             domains_ids.add( "B" );
2600             domains_ids.add( "A" );
2601             domains_ids.add( "B" );
2602             domains_ids.add( "C" );
2603             domains_ids.add( "A" );
2604             domains_ids.add( "C" );
2605             domains_ids.add( "D" );
2606             if ( !p.contains( domains_ids, false ) ) {
2607                 return false;
2608             }
2609             if ( p.contains( domains_ids, true ) ) {
2610                 return false;
2611             }
2612         }
2613         catch ( final Exception e ) {
2614             e.printStackTrace( System.out );
2615             return false;
2616         }
2617         return true;
2618     }
2619
2620     private static boolean testBasicTable() {
2621         try {
2622             final BasicTable<String> t0 = new BasicTable<String>();
2623             if ( t0.getNumberOfColumns() != 0 ) {
2624                 return false;
2625             }
2626             if ( t0.getNumberOfRows() != 0 ) {
2627                 return false;
2628             }
2629             t0.setValue( 3, 2, "23" );
2630             t0.setValue( 10, 1, "error" );
2631             t0.setValue( 10, 1, "110" );
2632             t0.setValue( 9, 1, "19" );
2633             t0.setValue( 1, 10, "101" );
2634             t0.setValue( 10, 10, "1010" );
2635             t0.setValue( 100, 10, "10100" );
2636             t0.setValue( 0, 0, "00" );
2637             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2638                 return false;
2639             }
2640             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2641                 return false;
2642             }
2643             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2644                 return false;
2645             }
2646             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2647                 return false;
2648             }
2649             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2650                 return false;
2651             }
2652             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2653                 return false;
2654             }
2655             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2656                 return false;
2657             }
2658             if ( t0.getNumberOfColumns() != 101 ) {
2659                 return false;
2660             }
2661             if ( t0.getNumberOfRows() != 11 ) {
2662                 return false;
2663             }
2664             if ( t0.getValueAsString( 49, 4 ) != null ) {
2665                 return false;
2666             }
2667             final String l = ForesterUtil.getLineSeparator();
2668             final StringBuffer source = new StringBuffer();
2669             source.append( "" + l );
2670             source.append( "# 1 1 1 1 1 1 1 1" + l );
2671             source.append( " 00 01 02 03" + l );
2672             source.append( "   10 11 12 13  " + l );
2673             source.append( "20 21 22 23 " + l );
2674             source.append( "    30  31    32 33" + l );
2675             source.append( "40 41 42 43" + l );
2676             source.append( "  # 1 1 1 1 1 " + l );
2677             source.append( "50 51 52 53 54" + l );
2678             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2679             if ( t1.getNumberOfColumns() != 5 ) {
2680                 return false;
2681             }
2682             if ( t1.getNumberOfRows() != 6 ) {
2683                 return false;
2684             }
2685             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2686                 return false;
2687             }
2688             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2689                 return false;
2690             }
2691             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2692                 return false;
2693             }
2694             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2695                 return false;
2696             }
2697             final StringBuffer source1 = new StringBuffer();
2698             source1.append( "" + l );
2699             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2700             source1.append( " 00; 01 ;02;03" + l );
2701             source1.append( "   10; 11; 12; 13  " + l );
2702             source1.append( "20; 21; 22; 23 " + l );
2703             source1.append( "    30;  31;    32; 33" + l );
2704             source1.append( "40;41;42;43" + l );
2705             source1.append( "  # 1 1 1 1 1 " + l );
2706             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2707             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2708             if ( t2.getNumberOfColumns() != 5 ) {
2709                 return false;
2710             }
2711             if ( t2.getNumberOfRows() != 6 ) {
2712                 return false;
2713             }
2714             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2715                 return false;
2716             }
2717             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2718                 return false;
2719             }
2720             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2721                 return false;
2722             }
2723             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2724                 return false;
2725             }
2726             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2727                 return false;
2728             }
2729             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2730                 return false;
2731             }
2732             final StringBuffer source2 = new StringBuffer();
2733             source2.append( "" + l );
2734             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2735             source2.append( " 00; 01 ;02;03" + l );
2736             source2.append( "   10; 11; 12; 13  " + l );
2737             source2.append( "20; 21; 22; 23 " + l );
2738             source2.append( "                     " + l );
2739             source2.append( "    30;  31;    32; 33" + l );
2740             source2.append( "40;41;42;43" + l );
2741             source2.append( "  comment: 1 1 1 1 1 " + l );
2742             source2.append( ";;;50  ;   52; 53;;54   " + l );
2743             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2744                                                                         ';',
2745                                                                         false,
2746                                                                         false,
2747                                                                         "comment:",
2748                                                                         false );
2749             if ( tl.size() != 2 ) {
2750                 return false;
2751             }
2752             final BasicTable<String> t3 = tl.get( 0 );
2753             final BasicTable<String> t4 = tl.get( 1 );
2754             if ( t3.getNumberOfColumns() != 4 ) {
2755                 return false;
2756             }
2757             if ( t3.getNumberOfRows() != 3 ) {
2758                 return false;
2759             }
2760             if ( t4.getNumberOfColumns() != 4 ) {
2761                 return false;
2762             }
2763             if ( t4.getNumberOfRows() != 3 ) {
2764                 return false;
2765             }
2766             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2767                 return false;
2768             }
2769             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2770                 return false;
2771             }
2772         }
2773         catch ( final Exception e ) {
2774             e.printStackTrace( System.out );
2775             return false;
2776         }
2777         return true;
2778     }
2779
2780     private static boolean testBasicTolXMLparsing() {
2781         try {
2782             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2783             final TolParser parser = new TolParser();
2784             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2785             if ( parser.getErrorCount() > 0 ) {
2786                 System.out.println( parser.getErrorMessages().toString() );
2787                 return false;
2788             }
2789             if ( phylogenies_0.length != 1 ) {
2790                 return false;
2791             }
2792             final Phylogeny t1 = phylogenies_0[ 0 ];
2793             if ( t1.getNumberOfExternalNodes() != 5 ) {
2794                 return false;
2795             }
2796             if ( !t1.isRooted() ) {
2797                 return false;
2798             }
2799             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2800                 return false;
2801             }
2802             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2803                 return false;
2804             }
2805             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2806                 return false;
2807             }
2808             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2809                 return false;
2810             }
2811             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2812             if ( parser.getErrorCount() > 0 ) {
2813                 System.out.println( parser.getErrorMessages().toString() );
2814                 return false;
2815             }
2816             if ( phylogenies_1.length != 1 ) {
2817                 return false;
2818             }
2819             final Phylogeny t2 = phylogenies_1[ 0 ];
2820             if ( t2.getNumberOfExternalNodes() != 664 ) {
2821                 return false;
2822             }
2823             if ( !t2.isRooted() ) {
2824                 return false;
2825             }
2826             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2827                 return false;
2828             }
2829             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2830                 return false;
2831             }
2832             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2833                 return false;
2834             }
2835             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2836                 return false;
2837             }
2838             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2839                 return false;
2840             }
2841             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2842                     .equals( "Aquifex" ) ) {
2843                 return false;
2844             }
2845             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2846             if ( parser.getErrorCount() > 0 ) {
2847                 System.out.println( parser.getErrorMessages().toString() );
2848                 return false;
2849             }
2850             if ( phylogenies_2.length != 1 ) {
2851                 return false;
2852             }
2853             final Phylogeny t3 = phylogenies_2[ 0 ];
2854             if ( t3.getNumberOfExternalNodes() != 184 ) {
2855                 return false;
2856             }
2857             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2858                 return false;
2859             }
2860             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2861                 return false;
2862             }
2863             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2864                 return false;
2865             }
2866             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2867             if ( parser.getErrorCount() > 0 ) {
2868                 System.out.println( parser.getErrorMessages().toString() );
2869                 return false;
2870             }
2871             if ( phylogenies_3.length != 1 ) {
2872                 return false;
2873             }
2874             final Phylogeny t4 = phylogenies_3[ 0 ];
2875             if ( t4.getNumberOfExternalNodes() != 1 ) {
2876                 return false;
2877             }
2878             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2879                 return false;
2880             }
2881             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2882                 return false;
2883             }
2884             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2885                 return false;
2886             }
2887             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2888             if ( parser.getErrorCount() > 0 ) {
2889                 System.out.println( parser.getErrorMessages().toString() );
2890                 return false;
2891             }
2892             if ( phylogenies_4.length != 1 ) {
2893                 return false;
2894             }
2895             final Phylogeny t5 = phylogenies_4[ 0 ];
2896             if ( t5.getNumberOfExternalNodes() != 13 ) {
2897                 return false;
2898             }
2899             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2900                 return false;
2901             }
2902             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2903                 return false;
2904             }
2905             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2906                 return false;
2907             }
2908         }
2909         catch ( final Exception e ) {
2910             e.printStackTrace( System.out );
2911             return false;
2912         }
2913         return true;
2914     }
2915
2916     private static boolean testBasicTreeMethods() {
2917         try {
2918             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2919             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2920             if ( t2.getNumberOfExternalNodes() != 4 ) {
2921                 return false;
2922             }
2923             if ( t2.getHeight() != 8.5 ) {
2924                 return false;
2925             }
2926             if ( !t2.isCompletelyBinary() ) {
2927                 return false;
2928             }
2929             if ( t2.isEmpty() ) {
2930                 return false;
2931             }
2932             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2933             if ( t3.getNumberOfExternalNodes() != 5 ) {
2934                 return false;
2935             }
2936             if ( t3.getHeight() != 11 ) {
2937                 return false;
2938             }
2939             if ( t3.isCompletelyBinary() ) {
2940                 return false;
2941             }
2942             final PhylogenyNode n = t3.getNode( "ABC" );
2943             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 ];
2944             if ( t4.getNumberOfExternalNodes() != 9 ) {
2945                 return false;
2946             }
2947             if ( t4.getHeight() != 11 ) {
2948                 return false;
2949             }
2950             if ( t4.isCompletelyBinary() ) {
2951                 return false;
2952             }
2953             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)" );
2954             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2955             if ( t5.getNumberOfExternalNodes() != 8 ) {
2956                 return false;
2957             }
2958             if ( t5.getHeight() != 15 ) {
2959                 return false;
2960             }
2961             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)" );
2962             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2963             if ( t6.getHeight() != 15 ) {
2964                 return false;
2965             }
2966             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)" );
2967             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2968             if ( t7.getHeight() != 15 ) {
2969                 return false;
2970             }
2971             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)" );
2972             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2973             if ( t8.getNumberOfExternalNodes() != 10 ) {
2974                 return false;
2975             }
2976             if ( t8.getHeight() != 15 ) {
2977                 return false;
2978             }
2979             final char[] a9 = new char[] { 'a' };
2980             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2981             if ( t9.getHeight() != 0 ) {
2982                 return false;
2983             }
2984             final char[] a10 = new char[] { 'a', ':', '6' };
2985             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2986             if ( t10.getHeight() != 6 ) {
2987                 return false;
2988             }
2989         }
2990         catch ( final Exception e ) {
2991             e.printStackTrace( System.out );
2992             return false;
2993         }
2994         return true;
2995     }
2996
2997     private static boolean testConfidenceAssessor() {
2998         try {
2999             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3000             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3001             final Phylogeny[] ev0 = factory
3002                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3003                              new NHXParser() );
3004             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3005             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3006                 return false;
3007             }
3008             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3009                 return false;
3010             }
3011             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3012             final Phylogeny[] ev1 = factory
3013                     .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)));",
3014                              new NHXParser() );
3015             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3016             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3017                 return false;
3018             }
3019             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3020                 return false;
3021             }
3022             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3023             final Phylogeny[] ev_b = factory
3024                     .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",
3025                              new NHXParser() );
3026             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3027             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3028                 return false;
3029             }
3030             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3031                 return false;
3032             }
3033             //
3034             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3035             final Phylogeny[] ev1x = factory
3036                     .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)));",
3037                              new NHXParser() );
3038             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3039             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3040                 return false;
3041             }
3042             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3043                 return false;
3044             }
3045             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3046             final Phylogeny[] ev_bx = factory
3047                     .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",
3048                              new NHXParser() );
3049             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3050             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3051                 return false;
3052             }
3053             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3054                 return false;
3055             }
3056             final Phylogeny[] t2 = factory
3057                     .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);",
3058                              new NHXParser() );
3059             final Phylogeny[] ev2 = factory
3060                     .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);",
3061                              new NHXParser() );
3062             for( final Phylogeny target : t2 ) {
3063                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3064             }
3065             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3066                                                  new NHXParser() )[ 0 ];
3067             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3068             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3069             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3070                 return false;
3071             }
3072             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3073                 return false;
3074             }
3075             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3076                 return false;
3077             }
3078         }
3079         catch ( final Exception e ) {
3080             e.printStackTrace();
3081             return false;
3082         }
3083         return true;
3084     }
3085
3086     private static boolean testCopyOfNodeData() {
3087         try {
3088             final PhylogenyNode n1 = PhylogenyNode
3089                     .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]" );
3090             final PhylogenyNode n2 = n1.copyNodeData();
3091             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3092                 return false;
3093             }
3094         }
3095         catch ( final Exception e ) {
3096             e.printStackTrace();
3097             return false;
3098         }
3099         return true;
3100     }
3101
3102     private static boolean testCreateBalancedPhylogeny() {
3103         try {
3104             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3105             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3106                 return false;
3107             }
3108             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3109                 return false;
3110             }
3111             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3112             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3113                 return false;
3114             }
3115             if ( p1.getNumberOfExternalNodes() != 100 ) {
3116                 return false;
3117             }
3118         }
3119         catch ( final Exception e ) {
3120             e.printStackTrace();
3121             return false;
3122         }
3123         return true;
3124     }
3125
3126     private static boolean testCreateUriForSeqWeb() {
3127         try {
3128             final PhylogenyNode n = new PhylogenyNode();
3129             n.setName( "tr|B3RJ64" );
3130             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3131                 return false;
3132             }
3133             n.setName( "B0LM41_HUMAN" );
3134             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3135                 return false;
3136             }
3137             n.setName( "NP_001025424" );
3138             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3139                 return false;
3140             }
3141             n.setName( "_NM_001030253-" );
3142             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3143                 return false;
3144             }
3145             n.setName( "XM_002122186" );
3146             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3147                 return false;
3148             }
3149             n.setName( "dgh_AAA34956_gdg" );
3150             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3151                 return false;
3152             }
3153             n.setName( "AAA34956" );
3154             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3155                 return false;
3156             }
3157             n.setName( "GI:394892" );
3158             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3159                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3160                 return false;
3161             }
3162             n.setName( "gi_394892" );
3163             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3164                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3165                 return false;
3166             }
3167             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3168             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3169                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3170                 return false;
3171             }
3172             n.setName( "P12345" );
3173             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3174                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3175                 return false;
3176             }
3177             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3178             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3179                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3180                 return false;
3181             }
3182         }
3183         catch ( final Exception e ) {
3184             e.printStackTrace( System.out );
3185             return false;
3186         }
3187         return true;
3188     }
3189
3190     private static boolean testDataObjects() {
3191         try {
3192             final Confidence s0 = new Confidence();
3193             final Confidence s1 = new Confidence();
3194             if ( !s0.isEqual( s1 ) ) {
3195                 return false;
3196             }
3197             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3198             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3199             if ( s2.isEqual( s1 ) ) {
3200                 return false;
3201             }
3202             if ( !s2.isEqual( s3 ) ) {
3203                 return false;
3204             }
3205             final Confidence s4 = ( Confidence ) s3.copy();
3206             if ( !s4.isEqual( s3 ) ) {
3207                 return false;
3208             }
3209             s3.asSimpleText();
3210             s3.asText();
3211             // Taxonomy
3212             // ----------
3213             final Taxonomy t1 = new Taxonomy();
3214             final Taxonomy t2 = new Taxonomy();
3215             final Taxonomy t3 = new Taxonomy();
3216             final Taxonomy t4 = new Taxonomy();
3217             final Taxonomy t5 = new Taxonomy();
3218             t1.setIdentifier( new Identifier( "ecoli" ) );
3219             t1.setTaxonomyCode( "ECOLI" );
3220             t1.setScientificName( "E. coli" );
3221             t1.setCommonName( "coli" );
3222             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3223             if ( !t1.isEqual( t0 ) ) {
3224                 return false;
3225             }
3226             t2.setIdentifier( new Identifier( "ecoli" ) );
3227             t2.setTaxonomyCode( "OTHER" );
3228             t2.setScientificName( "what" );
3229             t2.setCommonName( "something" );
3230             if ( !t1.isEqual( t2 ) ) {
3231                 return false;
3232             }
3233             t2.setIdentifier( new Identifier( "nemve" ) );
3234             if ( t1.isEqual( t2 ) ) {
3235                 return false;
3236             }
3237             t1.setIdentifier( null );
3238             t3.setTaxonomyCode( "ECOLI" );
3239             t3.setScientificName( "what" );
3240             t3.setCommonName( "something" );
3241             if ( !t1.isEqual( t3 ) ) {
3242                 return false;
3243             }
3244             t1.setIdentifier( null );
3245             t1.setTaxonomyCode( "" );
3246             t4.setScientificName( "E. ColI" );
3247             t4.setCommonName( "something" );
3248             if ( !t1.isEqual( t4 ) ) {
3249                 return false;
3250             }
3251             t4.setScientificName( "B. subtilis" );
3252             t4.setCommonName( "something" );
3253             if ( t1.isEqual( t4 ) ) {
3254                 return false;
3255             }
3256             t1.setIdentifier( null );
3257             t1.setTaxonomyCode( "" );
3258             t1.setScientificName( "" );
3259             t5.setCommonName( "COLI" );
3260             if ( !t1.isEqual( t5 ) ) {
3261                 return false;
3262             }
3263             t5.setCommonName( "vibrio" );
3264             if ( t1.isEqual( t5 ) ) {
3265                 return false;
3266             }
3267             // Identifier
3268             // ----------
3269             final Identifier id0 = new Identifier( "123", "pfam" );
3270             final Identifier id1 = ( Identifier ) id0.copy();
3271             if ( !id1.isEqual( id1 ) ) {
3272                 return false;
3273             }
3274             if ( !id1.isEqual( id0 ) ) {
3275                 return false;
3276             }
3277             if ( !id0.isEqual( id1 ) ) {
3278                 return false;
3279             }
3280             id1.asSimpleText();
3281             id1.asText();
3282             // ProteinDomain
3283             // ---------------
3284             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3285             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3286             if ( !pd1.isEqual( pd1 ) ) {
3287                 return false;
3288             }
3289             if ( !pd1.isEqual( pd0 ) ) {
3290                 return false;
3291             }
3292             pd1.asSimpleText();
3293             pd1.asText();
3294             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3295             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3296             if ( !pd3.isEqual( pd3 ) ) {
3297                 return false;
3298             }
3299             if ( !pd2.isEqual( pd3 ) ) {
3300                 return false;
3301             }
3302             if ( !pd0.isEqual( pd3 ) ) {
3303                 return false;
3304             }
3305             pd3.asSimpleText();
3306             pd3.asText();
3307             // DomainArchitecture
3308             // ------------------
3309             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3310             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3311             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3312             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3313             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3314             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3315             domains0.add( d2 );
3316             domains0.add( d0 );
3317             domains0.add( d3 );
3318             domains0.add( d1 );
3319             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3320             if ( ds0.getNumberOfDomains() != 4 ) {
3321                 return false;
3322             }
3323             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3324             if ( !ds0.isEqual( ds0 ) ) {
3325                 return false;
3326             }
3327             if ( !ds0.isEqual( ds1 ) ) {
3328                 return false;
3329             }
3330             if ( ds1.getNumberOfDomains() != 4 ) {
3331                 return false;
3332             }
3333             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3334             domains1.add( d1 );
3335             domains1.add( d2 );
3336             domains1.add( d4 );
3337             domains1.add( d0 );
3338             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3339             if ( ds0.isEqual( ds2 ) ) {
3340                 return false;
3341             }
3342             ds1.asSimpleText();
3343             ds1.asText();
3344             ds1.toNHX();
3345             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3346             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3347                 System.out.println( ds3.toNHX() );
3348                 return false;
3349             }
3350             if ( ds3.getNumberOfDomains() != 3 ) {
3351                 return false;
3352             }
3353             // Event
3354             // -----
3355             final Event e1 = new Event( Event.EventType.fusion );
3356             if ( e1.isDuplication() ) {
3357                 return false;
3358             }
3359             if ( !e1.isFusion() ) {
3360                 return false;
3361             }
3362             if ( !e1.asText().toString().equals( "fusion" ) ) {
3363                 return false;
3364             }
3365             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3366                 return false;
3367             }
3368             final Event e11 = new Event( Event.EventType.fusion );
3369             if ( !e11.isEqual( e1 ) ) {
3370                 return false;
3371             }
3372             if ( !e11.toNHX().toString().equals( "" ) ) {
3373                 return false;
3374             }
3375             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3376             if ( e2.isDuplication() ) {
3377                 return false;
3378             }
3379             if ( !e2.isSpeciationOrDuplication() ) {
3380                 return false;
3381             }
3382             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3383                 return false;
3384             }
3385             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3386                 return false;
3387             }
3388             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3389                 return false;
3390             }
3391             if ( e11.isEqual( e2 ) ) {
3392                 return false;
3393             }
3394             final Event e2c = ( Event ) e2.copy();
3395             if ( !e2c.isEqual( e2 ) ) {
3396                 return false;
3397             }
3398             Event e3 = new Event( 1, 2, 3 );
3399             if ( e3.isDuplication() ) {
3400                 return false;
3401             }
3402             if ( e3.isSpeciation() ) {
3403                 return false;
3404             }
3405             if ( e3.isGeneLoss() ) {
3406                 return false;
3407             }
3408             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3409                 return false;
3410             }
3411             final Event e3c = ( Event ) e3.copy();
3412             final Event e3cc = ( Event ) e3c.copy();
3413             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3414                 return false;
3415             }
3416             e3 = null;
3417             if ( !e3c.isEqual( e3cc ) ) {
3418                 return false;
3419             }
3420             Event e4 = new Event( 1, 2, 3 );
3421             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3422                 return false;
3423             }
3424             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3425                 return false;
3426             }
3427             final Event e4c = ( Event ) e4.copy();
3428             e4 = null;
3429             final Event e4cc = ( Event ) e4c.copy();
3430             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3431                 return false;
3432             }
3433             if ( !e4c.isEqual( e4cc ) ) {
3434                 return false;
3435             }
3436             final Event e5 = new Event();
3437             if ( !e5.isUnassigned() ) {
3438                 return false;
3439             }
3440             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3441                 return false;
3442             }
3443             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3444                 return false;
3445             }
3446             final Event e6 = new Event( 1, 0, 0 );
3447             if ( !e6.asText().toString().equals( "duplication" ) ) {
3448                 return false;
3449             }
3450             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3451                 return false;
3452             }
3453             final Event e7 = new Event( 0, 1, 0 );
3454             if ( !e7.asText().toString().equals( "speciation" ) ) {
3455                 return false;
3456             }
3457             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3458                 return false;
3459             }
3460             final Event e8 = new Event( 0, 0, 1 );
3461             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3462                 return false;
3463             }
3464             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3465                 return false;
3466             }
3467         }
3468         catch ( final Exception e ) {
3469             e.printStackTrace( System.out );
3470             return false;
3471         }
3472         return true;
3473     }
3474
3475     private static boolean testDeletionOfExternalNodes() {
3476         try {
3477             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3478             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3479             final PhylogenyWriter w = new PhylogenyWriter();
3480             if ( t0.isEmpty() ) {
3481                 return false;
3482             }
3483             if ( t0.getNumberOfExternalNodes() != 1 ) {
3484                 return false;
3485             }
3486             t0.deleteSubtree( t0.getNode( "A" ), false );
3487             if ( t0.getNumberOfExternalNodes() != 0 ) {
3488                 return false;
3489             }
3490             if ( !t0.isEmpty() ) {
3491                 return false;
3492             }
3493             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3494             if ( t1.getNumberOfExternalNodes() != 2 ) {
3495                 return false;
3496             }
3497             t1.deleteSubtree( t1.getNode( "A" ), false );
3498             if ( t1.getNumberOfExternalNodes() != 1 ) {
3499                 return false;
3500             }
3501             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3502                 return false;
3503             }
3504             t1.deleteSubtree( t1.getNode( "B" ), false );
3505             if ( t1.getNumberOfExternalNodes() != 1 ) {
3506                 return false;
3507             }
3508             t1.deleteSubtree( t1.getNode( "r" ), false );
3509             if ( !t1.isEmpty() ) {
3510                 return false;
3511             }
3512             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3513             if ( t2.getNumberOfExternalNodes() != 3 ) {
3514                 return false;
3515             }
3516             t2.deleteSubtree( t2.getNode( "B" ), false );
3517             if ( t2.getNumberOfExternalNodes() != 2 ) {
3518                 return false;
3519             }
3520             t2.toNewHampshireX();
3521             PhylogenyNode n = t2.getNode( "A" );
3522             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3523                 return false;
3524             }
3525             t2.deleteSubtree( t2.getNode( "A" ), false );
3526             if ( t2.getNumberOfExternalNodes() != 2 ) {
3527                 return false;
3528             }
3529             t2.deleteSubtree( t2.getNode( "C" ), true );
3530             if ( t2.getNumberOfExternalNodes() != 1 ) {
3531                 return false;
3532             }
3533             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3534             if ( t3.getNumberOfExternalNodes() != 4 ) {
3535                 return false;
3536             }
3537             t3.deleteSubtree( t3.getNode( "B" ), true );
3538             if ( t3.getNumberOfExternalNodes() != 3 ) {
3539                 return false;
3540             }
3541             n = t3.getNode( "A" );
3542             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3543                 return false;
3544             }
3545             n = n.getNextExternalNode();
3546             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3547                 return false;
3548             }
3549             t3.deleteSubtree( t3.getNode( "A" ), true );
3550             if ( t3.getNumberOfExternalNodes() != 2 ) {
3551                 return false;
3552             }
3553             n = t3.getNode( "C" );
3554             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3555                 return false;
3556             }
3557             t3.deleteSubtree( t3.getNode( "C" ), true );
3558             if ( t3.getNumberOfExternalNodes() != 1 ) {
3559                 return false;
3560             }
3561             t3.deleteSubtree( t3.getNode( "D" ), true );
3562             if ( t3.getNumberOfExternalNodes() != 0 ) {
3563                 return false;
3564             }
3565             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3566             if ( t4.getNumberOfExternalNodes() != 6 ) {
3567                 return false;
3568             }
3569             t4.deleteSubtree( t4.getNode( "B2" ), true );
3570             if ( t4.getNumberOfExternalNodes() != 5 ) {
3571                 return false;
3572             }
3573             String s = w.toNewHampshire( t4, true ).toString();
3574             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3575                 return false;
3576             }
3577             t4.deleteSubtree( t4.getNode( "B11" ), true );
3578             if ( t4.getNumberOfExternalNodes() != 4 ) {
3579                 return false;
3580             }
3581             t4.deleteSubtree( t4.getNode( "C" ), true );
3582             if ( t4.getNumberOfExternalNodes() != 3 ) {
3583                 return false;
3584             }
3585             n = t4.getNode( "A" );
3586             n = n.getNextExternalNode();
3587             if ( !n.getName().equals( "B12" ) ) {
3588                 return false;
3589             }
3590             n = n.getNextExternalNode();
3591             if ( !n.getName().equals( "D" ) ) {
3592                 return false;
3593             }
3594             s = w.toNewHampshire( t4, true ).toString();
3595             if ( !s.equals( "((A,B12),D);" ) ) {
3596                 return false;
3597             }
3598             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3599             t5.deleteSubtree( t5.getNode( "A" ), true );
3600             if ( t5.getNumberOfExternalNodes() != 5 ) {
3601                 return false;
3602             }
3603             s = w.toNewHampshire( t5, true ).toString();
3604             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3605                 return false;
3606             }
3607             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3608             t6.deleteSubtree( t6.getNode( "B11" ), true );
3609             if ( t6.getNumberOfExternalNodes() != 5 ) {
3610                 return false;
3611             }
3612             s = w.toNewHampshire( t6, false ).toString();
3613             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3614                 return false;
3615             }
3616             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3617             t7.deleteSubtree( t7.getNode( "B12" ), true );
3618             if ( t7.getNumberOfExternalNodes() != 5 ) {
3619                 return false;
3620             }
3621             s = w.toNewHampshire( t7, true ).toString();
3622             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3623                 return false;
3624             }
3625             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3626             t8.deleteSubtree( t8.getNode( "B2" ), true );
3627             if ( t8.getNumberOfExternalNodes() != 5 ) {
3628                 return false;
3629             }
3630             s = w.toNewHampshire( t8, false ).toString();
3631             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3632                 return false;
3633             }
3634             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3635             t9.deleteSubtree( t9.getNode( "C" ), true );
3636             if ( t9.getNumberOfExternalNodes() != 5 ) {
3637                 return false;
3638             }
3639             s = w.toNewHampshire( t9, true ).toString();
3640             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3641                 return false;
3642             }
3643             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3644             t10.deleteSubtree( t10.getNode( "D" ), true );
3645             if ( t10.getNumberOfExternalNodes() != 5 ) {
3646                 return false;
3647             }
3648             s = w.toNewHampshire( t10, true ).toString();
3649             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3650                 return false;
3651             }
3652             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3653             t11.deleteSubtree( t11.getNode( "A" ), true );
3654             if ( t11.getNumberOfExternalNodes() != 2 ) {
3655                 return false;
3656             }
3657             s = w.toNewHampshire( t11, true ).toString();
3658             if ( !s.equals( "(B,C);" ) ) {
3659                 return false;
3660             }
3661             t11.deleteSubtree( t11.getNode( "C" ), true );
3662             if ( t11.getNumberOfExternalNodes() != 1 ) {
3663                 return false;
3664             }
3665             s = w.toNewHampshire( t11, false ).toString();
3666             if ( !s.equals( "B;" ) ) {
3667                 return false;
3668             }
3669             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3670             t12.deleteSubtree( t12.getNode( "B2" ), true );
3671             if ( t12.getNumberOfExternalNodes() != 8 ) {
3672                 return false;
3673             }
3674             s = w.toNewHampshire( t12, true ).toString();
3675             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3676                 return false;
3677             }
3678             t12.deleteSubtree( t12.getNode( "B3" ), true );
3679             if ( t12.getNumberOfExternalNodes() != 7 ) {
3680                 return false;
3681             }
3682             s = w.toNewHampshire( t12, true ).toString();
3683             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3684                 return false;
3685             }
3686             t12.deleteSubtree( t12.getNode( "C3" ), true );
3687             if ( t12.getNumberOfExternalNodes() != 6 ) {
3688                 return false;
3689             }
3690             s = w.toNewHampshire( t12, true ).toString();
3691             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3692                 return false;
3693             }
3694             t12.deleteSubtree( t12.getNode( "A1" ), true );
3695             if ( t12.getNumberOfExternalNodes() != 5 ) {
3696                 return false;
3697             }
3698             s = w.toNewHampshire( t12, true ).toString();
3699             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3700                 return false;
3701             }
3702             t12.deleteSubtree( t12.getNode( "B1" ), true );
3703             if ( t12.getNumberOfExternalNodes() != 4 ) {
3704                 return false;
3705             }
3706             s = w.toNewHampshire( t12, true ).toString();
3707             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3708                 return false;
3709             }
3710             t12.deleteSubtree( t12.getNode( "A3" ), true );
3711             if ( t12.getNumberOfExternalNodes() != 3 ) {
3712                 return false;
3713             }
3714             s = w.toNewHampshire( t12, true ).toString();
3715             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3716                 return false;
3717             }
3718             t12.deleteSubtree( t12.getNode( "A2" ), true );
3719             if ( t12.getNumberOfExternalNodes() != 2 ) {
3720                 return false;
3721             }
3722             s = w.toNewHampshire( t12, true ).toString();
3723             if ( !s.equals( "(C1,C2);" ) ) {
3724                 return false;
3725             }
3726             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3727             t13.deleteSubtree( t13.getNode( "D" ), true );
3728             if ( t13.getNumberOfExternalNodes() != 4 ) {
3729                 return false;
3730             }
3731             s = w.toNewHampshire( t13, true ).toString();
3732             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3733                 return false;
3734             }
3735             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3736             t14.deleteSubtree( t14.getNode( "E" ), true );
3737             if ( t14.getNumberOfExternalNodes() != 5 ) {
3738                 return false;
3739             }
3740             s = w.toNewHampshire( t14, true ).toString();
3741             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3742                 return false;
3743             }
3744             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3745             t15.deleteSubtree( t15.getNode( "B2" ), true );
3746             if ( t15.getNumberOfExternalNodes() != 11 ) {
3747                 return false;
3748             }
3749             t15.deleteSubtree( t15.getNode( "B1" ), true );
3750             if ( t15.getNumberOfExternalNodes() != 10 ) {
3751                 return false;
3752             }
3753             t15.deleteSubtree( t15.getNode( "B3" ), true );
3754             if ( t15.getNumberOfExternalNodes() != 9 ) {
3755                 return false;
3756             }
3757             t15.deleteSubtree( t15.getNode( "B4" ), true );
3758             if ( t15.getNumberOfExternalNodes() != 8 ) {
3759                 return false;
3760             }
3761             t15.deleteSubtree( t15.getNode( "A1" ), true );
3762             if ( t15.getNumberOfExternalNodes() != 7 ) {
3763                 return false;
3764             }
3765             t15.deleteSubtree( t15.getNode( "C4" ), true );
3766             if ( t15.getNumberOfExternalNodes() != 6 ) {
3767                 return false;
3768             }
3769         }
3770         catch ( final Exception e ) {
3771             e.printStackTrace( System.out );
3772             return false;
3773         }
3774         return true;
3775     }
3776
3777     private static boolean testDescriptiveStatistics() {
3778         try {
3779             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3780             dss1.addValue( 82 );
3781             dss1.addValue( 78 );
3782             dss1.addValue( 70 );
3783             dss1.addValue( 58 );
3784             dss1.addValue( 42 );
3785             if ( dss1.getN() != 5 ) {
3786                 return false;
3787             }
3788             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3789                 return false;
3790             }
3791             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3792                 return false;
3793             }
3794             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3795                 return false;
3796             }
3797             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3798                 return false;
3799             }
3800             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3801                 return false;
3802             }
3803             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3804                 return false;
3805             }
3806             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3807                 return false;
3808             }
3809             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3810                 return false;
3811             }
3812             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3813                 return false;
3814             }
3815             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3816                 return false;
3817             }
3818             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3819                 return false;
3820             }
3821             dss1.addValue( 123 );
3822             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3823                 return false;
3824             }
3825             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3826                 return false;
3827             }
3828             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3829                 return false;
3830             }
3831             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3832             dss2.addValue( -1.85 );
3833             dss2.addValue( 57.5 );
3834             dss2.addValue( 92.78 );
3835             dss2.addValue( 57.78 );
3836             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3837                 return false;
3838             }
3839             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3840                 return false;
3841             }
3842             final double[] a = dss2.getDataAsDoubleArray();
3843             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3844                 return false;
3845             }
3846             dss2.addValue( -100 );
3847             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3848                 return false;
3849             }
3850             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3851                 return false;
3852             }
3853             final double[] ds = new double[ 14 ];
3854             ds[ 0 ] = 34;
3855             ds[ 1 ] = 23;
3856             ds[ 2 ] = 1;
3857             ds[ 3 ] = 32;
3858             ds[ 4 ] = 11;
3859             ds[ 5 ] = 2;
3860             ds[ 6 ] = 12;
3861             ds[ 7 ] = 33;
3862             ds[ 8 ] = 13;
3863             ds[ 9 ] = 22;
3864             ds[ 10 ] = 21;
3865             ds[ 11 ] = 35;
3866             ds[ 12 ] = 24;
3867             ds[ 13 ] = 31;
3868             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3869             if ( bins.length != 4 ) {
3870                 return false;
3871             }
3872             if ( bins[ 0 ] != 2 ) {
3873                 return false;
3874             }
3875             if ( bins[ 1 ] != 3 ) {
3876                 return false;
3877             }
3878             if ( bins[ 2 ] != 4 ) {
3879                 return false;
3880             }
3881             if ( bins[ 3 ] != 5 ) {
3882                 return false;
3883             }
3884             final double[] ds1 = new double[ 9 ];
3885             ds1[ 0 ] = 10.0;
3886             ds1[ 1 ] = 19.0;
3887             ds1[ 2 ] = 9.999;
3888             ds1[ 3 ] = 0.0;
3889             ds1[ 4 ] = 39.9;
3890             ds1[ 5 ] = 39.999;
3891             ds1[ 6 ] = 30.0;
3892             ds1[ 7 ] = 19.999;
3893             ds1[ 8 ] = 30.1;
3894             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3895             if ( bins1.length != 4 ) {
3896                 return false;
3897             }
3898             if ( bins1[ 0 ] != 2 ) {
3899                 return false;
3900             }
3901             if ( bins1[ 1 ] != 3 ) {
3902                 return false;
3903             }
3904             if ( bins1[ 2 ] != 0 ) {
3905                 return false;
3906             }
3907             if ( bins1[ 3 ] != 4 ) {
3908                 return false;
3909             }
3910             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3911             if ( bins1_1.length != 3 ) {
3912                 return false;
3913             }
3914             if ( bins1_1[ 0 ] != 3 ) {
3915                 return false;
3916             }
3917             if ( bins1_1[ 1 ] != 2 ) {
3918                 return false;
3919             }
3920             if ( bins1_1[ 2 ] != 4 ) {
3921                 return false;
3922             }
3923             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3924             if ( bins1_2.length != 3 ) {
3925                 return false;
3926             }
3927             if ( bins1_2[ 0 ] != 2 ) {
3928                 return false;
3929             }
3930             if ( bins1_2[ 1 ] != 2 ) {
3931                 return false;
3932             }
3933             if ( bins1_2[ 2 ] != 2 ) {
3934                 return false;
3935             }
3936             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3937             dss3.addValue( 1 );
3938             dss3.addValue( 1 );
3939             dss3.addValue( 1 );
3940             dss3.addValue( 2 );
3941             dss3.addValue( 3 );
3942             dss3.addValue( 4 );
3943             dss3.addValue( 5 );
3944             dss3.addValue( 5 );
3945             dss3.addValue( 5 );
3946             dss3.addValue( 6 );
3947             dss3.addValue( 7 );
3948             dss3.addValue( 8 );
3949             dss3.addValue( 9 );
3950             dss3.addValue( 10 );
3951             dss3.addValue( 10 );
3952             dss3.addValue( 10 );
3953             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3954             histo.toStringBuffer( 10, '=', 40, 5 );
3955             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3956         }
3957         catch ( final Exception e ) {
3958             e.printStackTrace( System.out );
3959             return false;
3960         }
3961         return true;
3962     }
3963
3964     private static boolean testDir( final String file ) {
3965         try {
3966             final File f = new File( file );
3967             if ( !f.exists() ) {
3968                 return false;
3969             }
3970             if ( !f.isDirectory() ) {
3971                 return false;
3972             }
3973             if ( !f.canRead() ) {
3974                 return false;
3975             }
3976         }
3977         catch ( final Exception e ) {
3978             return false;
3979         }
3980         return true;
3981     }
3982
3983     private static boolean testEbiEntryRetrieval() {
3984         try {
3985             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3986             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3987                 System.out.println( entry.getAccession() );
3988                 return false;
3989             }
3990             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3991                 System.out.println( entry.getTaxonomyScientificName() );
3992                 return false;
3993             }
3994             if ( !entry.getSequenceName()
3995                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3996                 System.out.println( entry.getSequenceName() );
3997                 return false;
3998             }
3999             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4000                 System.out.println( entry.getGeneName() );
4001                 return false;
4002             }
4003             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4004                 System.out.println( entry.getTaxonomyIdentifier() );
4005                 return false;
4006             }
4007             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4008                 System.out.println( entry.getAnnotations().first().getRefValue() );
4009                 return false;
4010             }
4011             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4012                 System.out.println( entry.getAnnotations().first().getRefSource() );
4013                 return false;
4014             }
4015             if ( entry.getCrossReferences().size() != 5 ) {
4016                 return false;
4017             }
4018             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4019             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4020                 return false;
4021             }
4022             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4023                 System.out.println( entry1.getTaxonomyScientificName() );
4024                 return false;
4025             }
4026             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4027                 System.out.println( entry1.getSequenceName() );
4028                 return false;
4029             }
4030             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4031                 System.out.println( entry1.getTaxonomyIdentifier() );
4032                 return false;
4033             }
4034             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4035                 System.out.println( entry1.getGeneName() );
4036                 return false;
4037             }
4038             if ( entry1.getCrossReferences().size() != 6 ) {
4039                 return false;
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             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4093             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4094                 return false;
4095             }
4096             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4097                 System.out.println( entry4.getTaxonomyScientificName() );
4098                 return false;
4099             }
4100             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4101                 System.out.println( entry4.getSequenceName() );
4102                 return false;
4103             }
4104             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4105                 System.out.println( entry4.getTaxonomyIdentifier() );
4106                 return false;
4107             }
4108             if ( !entry4.getGeneName().equals( "ras" ) ) {
4109                 System.out.println( entry4.getGeneName() );
4110                 return false;
4111             }
4112             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4113             //     System.out.println( entry4.getChromosome() );
4114             //     return false;
4115             // }
4116             // if ( !entry4.getMap().equals( "ras" ) ) {
4117             //     System.out.println( entry4.getMap() );
4118             //     return false;
4119             // }
4120             //TODO FIXME gi...
4121             //
4122             //TODO fails:
4123             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4124             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4125             //                return false;
4126             //            }
4127             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4128             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4129                 return false;
4130             }
4131             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4132                 System.out.println( entry5.getTaxonomyScientificName() );
4133                 return false;
4134             }
4135             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4136                 System.out.println( entry5.getSequenceName() );
4137                 return false;
4138             }
4139             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4140                 System.out.println( entry5.getTaxonomyIdentifier() );
4141                 return false;
4142             }
4143         }
4144         catch ( final IOException e ) {
4145             System.out.println();
4146             System.out.println( "the following might be due to absence internet connection:" );
4147             e.printStackTrace( System.out );
4148             return true;
4149         }
4150         catch ( final Exception e ) {
4151             e.printStackTrace();
4152             return false;
4153         }
4154         return true;
4155     }
4156
4157     private static boolean testExternalNodeRelatedMethods() {
4158         try {
4159             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4160             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4161             PhylogenyNode n = t1.getNode( "A" );
4162             n = n.getNextExternalNode();
4163             if ( !n.getName().equals( "B" ) ) {
4164                 return false;
4165             }
4166             n = n.getNextExternalNode();
4167             if ( !n.getName().equals( "C" ) ) {
4168                 return false;
4169             }
4170             n = n.getNextExternalNode();
4171             if ( !n.getName().equals( "D" ) ) {
4172                 return false;
4173             }
4174             n = t1.getNode( "B" );
4175             while ( !n.isLastExternalNode() ) {
4176                 n = n.getNextExternalNode();
4177             }
4178             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4179             n = t2.getNode( "A" );
4180             n = n.getNextExternalNode();
4181             if ( !n.getName().equals( "B" ) ) {
4182                 return false;
4183             }
4184             n = n.getNextExternalNode();
4185             if ( !n.getName().equals( "C" ) ) {
4186                 return false;
4187             }
4188             n = n.getNextExternalNode();
4189             if ( !n.getName().equals( "D" ) ) {
4190                 return false;
4191             }
4192             n = t2.getNode( "B" );
4193             while ( !n.isLastExternalNode() ) {
4194                 n = n.getNextExternalNode();
4195             }
4196             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4197             n = t3.getNode( "A" );
4198             n = n.getNextExternalNode();
4199             if ( !n.getName().equals( "B" ) ) {
4200                 return false;
4201             }
4202             n = n.getNextExternalNode();
4203             if ( !n.getName().equals( "C" ) ) {
4204                 return false;
4205             }
4206             n = n.getNextExternalNode();
4207             if ( !n.getName().equals( "D" ) ) {
4208                 return false;
4209             }
4210             n = n.getNextExternalNode();
4211             if ( !n.getName().equals( "E" ) ) {
4212                 return false;
4213             }
4214             n = n.getNextExternalNode();
4215             if ( !n.getName().equals( "F" ) ) {
4216                 return false;
4217             }
4218             n = n.getNextExternalNode();
4219             if ( !n.getName().equals( "G" ) ) {
4220                 return false;
4221             }
4222             n = n.getNextExternalNode();
4223             if ( !n.getName().equals( "H" ) ) {
4224                 return false;
4225             }
4226             n = t3.getNode( "B" );
4227             while ( !n.isLastExternalNode() ) {
4228                 n = n.getNextExternalNode();
4229             }
4230             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4231             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4232                 final PhylogenyNode node = iter.next();
4233             }
4234             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4235             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4236                 final PhylogenyNode node = iter.next();
4237             }
4238             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4239             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4240             if ( !iter.next().getName().equals( "A" ) ) {
4241                 return false;
4242             }
4243             if ( !iter.next().getName().equals( "B" ) ) {
4244                 return false;
4245             }
4246             if ( !iter.next().getName().equals( "C" ) ) {
4247                 return false;
4248             }
4249             if ( !iter.next().getName().equals( "D" ) ) {
4250                 return false;
4251             }
4252             if ( !iter.next().getName().equals( "E" ) ) {
4253                 return false;
4254             }
4255             if ( !iter.next().getName().equals( "F" ) ) {
4256                 return false;
4257             }
4258             if ( iter.hasNext() ) {
4259                 return false;
4260             }
4261         }
4262         catch ( final Exception e ) {
4263             e.printStackTrace( System.out );
4264             return false;
4265         }
4266         return true;
4267     }
4268
4269     private static boolean testExtractSNFromNodeName() {
4270         try {
4271             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4272                 return false;
4273             }
4274             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4275                 return false;
4276             }
4277             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4278                 return false;
4279             }
4280             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4281                     .equals( "Mus musculus musculus" ) ) {
4282                 return false;
4283             }
4284             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4285                     .equals( "Mus musculus musculus" ) ) {
4286                 return false;
4287             }
4288             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4289                     .equals( "Mus musculus musculus" ) ) {
4290                 return false;
4291             }
4292             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4293                     .equals( "Mus musculus musculus" ) ) {
4294                 return false;
4295             }
4296             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4297                 return false;
4298             }
4299             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4300                     .equals( "Mus musculus musculus" ) ) {
4301                 return false;
4302             }
4303             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4304                     .equals( "Mus musculus musculus" ) ) {
4305                 return false;
4306             }
4307             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4308                 return false;
4309             }
4310             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4311                 return false;
4312             }
4313             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4314                 return false;
4315             }
4316             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4317                 return false;
4318             }
4319             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4320                     .equals( "Mus musculus musculus" ) ) {
4321                 return false;
4322             }
4323             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4324                 return false;
4325             }
4326             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4327                 return false;
4328             }
4329             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4330                 return false;
4331             }
4332             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4333                 return false;
4334             }
4335             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4336                 return false;
4337             }
4338             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4339                 return false;
4340             }
4341             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4342                 return false;
4343             }
4344             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4345                 return false;
4346             }
4347             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4348                     .equals( "Mus musculus" ) ) {
4349                 return false;
4350             }
4351             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4352                     .equals( "Mus musculus" ) ) {
4353                 return false;
4354             }
4355             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4356                 return false;
4357             }
4358             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4359                     .equals( "Mus musculus musculus" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4363                     .equals( "Mus musculus musculus" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4367                     .equals( "Mus musculus musculus" ) ) {
4368                 return false;
4369             }
4370             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4371                 return false;
4372             }
4373             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4374                     .equals( "Pilostyles mexicana" ) ) {
4375                 return false;
4376             }
4377             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4378                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4379                 return false;
4380             }
4381             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4382                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4383                 return false;
4384             }
4385             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4386                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4390                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4391                 return false;
4392             }
4393             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4394                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4395                 return false;
4396             }
4397             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4398                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4402                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4403                 return false;
4404             }
4405             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4406                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4410                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4414                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4418                     .equals( "Escherichia coli (strain K12)" ) ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4422                     .equals( "Escherichia coli (strain K12)" ) ) {
4423                 return false;
4424             }
4425             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4426                     .equals( "Escherichia coli (str. K12)" ) ) {
4427                 return false;
4428             }
4429             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4430                     .equals( "Escherichia coli (str. K12)" ) ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4434                     .equals( "Escherichia coli (str. K12)" ) ) {
4435                 return false;
4436             }
4437             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4438                     .equals( "Escherichia coli (var. K12)" ) ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4442                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4446                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4447                 return false;
4448             }
4449             if ( !ParserUtils
4450                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4451                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4455                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils
4459                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4460                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4461                 return false;
4462             }
4463             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4464                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4465                 return false;
4466             }
4467             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4468                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4469                 return false;
4470             }
4471             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4472                 return false;
4473             }
4474             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4475                 return false;
4476             }
4477             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4481                     .equals( "Macrocera sp." ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4485                 return false;
4486             }
4487             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4488                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4489                 return false;
4490             }
4491             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4492                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4493                 return false;
4494             }
4495             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4496                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4500                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4501                 return false;
4502             }
4503         }
4504         catch ( final Exception e ) {
4505             e.printStackTrace( System.out );
4506             return false;
4507         }
4508         return true;
4509     }
4510
4511     private static boolean testExtractTaxonomyDataFromNodeName() {
4512         try {
4513             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4514             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4515                 return false;
4516             }
4517             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4518             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4519                 return false;
4520             }
4521             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4522             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4523                 return false;
4524             }
4525             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4526             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4527                 return false;
4528             }
4529             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4530             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4531                 return false;
4532             }
4533             n = new PhylogenyNode( "HNRPR_HUMAN" );
4534             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4535                 return false;
4536             }
4537             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4538             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4539                 return false;
4540             }
4541         }
4542         catch ( final Exception e ) {
4543             e.printStackTrace( System.out );
4544             return false;
4545         }
4546         return true;
4547     }
4548
4549     private static boolean testExtractTaxonomyCodeFromNodeName() {
4550         try {
4551             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4552                 return false;
4553             }
4554             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4555                     .equals( "SOYBN" ) ) {
4556                 return false;
4557             }
4558             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4559                     .equals( "ARATH" ) ) {
4560                 return false;
4561             }
4562             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4563                     .equals( "ARATH" ) ) {
4564                 return false;
4565             }
4566             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4567                 return false;
4568             }
4569             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4570                 return false;
4571             }
4572             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4573                 return false;
4574             }
4575             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4576                     .equals( "SOYBN" ) ) {
4577                 return false;
4578             }
4579             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4580                     .equals( "SOYBN" ) ) {
4581                 return false;
4582             }
4583             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4584                     .equals( "SOYBN" ) ) {
4585                 return false;
4586             }
4587             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4588                     .equals( "SOYBN" ) ) {
4589                 return false;
4590             }
4591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4592                     .equals( "SOYBN" ) ) {
4593                 return false;
4594             }
4595             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4596                     .equals( "SOYBN" ) ) {
4597                 return false;
4598             }
4599             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4600                     .equals( "SOYBN" ) ) {
4601                 return false;
4602             }
4603             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4604                     .equals( "SOYBN" ) ) {
4605                 return false;
4606             }
4607             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4608                 return false;
4609             }
4610             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4611                     .equals( "SOYBN" ) ) {
4612                 return false;
4613             }
4614             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4615                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4616                 return false;
4617             }
4618             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4619                     .equals( "9YX45" ) ) {
4620                 return false;
4621             }
4622             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4623                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4624                     .equals( "MOUSE" ) ) {
4625                 return false;
4626             }
4627             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4628                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4629                     .equals( "MOUSE" ) ) {
4630                 return false;
4631             }
4632             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4633                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4634                     .equals( "MOUSE" ) ) {
4635                 return false;
4636             }
4637             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4638                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4639                 return false;
4640             }
4641             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4642                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4643                 return false;
4644             }
4645             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4646                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4647                 return false;
4648             }
4649             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4650                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4651                 return false;
4652             }
4653             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4654                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4655                 return false;
4656             }
4657             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4658                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4659                 return false;
4660             }
4661             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4662                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4663                 return false;
4664             }
4665             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4666                     .equals( "RAT" ) ) {
4667                 return false;
4668             }
4669             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4670                     .equals( "PIG" ) ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils
4674                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4675                     .equals( "MOUSE" ) ) {
4676                 return false;
4677             }
4678             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4679                     .equals( "MOUSE" ) ) {
4680                 return false;
4681             }
4682             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4683                 return false;
4684             }
4685         }
4686         catch ( final Exception e ) {
4687             e.printStackTrace( System.out );
4688             return false;
4689         }
4690         return true;
4691     }
4692
4693     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4694         try {
4695             PhylogenyNode n = new PhylogenyNode();
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=B3RJ64" );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4706                 return false;
4707             }
4708             n.setName( "tr-B3RJ64" );
4709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4710                 return false;
4711             }
4712             n.setName( "tr/B3RJ64" );
4713             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4714                 return false;
4715             }
4716             n.setName( "tr\\B3RJ64" );
4717             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4718                 return false;
4719             }
4720             n.setName( "tr_B3RJ64" );
4721             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4722                 return false;
4723             }
4724             n.setName( " tr|B3RJ64 " );
4725             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4726                 return false;
4727             }
4728             n.setName( "-tr|B3RJ64-" );
4729             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4730                 return false;
4731             }
4732             n.setName( "-tr=B3RJ64-" );
4733             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4734                 return false;
4735             }
4736             n.setName( "_tr=B3RJ64_" );
4737             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4738                 return false;
4739             }
4740             n.setName( " tr_tr|B3RJ64_sp|123 " );
4741             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4742                 return false;
4743             }
4744             n.setName( "B3RJ64" );
4745             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4746                 return false;
4747             }
4748             n.setName( "sp|B3RJ64" );
4749             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4750                 return false;
4751             }
4752             n.setName( "sp|B3RJ64C" );
4753             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4754                 return false;
4755             }
4756             n.setName( "sp B3RJ64" );
4757             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4758                 return false;
4759             }
4760             n.setName( "sp|B3RJ6X" );
4761             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4762                 return false;
4763             }
4764             n.setName( "sp|B3RJ6" );
4765             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4766                 return false;
4767             }
4768             n.setName( "K1PYK7_CRAGI" );
4769             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4770                 return false;
4771             }
4772             n.setName( "K1PYK7_PEA" );
4773             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4774                 return false;
4775             }
4776             n.setName( "K1PYK7_RAT" );
4777             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4778                 return false;
4779             }
4780             n.setName( "K1PYK7_PIG" );
4781             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4782                 return false;
4783             }
4784             n.setName( "~K1PYK7_PIG~" );
4785             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4786                 return false;
4787             }
4788             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4789             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4790                 return false;
4791             }
4792             n.setName( "K1PYKX_CRAGI" );
4793             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4794                 return false;
4795             }
4796             n.setName( "XXXXX_CRAGI" );
4797             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4798                 return false;
4799             }
4800             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4801             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4802                 return false;
4803             }
4804             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4805             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4806                 return false;
4807             }
4808             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4809             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4810                 return false;
4811             }
4812             n = new PhylogenyNode();
4813             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4814             seq.setSymbol( "K1PYK7_CRAGI" );
4815             n.getNodeData().addSequence( seq );
4816             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4817                 return false;
4818             }
4819             seq.setSymbol( "tr|B3RJ64" );
4820             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4821                 return false;
4822             }
4823             n = new PhylogenyNode();
4824             seq = new org.forester.phylogeny.data.Sequence();
4825             seq.setName( "K1PYK7_CRAGI" );
4826             n.getNodeData().addSequence( seq );
4827             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4828                 return false;
4829             }
4830             seq.setName( "tr|B3RJ64" );
4831             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4832                 return false;
4833             }
4834             n = new PhylogenyNode();
4835             seq = new org.forester.phylogeny.data.Sequence();
4836             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4837             n.getNodeData().addSequence( seq );
4838             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4839                 return false;
4840             }
4841             n = new PhylogenyNode();
4842             seq = new org.forester.phylogeny.data.Sequence();
4843             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4844             n.getNodeData().addSequence( seq );
4845             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4846                 return false;
4847             }
4848             //
4849             n = new PhylogenyNode();
4850             n.setName( "ACP19736" );
4851             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4852                 return false;
4853             }
4854             n = new PhylogenyNode();
4855             n.setName( "|ACP19736|" );
4856             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4857                 return false;
4858             }
4859         }
4860         catch ( final Exception e ) {
4861             e.printStackTrace( System.out );
4862             return false;
4863         }
4864         return true;
4865     }
4866
4867     private static boolean testFastaParser() {
4868         try {
4869             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4870                 return false;
4871             }
4872             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4873                 return false;
4874             }
4875             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4876             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4877                 return false;
4878             }
4879             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4880                 return false;
4881             }
4882             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4883                 return false;
4884             }
4885             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4886                 return false;
4887             }
4888             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4892                 return false;
4893             }
4894         }
4895         catch ( final Exception e ) {
4896             e.printStackTrace();
4897             return false;
4898         }
4899         return true;
4900     }
4901
4902     private static boolean testGenbankAccessorParsing() {
4903         //The format for GenBank Accession numbers are:
4904         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4905         //Protein:    3 letters + 5 numerals
4906         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4907         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4908             return false;
4909         }
4910         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4911             return false;
4912         }
4913         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4914             return false;
4915         }
4916         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4917             return false;
4918         }
4919         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4920             return false;
4921         }
4922         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4923             return false;
4924         }
4925         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4926             return false;
4927         }
4928         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4929             return false;
4930         }
4931         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4932             return false;
4933         }
4934         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4935             return false;
4936         }
4937         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4938             return false;
4939         }
4940         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4941             return false;
4942         }
4943         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4944             return false;
4945         }
4946         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4947             return false;
4948         }
4949         return true;
4950     }
4951
4952     private static boolean testGeneralMsaParser() {
4953         try {
4954             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4955             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4956             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4957             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4958             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4959             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4960             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4961             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4962             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4963                 return false;
4964             }
4965             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4966                 return false;
4967             }
4968             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4969                 return false;
4970             }
4971             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4972                 return false;
4973             }
4974             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4975                 return false;
4976             }
4977             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4978                 return false;
4979             }
4980             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4981                 return false;
4982             }
4983             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4984                 return false;
4985             }
4986             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4987                 return false;
4988             }
4989             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4990                 return false;
4991             }
4992             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4993                 return false;
4994             }
4995             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4996                 return false;
4997             }
4998             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4999             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5000                 return false;
5001             }
5002             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5003                 return false;
5004             }
5005             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5006                 return false;
5007             }
5008             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5009             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5010                 return false;
5011             }
5012             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5013                 return false;
5014             }
5015             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5016                 return false;
5017             }
5018             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5019             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5020                 return false;
5021             }
5022             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5023                 return false;
5024             }
5025             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5026                 return false;
5027             }
5028         }
5029         catch ( final Exception e ) {
5030             e.printStackTrace();
5031             return false;
5032         }
5033         return true;
5034     }
5035
5036     private static boolean testGeneralTable() {
5037         try {
5038             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5039             t0.setValue( 3, 2, "23" );
5040             t0.setValue( 10, 1, "error" );
5041             t0.setValue( 10, 1, "110" );
5042             t0.setValue( 9, 1, "19" );
5043             t0.setValue( 1, 10, "101" );
5044             t0.setValue( 10, 10, "1010" );
5045             t0.setValue( 100, 10, "10100" );
5046             t0.setValue( 0, 0, "00" );
5047             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5048                 return false;
5049             }
5050             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5051                 return false;
5052             }
5053             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5054                 return false;
5055             }
5056             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5057                 return false;
5058             }
5059             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5060                 return false;
5061             }
5062             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5063                 return false;
5064             }
5065             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5066                 return false;
5067             }
5068             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5069                 return false;
5070             }
5071             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5072                 return false;
5073             }
5074             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5075             t1.setValue( "3", "2", "23" );
5076             t1.setValue( "10", "1", "error" );
5077             t1.setValue( "10", "1", "110" );
5078             t1.setValue( "9", "1", "19" );
5079             t1.setValue( "1", "10", "101" );
5080             t1.setValue( "10", "10", "1010" );
5081             t1.setValue( "100", "10", "10100" );
5082             t1.setValue( "0", "0", "00" );
5083             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5084             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5085                 return false;
5086             }
5087             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5088                 return false;
5089             }
5090             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5091                 return false;
5092             }
5093             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5094                 return false;
5095             }
5096             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5097                 return false;
5098             }
5099             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5100                 return false;
5101             }
5102             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5103                 return false;
5104             }
5105             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5106                 return false;
5107             }
5108             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5109                 return false;
5110             }
5111             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5112                 return false;
5113             }
5114         }
5115         catch ( final Exception e ) {
5116             e.printStackTrace( System.out );
5117             return false;
5118         }
5119         return true;
5120     }
5121
5122     private static boolean testGetDistance() {
5123         try {
5124             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5125             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",
5126                                                  new NHXParser() )[ 0 ];
5127             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5128                 return false;
5129             }
5130             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5131                 return false;
5132             }
5133             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5134                 return false;
5135             }
5136             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5137                 return false;
5138             }
5139             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5140                 return false;
5141             }
5142             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5143                 return false;
5144             }
5145             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5146                 return false;
5147             }
5148             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5149                 return false;
5150             }
5151             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5152                 return false;
5153             }
5154             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5155                 return false;
5156             }
5157             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5158                 return false;
5159             }
5160             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5161                 return false;
5162             }
5163             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5164                 return false;
5165             }
5166             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5167                 return false;
5168             }
5169             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5170                 return false;
5171             }
5172             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5173                 return false;
5174             }
5175             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5176                 return false;
5177             }
5178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5179                 return false;
5180             }
5181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5182                 return false;
5183             }
5184             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5185                 return false;
5186             }
5187             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5188                 return false;
5189             }
5190             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5191                 return false;
5192             }
5193             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5194                 return false;
5195             }
5196             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5197                 return false;
5198             }
5199             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5200                 return false;
5201             }
5202             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5203                 return false;
5204             }
5205             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5206                 return false;
5207             }
5208             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5209                 return false;
5210             }
5211             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5212                 return false;
5213             }
5214             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5215                 return false;
5216             }
5217             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5218                 return false;
5219             }
5220             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",
5221                                                  new NHXParser() )[ 0 ];
5222             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5223                 return false;
5224             }
5225             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5226                 return false;
5227             }
5228             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5229                 return false;
5230             }
5231             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5232                 return false;
5233             }
5234             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5235                 return false;
5236             }
5237             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5238                 return false;
5239             }
5240             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5241                 return false;
5242             }
5243             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5244                 return false;
5245             }
5246             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5247                 return false;
5248             }
5249             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5250                 return false;
5251             }
5252             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5253                 return false;
5254             }
5255         }
5256         catch ( final Exception e ) {
5257             e.printStackTrace( System.out );
5258             return false;
5259         }
5260         return true;
5261     }
5262
5263     private static boolean testGetLCA() {
5264         try {
5265             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5266             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5267                                                  new NHXParser() )[ 0 ];
5268             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5269             if ( !A.getName().equals( "A" ) ) {
5270                 return false;
5271             }
5272             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5273             if ( !gh.getName().equals( "gh" ) ) {
5274                 return false;
5275             }
5276             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5277             if ( !ab.getName().equals( "ab" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5281             if ( !ab2.getName().equals( "ab" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5285             if ( !gh2.getName().equals( "gh" ) ) {
5286                 return false;
5287             }
5288             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5289             if ( !gh3.getName().equals( "gh" ) ) {
5290                 return false;
5291             }
5292             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5293             if ( !abc.getName().equals( "abc" ) ) {
5294                 return false;
5295             }
5296             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5297             if ( !abc2.getName().equals( "abc" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5301             if ( !abcd.getName().equals( "abcd" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5305             if ( !abcd2.getName().equals( "abcd" ) ) {
5306                 return false;
5307             }
5308             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5309             if ( !abcdef.getName().equals( "abcdef" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5313             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5317             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5321             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5322                 return false;
5323             }
5324             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5325             if ( !abcde.getName().equals( "abcde" ) ) {
5326                 return false;
5327             }
5328             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5329             if ( !abcde2.getName().equals( "abcde" ) ) {
5330                 return false;
5331             }
5332             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5333             if ( !r.getName().equals( "abcdefgh" ) ) {
5334                 return false;
5335             }
5336             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5337             if ( !r2.getName().equals( "abcdefgh" ) ) {
5338                 return false;
5339             }
5340             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5341             if ( !r3.getName().equals( "abcdefgh" ) ) {
5342                 return false;
5343             }
5344             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5345             if ( !abcde3.getName().equals( "abcde" ) ) {
5346                 return false;
5347             }
5348             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5349             if ( !abcde4.getName().equals( "abcde" ) ) {
5350                 return false;
5351             }
5352             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5353             if ( !ab3.getName().equals( "ab" ) ) {
5354                 return false;
5355             }
5356             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5357             if ( !ab4.getName().equals( "ab" ) ) {
5358                 return false;
5359             }
5360             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5361             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5362             if ( !cd.getName().equals( "cd" ) ) {
5363                 return false;
5364             }
5365             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5366             if ( !cd2.getName().equals( "cd" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5370             if ( !cde.getName().equals( "cde" ) ) {
5371                 return false;
5372             }
5373             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5374             if ( !cde2.getName().equals( "cde" ) ) {
5375                 return false;
5376             }
5377             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5378             if ( !cdef.getName().equals( "cdef" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5382             if ( !cdef2.getName().equals( "cdef" ) ) {
5383                 return false;
5384             }
5385             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5386             if ( !cdef3.getName().equals( "cdef" ) ) {
5387                 return false;
5388             }
5389             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5390             if ( !rt.getName().equals( "r" ) ) {
5391                 return false;
5392             }
5393             final Phylogeny p3 = factory
5394                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5395                              new NHXParser() )[ 0 ];
5396             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5397             if ( !bc_3.getName().equals( "bc" ) ) {
5398                 return false;
5399             }
5400             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5401             if ( !ac_3.getName().equals( "abc" ) ) {
5402                 return false;
5403             }
5404             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5405             if ( !ad_3.getName().equals( "abcde" ) ) {
5406                 return false;
5407             }
5408             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5409             if ( !af_3.getName().equals( "abcdef" ) ) {
5410                 return false;
5411             }
5412             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5413             if ( !ag_3.getName().equals( "" ) ) {
5414                 return false;
5415             }
5416             if ( !ag_3.isRoot() ) {
5417                 return false;
5418             }
5419             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5420             if ( !al_3.getName().equals( "" ) ) {
5421                 return false;
5422             }
5423             if ( !al_3.isRoot() ) {
5424                 return false;
5425             }
5426             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5427             if ( !kl_3.getName().equals( "" ) ) {
5428                 return false;
5429             }
5430             if ( !kl_3.isRoot() ) {
5431                 return false;
5432             }
5433             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5434             if ( !fl_3.getName().equals( "" ) ) {
5435                 return false;
5436             }
5437             if ( !fl_3.isRoot() ) {
5438                 return false;
5439             }
5440             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5441             if ( !gk_3.getName().equals( "ghijk" ) ) {
5442                 return false;
5443             }
5444             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5445             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5446             if ( !r_4.getName().equals( "r" ) ) {
5447                 return false;
5448             }
5449             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5450             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5451             if ( !r_5.getName().equals( "root" ) ) {
5452                 return false;
5453             }
5454             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5455             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5456             if ( !r_6.getName().equals( "rot" ) ) {
5457                 return false;
5458             }
5459             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5460             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5461             if ( !r_7.getName().equals( "rott" ) ) {
5462                 return false;
5463             }
5464         }
5465         catch ( final Exception e ) {
5466             e.printStackTrace( System.out );
5467             return false;
5468         }
5469         return true;
5470     }
5471
5472     private static boolean testGetLCA2() {
5473         try {
5474             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5475             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5476             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5477             PhylogenyMethods.preOrderReId( p_a );
5478             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5479                                                                                               p_a.getNode( "a" ) );
5480             if ( !p_a_1.getName().equals( "a" ) ) {
5481                 return false;
5482             }
5483             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5484             PhylogenyMethods.preOrderReId( p_b );
5485             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5486                                                                                               p_b.getNode( "a" ) );
5487             if ( !p_b_1.getName().equals( "b" ) ) {
5488                 return false;
5489             }
5490             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5491                                                                                               p_b.getNode( "b" ) );
5492             if ( !p_b_2.getName().equals( "b" ) ) {
5493                 return false;
5494             }
5495             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5496             PhylogenyMethods.preOrderReId( p_c );
5497             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5498                                                                                               p_c.getNode( "a" ) );
5499             if ( !p_c_1.getName().equals( "b" ) ) {
5500                 return false;
5501             }
5502             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5503                                                                                               p_c.getNode( "c" ) );
5504             if ( !p_c_2.getName().equals( "c" ) ) {
5505                 System.out.println( p_c_2.getName() );
5506                 System.exit( -1 );
5507                 return false;
5508             }
5509             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5510                                                                                               p_c.getNode( "b" ) );
5511             if ( !p_c_3.getName().equals( "b" ) ) {
5512                 return false;
5513             }
5514             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5515                                                                                               p_c.getNode( "a" ) );
5516             if ( !p_c_4.getName().equals( "c" ) ) {
5517                 return false;
5518             }
5519             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5520                                                  new NHXParser() )[ 0 ];
5521             PhylogenyMethods.preOrderReId( p1 );
5522             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5523                                                                                           p1.getNode( "A" ) );
5524             if ( !A.getName().equals( "A" ) ) {
5525                 return false;
5526             }
5527             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5528                                                                                            p1.getNode( "gh" ) );
5529             if ( !gh.getName().equals( "gh" ) ) {
5530                 return false;
5531             }
5532             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5533                                                                                            p1.getNode( "B" ) );
5534             if ( !ab.getName().equals( "ab" ) ) {
5535                 return false;
5536             }
5537             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5538                                                                                             p1.getNode( "A" ) );
5539             if ( !ab2.getName().equals( "ab" ) ) {
5540                 return false;
5541             }
5542             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5543                                                                                             p1.getNode( "G" ) );
5544             if ( !gh2.getName().equals( "gh" ) ) {
5545                 return false;
5546             }
5547             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5548                                                                                             p1.getNode( "H" ) );
5549             if ( !gh3.getName().equals( "gh" ) ) {
5550                 return false;
5551             }
5552             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5553                                                                                             p1.getNode( "A" ) );
5554             if ( !abc.getName().equals( "abc" ) ) {
5555                 return false;
5556             }
5557             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5558                                                                                              p1.getNode( "C" ) );
5559             if ( !abc2.getName().equals( "abc" ) ) {
5560                 return false;
5561             }
5562             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5563                                                                                              p1.getNode( "D" ) );
5564             if ( !abcd.getName().equals( "abcd" ) ) {
5565                 return false;
5566             }
5567             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5568                                                                                               p1.getNode( "A" ) );
5569             if ( !abcd2.getName().equals( "abcd" ) ) {
5570                 return false;
5571             }
5572             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5573                                                                                                p1.getNode( "F" ) );
5574             if ( !abcdef.getName().equals( "abcdef" ) ) {
5575                 return false;
5576             }
5577             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5578                                                                                                 p1.getNode( "A" ) );
5579             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5580                 return false;
5581             }
5582             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5583                                                                                                 p1.getNode( "F" ) );
5584             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5585                 return false;
5586             }
5587             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5588                                                                                                 p1.getNode( "ab" ) );
5589             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5590                 return false;
5591             }
5592             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5593                                                                                               p1.getNode( "E" ) );
5594             if ( !abcde.getName().equals( "abcde" ) ) {
5595                 return false;
5596             }
5597             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5598                                                                                                p1.getNode( "A" ) );
5599             if ( !abcde2.getName().equals( "abcde" ) ) {
5600                 return false;
5601             }
5602             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5603                                                                                           p1.getNode( "abcdefgh" ) );
5604             if ( !r.getName().equals( "abcdefgh" ) ) {
5605                 return false;
5606             }
5607             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5608                                                                                            p1.getNode( "H" ) );
5609             if ( !r2.getName().equals( "abcdefgh" ) ) {
5610                 return false;
5611             }
5612             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5613                                                                                            p1.getNode( "A" ) );
5614             if ( !r3.getName().equals( "abcdefgh" ) ) {
5615                 return false;
5616             }
5617             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5618                                                                                                p1.getNode( "abcde" ) );
5619             if ( !abcde3.getName().equals( "abcde" ) ) {
5620                 return false;
5621             }
5622             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5623                                                                                                p1.getNode( "E" ) );
5624             if ( !abcde4.getName().equals( "abcde" ) ) {
5625                 return false;
5626             }
5627             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5628                                                                                             p1.getNode( "B" ) );
5629             if ( !ab3.getName().equals( "ab" ) ) {
5630                 return false;
5631             }
5632             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5633                                                                                             p1.getNode( "ab" ) );
5634             if ( !ab4.getName().equals( "ab" ) ) {
5635                 return false;
5636             }
5637             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5638             PhylogenyMethods.preOrderReId( p2 );
5639             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5640                                                                                            p2.getNode( "d" ) );
5641             if ( !cd.getName().equals( "cd" ) ) {
5642                 return false;
5643             }
5644             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5645                                                                                             p2.getNode( "c" ) );
5646             if ( !cd2.getName().equals( "cd" ) ) {
5647                 return false;
5648             }
5649             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5650                                                                                             p2.getNode( "e" ) );
5651             if ( !cde.getName().equals( "cde" ) ) {
5652                 return false;
5653             }
5654             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5655                                                                                              p2.getNode( "c" ) );
5656             if ( !cde2.getName().equals( "cde" ) ) {
5657                 return false;
5658             }
5659             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5660                                                                                              p2.getNode( "f" ) );
5661             if ( !cdef.getName().equals( "cdef" ) ) {
5662                 return false;
5663             }
5664             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5665                                                                                               p2.getNode( "f" ) );
5666             if ( !cdef2.getName().equals( "cdef" ) ) {
5667                 return false;
5668             }
5669             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5670                                                                                               p2.getNode( "d" ) );
5671             if ( !cdef3.getName().equals( "cdef" ) ) {
5672                 return false;
5673             }
5674             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5675                                                                                            p2.getNode( "a" ) );
5676             if ( !rt.getName().equals( "r" ) ) {
5677                 return false;
5678             }
5679             final Phylogeny p3 = factory
5680                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5681                              new NHXParser() )[ 0 ];
5682             PhylogenyMethods.preOrderReId( p3 );
5683             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5684                                                                                              p3.getNode( "c" ) );
5685             if ( !bc_3.getName().equals( "bc" ) ) {
5686                 return false;
5687             }
5688             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5689                                                                                              p3.getNode( "c" ) );
5690             if ( !ac_3.getName().equals( "abc" ) ) {
5691                 return false;
5692             }
5693             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5694                                                                                              p3.getNode( "d" ) );
5695             if ( !ad_3.getName().equals( "abcde" ) ) {
5696                 return false;
5697             }
5698             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5699                                                                                              p3.getNode( "f" ) );
5700             if ( !af_3.getName().equals( "abcdef" ) ) {
5701                 return false;
5702             }
5703             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5704                                                                                              p3.getNode( "g" ) );
5705             if ( !ag_3.getName().equals( "" ) ) {
5706                 return false;
5707             }
5708             if ( !ag_3.isRoot() ) {
5709                 return false;
5710             }
5711             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5712                                                                                              p3.getNode( "l" ) );
5713             if ( !al_3.getName().equals( "" ) ) {
5714                 return false;
5715             }
5716             if ( !al_3.isRoot() ) {
5717                 return false;
5718             }
5719             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5720                                                                                              p3.getNode( "l" ) );
5721             if ( !kl_3.getName().equals( "" ) ) {
5722                 return false;
5723             }
5724             if ( !kl_3.isRoot() ) {
5725                 return false;
5726             }
5727             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5728                                                                                              p3.getNode( "l" ) );
5729             if ( !fl_3.getName().equals( "" ) ) {
5730                 return false;
5731             }
5732             if ( !fl_3.isRoot() ) {
5733                 return false;
5734             }
5735             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5736                                                                                              p3.getNode( "k" ) );
5737             if ( !gk_3.getName().equals( "ghijk" ) ) {
5738                 return false;
5739             }
5740             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5741             PhylogenyMethods.preOrderReId( p4 );
5742             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5743                                                                                             p4.getNode( "c" ) );
5744             if ( !r_4.getName().equals( "r" ) ) {
5745                 return false;
5746             }
5747             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5748             PhylogenyMethods.preOrderReId( p5 );
5749             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5750                                                                                             p5.getNode( "c" ) );
5751             if ( !r_5.getName().equals( "root" ) ) {
5752                 return false;
5753             }
5754             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5755             PhylogenyMethods.preOrderReId( p6 );
5756             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5757                                                                                             p6.getNode( "a" ) );
5758             if ( !r_6.getName().equals( "rot" ) ) {
5759                 return false;
5760             }
5761             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5762             PhylogenyMethods.preOrderReId( p7 );
5763             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5764                                                                                             p7.getNode( "e" ) );
5765             if ( !r_7.getName().equals( "rott" ) ) {
5766                 return false;
5767             }
5768             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5769                                                                                              p7.getNode( "a" ) );
5770             if ( !r_71.getName().equals( "rott" ) ) {
5771                 return false;
5772             }
5773             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5774                                                                                              p7.getNode( "rott" ) );
5775             if ( !r_72.getName().equals( "rott" ) ) {
5776                 return false;
5777             }
5778             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5779                                                                                              p7.getNode( "a" ) );
5780             if ( !r_73.getName().equals( "rott" ) ) {
5781                 return false;
5782             }
5783             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5784                                                                                              p7.getNode( "rott" ) );
5785             if ( !r_74.getName().equals( "rott" ) ) {
5786                 return false;
5787             }
5788             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5789                                                                                              p7.getNode( "e" ) );
5790             if ( !r_75.getName().equals( "e" ) ) {
5791                 return false;
5792             }
5793         }
5794         catch ( final Exception e ) {
5795             e.printStackTrace( System.out );
5796             return false;
5797         }
5798         return true;
5799     }
5800
5801     private static boolean testHmmscanOutputParser() {
5802         final String test_dir = Test.PATH_TO_TEST_DATA;
5803         try {
5804             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5805                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5806             parser1.parse();
5807             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5808                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5809             final List<Protein> proteins = parser2.parse();
5810             if ( parser2.getProteinsEncountered() != 4 ) {
5811                 return false;
5812             }
5813             if ( proteins.size() != 4 ) {
5814                 return false;
5815             }
5816             if ( parser2.getDomainsEncountered() != 69 ) {
5817                 return false;
5818             }
5819             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5820                 return false;
5821             }
5822             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5823                 return false;
5824             }
5825             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5826                 return false;
5827             }
5828             final Protein p1 = proteins.get( 0 );
5829             if ( p1.getNumberOfProteinDomains() != 15 ) {
5830                 return false;
5831             }
5832             if ( p1.getLength() != 850 ) {
5833                 return false;
5834             }
5835             final Protein p2 = proteins.get( 1 );
5836             if ( p2.getNumberOfProteinDomains() != 51 ) {
5837                 return false;
5838             }
5839             if ( p2.getLength() != 1291 ) {
5840                 return false;
5841             }
5842             final Protein p3 = proteins.get( 2 );
5843             if ( p3.getNumberOfProteinDomains() != 2 ) {
5844                 return false;
5845             }
5846             final Protein p4 = proteins.get( 3 );
5847             if ( p4.getNumberOfProteinDomains() != 1 ) {
5848                 return false;
5849             }
5850             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5851                 return false;
5852             }
5853             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5854                 return false;
5855             }
5856             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5857                 return false;
5858             }
5859             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5860                 return false;
5861             }
5862             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5863                 return false;
5864             }
5865             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5866                 return false;
5867             }
5868             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5869                 return false;
5870             }
5871         }
5872         catch ( final Exception e ) {
5873             e.printStackTrace( System.out );
5874             return false;
5875         }
5876         return true;
5877     }
5878
5879     private static boolean testLastExternalNodeMethods() {
5880         try {
5881             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5882             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5883             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5884             final PhylogenyNode n1 = t0.getNode( "A" );
5885             if ( n1.isLastExternalNode() ) {
5886                 return false;
5887             }
5888             final PhylogenyNode n2 = t0.getNode( "B" );
5889             if ( n2.isLastExternalNode() ) {
5890                 return false;
5891             }
5892             final PhylogenyNode n3 = t0.getNode( "C" );
5893             if ( n3.isLastExternalNode() ) {
5894                 return false;
5895             }
5896             final PhylogenyNode n4 = t0.getNode( "D" );
5897             if ( !n4.isLastExternalNode() ) {
5898                 return false;
5899             }
5900         }
5901         catch ( final Exception e ) {
5902             e.printStackTrace( System.out );
5903             return false;
5904         }
5905         return true;
5906     }
5907
5908     private static boolean testLevelOrderIterator() {
5909         try {
5910             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5911             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5912             PhylogenyNodeIterator it0;
5913             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5914                 it0.next();
5915             }
5916             for( it0.reset(); it0.hasNext(); ) {
5917                 it0.next();
5918             }
5919             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5920             if ( !it.next().getName().equals( "r" ) ) {
5921                 return false;
5922             }
5923             if ( !it.next().getName().equals( "ab" ) ) {
5924                 return false;
5925             }
5926             if ( !it.next().getName().equals( "cd" ) ) {
5927                 return false;
5928             }
5929             if ( !it.next().getName().equals( "A" ) ) {
5930                 return false;
5931             }
5932             if ( !it.next().getName().equals( "B" ) ) {
5933                 return false;
5934             }
5935             if ( !it.next().getName().equals( "C" ) ) {
5936                 return false;
5937             }
5938             if ( !it.next().getName().equals( "D" ) ) {
5939                 return false;
5940             }
5941             if ( it.hasNext() ) {
5942                 return false;
5943             }
5944             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",
5945                                                  new NHXParser() )[ 0 ];
5946             PhylogenyNodeIterator it2;
5947             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5948                 it2.next();
5949             }
5950             for( it2.reset(); it2.hasNext(); ) {
5951                 it2.next();
5952             }
5953             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5954             if ( !it3.next().getName().equals( "r" ) ) {
5955                 return false;
5956             }
5957             if ( !it3.next().getName().equals( "abc" ) ) {
5958                 return false;
5959             }
5960             if ( !it3.next().getName().equals( "defg" ) ) {
5961                 return false;
5962             }
5963             if ( !it3.next().getName().equals( "A" ) ) {
5964                 return false;
5965             }
5966             if ( !it3.next().getName().equals( "B" ) ) {
5967                 return false;
5968             }
5969             if ( !it3.next().getName().equals( "C" ) ) {
5970                 return false;
5971             }
5972             if ( !it3.next().getName().equals( "D" ) ) {
5973                 return false;
5974             }
5975             if ( !it3.next().getName().equals( "E" ) ) {
5976                 return false;
5977             }
5978             if ( !it3.next().getName().equals( "F" ) ) {
5979                 return false;
5980             }
5981             if ( !it3.next().getName().equals( "G" ) ) {
5982                 return false;
5983             }
5984             if ( !it3.next().getName().equals( "1" ) ) {
5985                 return false;
5986             }
5987             if ( !it3.next().getName().equals( "2" ) ) {
5988                 return false;
5989             }
5990             if ( !it3.next().getName().equals( "3" ) ) {
5991                 return false;
5992             }
5993             if ( !it3.next().getName().equals( "4" ) ) {
5994                 return false;
5995             }
5996             if ( !it3.next().getName().equals( "5" ) ) {
5997                 return false;
5998             }
5999             if ( !it3.next().getName().equals( "6" ) ) {
6000                 return false;
6001             }
6002             if ( !it3.next().getName().equals( "f1" ) ) {
6003                 return false;
6004             }
6005             if ( !it3.next().getName().equals( "f2" ) ) {
6006                 return false;
6007             }
6008             if ( !it3.next().getName().equals( "f3" ) ) {
6009                 return false;
6010             }
6011             if ( !it3.next().getName().equals( "a" ) ) {
6012                 return false;
6013             }
6014             if ( !it3.next().getName().equals( "b" ) ) {
6015                 return false;
6016             }
6017             if ( !it3.next().getName().equals( "f21" ) ) {
6018                 return false;
6019             }
6020             if ( !it3.next().getName().equals( "X" ) ) {
6021                 return false;
6022             }
6023             if ( !it3.next().getName().equals( "Y" ) ) {
6024                 return false;
6025             }
6026             if ( !it3.next().getName().equals( "Z" ) ) {
6027                 return false;
6028             }
6029             if ( it3.hasNext() ) {
6030                 return false;
6031             }
6032             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6033             PhylogenyNodeIterator it4;
6034             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6035                 it4.next();
6036             }
6037             for( it4.reset(); it4.hasNext(); ) {
6038                 it4.next();
6039             }
6040             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6041             if ( !it5.next().getName().equals( "r" ) ) {
6042                 return false;
6043             }
6044             if ( !it5.next().getName().equals( "A" ) ) {
6045                 return false;
6046             }
6047             if ( !it5.next().getName().equals( "B" ) ) {
6048                 return false;
6049             }
6050             if ( !it5.next().getName().equals( "C" ) ) {
6051                 return false;
6052             }
6053             if ( !it5.next().getName().equals( "D" ) ) {
6054                 return false;
6055             }
6056             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6057             PhylogenyNodeIterator it6;
6058             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6059                 it6.next();
6060             }
6061             for( it6.reset(); it6.hasNext(); ) {
6062                 it6.next();
6063             }
6064             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6065             if ( !it7.next().getName().equals( "A" ) ) {
6066                 return false;
6067             }
6068             if ( it.hasNext() ) {
6069                 return false;
6070             }
6071         }
6072         catch ( final Exception e ) {
6073             e.printStackTrace( System.out );
6074             return false;
6075         }
6076         return true;
6077     }
6078
6079     private static boolean testMafft( final String path ) {
6080         try {
6081             final List<String> opts = new ArrayList<String>();
6082             opts.add( "--maxiterate" );
6083             opts.add( "1000" );
6084             opts.add( "--localpair" );
6085             opts.add( "--quiet" );
6086             Msa msa = null;
6087             final MsaInferrer mafft = Mafft.createInstance( path );
6088             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6089             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6090                 return false;
6091             }
6092             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6093                 return false;
6094             }
6095         }
6096         catch ( final Exception e ) {
6097             e.printStackTrace( System.out );
6098             return false;
6099         }
6100         return true;
6101     }
6102
6103     private static boolean testMidpointrooting() {
6104         try {
6105             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6106             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6107             PhylogenyMethods.midpointRoot( t0 );
6108             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6109                 return false;
6110             }
6111             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6112                 return false;
6113             }
6114             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6115                            1 ) ) {
6116                 return false;
6117             }
6118             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",
6119                                                  new NHXParser() )[ 0 ];
6120             if ( !t1.isRooted() ) {
6121                 return false;
6122             }
6123             PhylogenyMethods.midpointRoot( t1 );
6124             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6125                 return false;
6126             }
6127             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6128                 return false;
6129             }
6130             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6131                 return false;
6132             }
6133             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6134                 return false;
6135             }
6136             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6137                 return false;
6138             }
6139             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6140                 return false;
6141             }
6142             t1.reRoot( t1.getNode( "A" ) );
6143             PhylogenyMethods.midpointRoot( t1 );
6144             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6145                 return false;
6146             }
6147             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6148                 return false;
6149             }
6150             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6151                 return false;
6152             }
6153             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6154                 return false;
6155             }
6156             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6157                 System.exit( -1 );
6158                 return false;
6159             }
6160             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6161                 return false;
6162             }
6163         }
6164         catch ( final Exception e ) {
6165             e.printStackTrace( System.out );
6166             return false;
6167         }
6168         return true;
6169     }
6170
6171     private static boolean testMsaQualityMethod() {
6172         try {
6173             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6174             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6175             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6176             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6177             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6178             l.add( s0 );
6179             l.add( s1 );
6180             l.add( s2 );
6181             l.add( s3 );
6182             final Msa msa = BasicMsa.createInstance( l );
6183             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6184                 return false;
6185             }
6186             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6187                 return false;
6188             }
6189             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6190                 return false;
6191             }
6192             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6193                 return false;
6194             }
6195             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6196                 return false;
6197             }
6198             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6199                 return false;
6200             }
6201             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6202                 return false;
6203             }
6204         }
6205         catch ( final Exception e ) {
6206             e.printStackTrace( System.out );
6207             return false;
6208         }
6209         return true;
6210     }
6211
6212     private static boolean testMsaEntropy() {
6213         try {
6214             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6215             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6216             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6217             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6218             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6219             l.add( s0 );
6220             l.add( s1 );
6221             l.add( s2 );
6222             l.add( s3 );
6223             final Msa msa = BasicMsa.createInstance( l );
6224             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6225             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6226             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6227             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6228             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6229             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6230             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6231             System.out.println();
6232             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6233             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6234             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6235             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6236             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6237             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6238             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6239             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6240             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6241             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6242             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6243             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6244             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6245             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6246             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6247             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6248             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6249             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6250             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6251             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6252             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6253             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6254             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6255             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6256             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6257             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6258             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6259             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6260             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6261             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6262             final Msa msa2 = BasicMsa.createInstance( l2 );
6263             System.out.println();
6264             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6265             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6266             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6267         }
6268         catch ( final Exception e ) {
6269             e.printStackTrace( System.out );
6270             return false;
6271         }
6272         return true;
6273     }
6274
6275     private static boolean testDeleteableMsa() {
6276         try {
6277             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6278             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6279             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6280             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6281             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6282             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6283             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6284             l0.add( s0 );
6285             l0.add( s1 );
6286             l0.add( s2 );
6287             l0.add( s3 );
6288             l0.add( s4 );
6289             l0.add( s5 );
6290             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6291             dmsa0.deleteRow( "b", false );
6292             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6293                 return false;
6294             }
6295             dmsa0.deleteRow( "e", false );
6296             dmsa0.deleteRow( "a", false );
6297             dmsa0.deleteRow( "f", false );
6298             if ( dmsa0.getLength() != 4 ) {
6299                 return false;
6300             }
6301             if ( dmsa0.getNumberOfSequences() != 2 ) {
6302                 return false;
6303             }
6304             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6305                 return false;
6306             }
6307             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6308                 return false;
6309             }
6310             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6311                 return false;
6312             }
6313             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6314                 return false;
6315             }
6316             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6317                 return false;
6318             }
6319             dmsa0.deleteRow( "c", false );
6320             dmsa0.deleteRow( "d", false );
6321             if ( dmsa0.getNumberOfSequences() != 0 ) {
6322                 return false;
6323             }
6324             //
6325             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6326             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6327             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6328             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6329             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6330             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6331             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6332             l1.add( s_0 );
6333             l1.add( s_1 );
6334             l1.add( s_2 );
6335             l1.add( s_3 );
6336             l1.add( s_4 );
6337             l1.add( s_5 );
6338             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6339             dmsa1.deleteGapOnlyColumns();
6340             dmsa1.deleteRow( "a", false );
6341             dmsa1.deleteRow( "f", false );
6342             dmsa1.deleteRow( "d", false );
6343             dmsa1.deleteGapOnlyColumns();
6344             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6345                 return false;
6346             }
6347             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6348                 return false;
6349             }
6350             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6351                 return false;
6352             }
6353             dmsa1.deleteRow( "c", false );
6354             dmsa1.deleteGapOnlyColumns();
6355             final Writer w0 = new StringWriter();
6356             dmsa1.write( w0, MSA_FORMAT.FASTA );
6357             final Writer w1 = new StringWriter();
6358             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6359             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6360                 return false;
6361             }
6362             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6363                 return false;
6364             }
6365             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6366             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6367             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6368             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6369             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6370             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6371             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6372             l2.add( s__0 );
6373             l2.add( s__1 );
6374             l2.add( s__2 );
6375             l2.add( s__3 );
6376             l2.add( s__4 );
6377             l2.add( s__5 );
6378             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6379             dmsa2.deleteGapColumns( 0.5 );
6380             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6381                 return false;
6382             }
6383             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6384                 return false;
6385             }
6386             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6387                 return false;
6388             }
6389             dmsa2.deleteGapColumns( 0.2 );
6390             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6391                 return false;
6392             }
6393             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6394                 return false;
6395             }
6396             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6397                 return false;
6398             }
6399             dmsa2.deleteGapColumns( 0 );
6400             dmsa2.deleteRow( "a", false );
6401             dmsa2.deleteRow( "b", false );
6402             dmsa2.deleteRow( "f", false );
6403             dmsa2.deleteRow( "e", false );
6404             dmsa2.setIdentifier( 0, "new_c" );
6405             dmsa2.setIdentifier( 1, "new_d" );
6406             dmsa2.setResidueAt( 0, 0, 'x' );
6407             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6408             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6409                 return false;
6410             }
6411             final Writer w = new StringWriter();
6412             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6413             final String phylip = w.toString();
6414             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6415                 System.out.println( phylip );
6416                 return false;
6417             }
6418             final Writer w2 = new StringWriter();
6419             dmsa2.write( w2, MSA_FORMAT.FASTA );
6420             final String fasta = w2.toString();
6421             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6422                 System.out.println( fasta );
6423                 return false;
6424             }
6425         }
6426         catch ( final Exception e ) {
6427             e.printStackTrace( System.out );
6428             return false;
6429         }
6430         return true;
6431     }
6432
6433     private static boolean testNextNodeWithCollapsing() {
6434         try {
6435             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6436             PhylogenyNode n;
6437             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6438             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6439             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6440             t0.getNode( "cd" ).setCollapse( true );
6441             t0.getNode( "cde" ).setCollapse( true );
6442             n = t0.getFirstExternalNode();
6443             while ( n != null ) {
6444                 ext.add( n );
6445                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6446             }
6447             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6448                 return false;
6449             }
6450             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6451                 return false;
6452             }
6453             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6454                 return false;
6455             }
6456             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6457                 return false;
6458             }
6459             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6460                 return false;
6461             }
6462             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6463                 return false;
6464             }
6465             ext.clear();
6466             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6467             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6468             t1.getNode( "ab" ).setCollapse( true );
6469             t1.getNode( "cd" ).setCollapse( true );
6470             t1.getNode( "cde" ).setCollapse( true );
6471             n = t1.getNode( "ab" );
6472             ext = new ArrayList<PhylogenyNode>();
6473             while ( n != null ) {
6474                 ext.add( n );
6475                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6476             }
6477             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6478                 return false;
6479             }
6480             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6481                 return false;
6482             }
6483             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6490                 return false;
6491             }
6492             ext.clear();
6493             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6494             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6495             t2.getNode( "ab" ).setCollapse( true );
6496             t2.getNode( "cd" ).setCollapse( true );
6497             t2.getNode( "cde" ).setCollapse( true );
6498             t2.getNode( "c" ).setCollapse( true );
6499             t2.getNode( "d" ).setCollapse( true );
6500             t2.getNode( "e" ).setCollapse( true );
6501             t2.getNode( "gh" ).setCollapse( true );
6502             n = t2.getNode( "ab" );
6503             ext = new ArrayList<PhylogenyNode>();
6504             while ( n != null ) {
6505                 ext.add( n );
6506                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6507             }
6508             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6509                 return false;
6510             }
6511             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6512                 return false;
6513             }
6514             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6515                 return false;
6516             }
6517             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6518                 return false;
6519             }
6520             ext.clear();
6521             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6522             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6523             t3.getNode( "ab" ).setCollapse( true );
6524             t3.getNode( "cd" ).setCollapse( true );
6525             t3.getNode( "cde" ).setCollapse( true );
6526             t3.getNode( "c" ).setCollapse( true );
6527             t3.getNode( "d" ).setCollapse( true );
6528             t3.getNode( "e" ).setCollapse( true );
6529             t3.getNode( "gh" ).setCollapse( true );
6530             t3.getNode( "fgh" ).setCollapse( true );
6531             n = t3.getNode( "ab" );
6532             ext = new ArrayList<PhylogenyNode>();
6533             while ( n != null ) {
6534                 ext.add( n );
6535                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6536             }
6537             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6538                 return false;
6539             }
6540             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6541                 return false;
6542             }
6543             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6544                 return false;
6545             }
6546             ext.clear();
6547             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6548             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6549             t4.getNode( "ab" ).setCollapse( true );
6550             t4.getNode( "cd" ).setCollapse( true );
6551             t4.getNode( "cde" ).setCollapse( true );
6552             t4.getNode( "c" ).setCollapse( true );
6553             t4.getNode( "d" ).setCollapse( true );
6554             t4.getNode( "e" ).setCollapse( true );
6555             t4.getNode( "gh" ).setCollapse( true );
6556             t4.getNode( "fgh" ).setCollapse( true );
6557             t4.getNode( "abcdefgh" ).setCollapse( true );
6558             n = t4.getNode( "abcdefgh" );
6559             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6560                 return false;
6561             }
6562             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6563             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6564             ext.clear();
6565             n = t5.getFirstExternalNode();
6566             while ( n != null ) {
6567                 ext.add( n );
6568                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6569             }
6570             if ( ext.size() != 8 ) {
6571                 return false;
6572             }
6573             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6574                 return false;
6575             }
6576             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6577                 return false;
6578             }
6579             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6595                 return false;
6596             }
6597             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6598             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6599             ext.clear();
6600             t6.getNode( "ab" ).setCollapse( true );
6601             n = t6.getNode( "ab" );
6602             while ( n != null ) {
6603                 ext.add( n );
6604                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6605             }
6606             if ( ext.size() != 7 ) {
6607                 return false;
6608             }
6609             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6610                 return false;
6611             }
6612             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6628                 return false;
6629             }
6630             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6631             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6632             ext.clear();
6633             t7.getNode( "cd" ).setCollapse( true );
6634             n = t7.getNode( "a" );
6635             while ( n != null ) {
6636                 ext.add( n );
6637                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6638             }
6639             if ( ext.size() != 7 ) {
6640                 return false;
6641             }
6642             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6643                 return false;
6644             }
6645             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6646                 return false;
6647             }
6648             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6661                 return false;
6662             }
6663             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6664             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6665             ext.clear();
6666             t8.getNode( "cd" ).setCollapse( true );
6667             t8.getNode( "c" ).setCollapse( true );
6668             t8.getNode( "d" ).setCollapse( true );
6669             n = t8.getNode( "a" );
6670             while ( n != null ) {
6671                 ext.add( n );
6672                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6673             }
6674             if ( ext.size() != 7 ) {
6675                 return false;
6676             }
6677             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6678                 return false;
6679             }
6680             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6681                 return false;
6682             }
6683             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6684                 System.out.println( "2 fail" );
6685                 return false;
6686             }
6687             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6688                 return false;
6689             }
6690             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6691                 return false;
6692             }
6693             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6694                 return false;
6695             }
6696             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6697                 return false;
6698             }
6699             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6700             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6701             ext.clear();
6702             t9.getNode( "gh" ).setCollapse( true );
6703             n = t9.getNode( "a" );
6704             while ( n != null ) {
6705                 ext.add( n );
6706                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6707             }
6708             if ( ext.size() != 7 ) {
6709                 return false;
6710             }
6711             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6712                 return false;
6713             }
6714             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6715                 return false;
6716             }
6717             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6724                 return false;
6725             }
6726             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6727                 return false;
6728             }
6729             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6730                 return false;
6731             }
6732             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6733             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6734             ext.clear();
6735             t10.getNode( "gh" ).setCollapse( true );
6736             t10.getNode( "g" ).setCollapse( true );
6737             t10.getNode( "h" ).setCollapse( true );
6738             n = t10.getNode( "a" );
6739             while ( n != null ) {
6740                 ext.add( n );
6741                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6742             }
6743             if ( ext.size() != 7 ) {
6744                 return false;
6745             }
6746             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6747                 return false;
6748             }
6749             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6750                 return false;
6751             }
6752             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6753                 return false;
6754             }
6755             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6756                 return false;
6757             }
6758             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6759                 return false;
6760             }
6761             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6762                 return false;
6763             }
6764             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6765                 return false;
6766             }
6767             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6768             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6769             ext.clear();
6770             t11.getNode( "gh" ).setCollapse( true );
6771             t11.getNode( "fgh" ).setCollapse( true );
6772             n = t11.getNode( "a" );
6773             while ( n != null ) {
6774                 ext.add( n );
6775                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6776             }
6777             if ( ext.size() != 6 ) {
6778                 return false;
6779             }
6780             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6781                 return false;
6782             }
6783             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6784                 return false;
6785             }
6786             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6796                 return false;
6797             }
6798             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6799             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6800             ext.clear();
6801             t12.getNode( "gh" ).setCollapse( true );
6802             t12.getNode( "fgh" ).setCollapse( true );
6803             t12.getNode( "g" ).setCollapse( true );
6804             t12.getNode( "h" ).setCollapse( true );
6805             t12.getNode( "f" ).setCollapse( true );
6806             n = t12.getNode( "a" );
6807             while ( n != null ) {
6808                 ext.add( n );
6809                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6810             }
6811             if ( ext.size() != 6 ) {
6812                 return false;
6813             }
6814             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6815                 return false;
6816             }
6817             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6818                 return false;
6819             }
6820             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6821                 return false;
6822             }
6823             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6824                 return false;
6825             }
6826             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6827                 return false;
6828             }
6829             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6830                 return false;
6831             }
6832             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6833             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6834             ext.clear();
6835             t13.getNode( "ab" ).setCollapse( true );
6836             t13.getNode( "b" ).setCollapse( true );
6837             t13.getNode( "fgh" ).setCollapse( true );
6838             t13.getNode( "gh" ).setCollapse( true );
6839             n = t13.getNode( "ab" );
6840             while ( n != null ) {
6841                 ext.add( n );
6842                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6843             }
6844             if ( ext.size() != 5 ) {
6845                 return false;
6846             }
6847             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6848                 return false;
6849             }
6850             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6851                 return false;
6852             }
6853             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6857                 return false;
6858             }
6859             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6860                 return false;
6861             }
6862             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6863             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6864             ext.clear();
6865             t14.getNode( "ab" ).setCollapse( true );
6866             t14.getNode( "a" ).setCollapse( true );
6867             t14.getNode( "fgh" ).setCollapse( true );
6868             t14.getNode( "gh" ).setCollapse( true );
6869             n = t14.getNode( "ab" );
6870             while ( n != null ) {
6871                 ext.add( n );
6872                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6873             }
6874             if ( ext.size() != 5 ) {
6875                 return false;
6876             }
6877             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6878                 return false;
6879             }
6880             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6881                 return false;
6882             }
6883             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6887                 return false;
6888             }
6889             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6890                 return false;
6891             }
6892             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" );
6893             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6894             ext.clear();
6895             t15.getNode( "ab" ).setCollapse( true );
6896             t15.getNode( "a" ).setCollapse( true );
6897             t15.getNode( "fgh" ).setCollapse( true );
6898             t15.getNode( "gh" ).setCollapse( true );
6899             n = t15.getNode( "ab" );
6900             while ( n != null ) {
6901                 ext.add( n );
6902                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6903             }
6904             if ( ext.size() != 6 ) {
6905                 return false;
6906             }
6907             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6908                 return false;
6909             }
6910             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6920                 return false;
6921             }
6922             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6923                 return false;
6924             }
6925             //
6926             //
6927             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" );
6928             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6929             ext.clear();
6930             t16.getNode( "ab" ).setCollapse( true );
6931             t16.getNode( "a" ).setCollapse( true );
6932             t16.getNode( "fgh" ).setCollapse( true );
6933             t16.getNode( "gh" ).setCollapse( true );
6934             t16.getNode( "cd" ).setCollapse( true );
6935             t16.getNode( "cde" ).setCollapse( true );
6936             t16.getNode( "d" ).setCollapse( true );
6937             t16.getNode( "x" ).setCollapse( true );
6938             n = t16.getNode( "ab" );
6939             while ( n != null ) {
6940                 ext.add( n );
6941                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6942             }
6943             if ( ext.size() != 4 ) {
6944                 return false;
6945             }
6946             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6947                 return false;
6948             }
6949             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6950                 return false;
6951             }
6952             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6953                 return false;
6954             }
6955             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6956                 return false;
6957             }
6958         }
6959         catch ( final Exception e ) {
6960             e.printStackTrace( System.out );
6961             return false;
6962         }
6963         return true;
6964     }
6965
6966     private static boolean testNexusCharactersParsing() {
6967         try {
6968             final NexusCharactersParser parser = new NexusCharactersParser();
6969             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6970             parser.parse();
6971             String[] labels = parser.getCharStateLabels();
6972             if ( labels.length != 7 ) {
6973                 return false;
6974             }
6975             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6976                 return false;
6977             }
6978             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6979                 return false;
6980             }
6981             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6982                 return false;
6983             }
6984             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6985                 return false;
6986             }
6987             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6988                 return false;
6989             }
6990             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6991                 return false;
6992             }
6993             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6994                 return false;
6995             }
6996             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6997             parser.parse();
6998             labels = parser.getCharStateLabels();
6999             if ( labels.length != 7 ) {
7000                 return false;
7001             }
7002             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7003                 return false;
7004             }
7005             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7006                 return false;
7007             }
7008             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7009                 return false;
7010             }
7011             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7012                 return false;
7013             }
7014             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7015                 return false;
7016             }
7017             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7018                 return false;
7019             }
7020             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7021                 return false;
7022             }
7023         }
7024         catch ( final Exception e ) {
7025             e.printStackTrace( System.out );
7026             return false;
7027         }
7028         return true;
7029     }
7030
7031     private static boolean testNexusMatrixParsing() {
7032         try {
7033             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7034             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7035             parser.parse();
7036             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7037             if ( m.getNumberOfCharacters() != 9 ) {
7038                 return false;
7039             }
7040             if ( m.getNumberOfIdentifiers() != 5 ) {
7041                 return false;
7042             }
7043             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7044                 return false;
7045             }
7046             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7047                 return false;
7048             }
7049             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7050                 return false;
7051             }
7052             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7053                 return false;
7054             }
7055             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7056                 return false;
7057             }
7058             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7059                 return false;
7060             }
7061             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7062                 return false;
7063             }
7064             //            if ( labels.length != 7 ) {
7065             //                return false;
7066             //            }
7067             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7068             //                return false;
7069             //            }
7070             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7071             //                return false;
7072             //            }
7073             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7074             //                return false;
7075             //            }
7076             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7077             //                return false;
7078             //            }
7079             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7080             //                return false;
7081             //            }
7082             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7083             //                return false;
7084             //            }
7085             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7086             //                return false;
7087             //            }
7088             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7089             //            parser.parse();
7090             //            labels = parser.getCharStateLabels();
7091             //            if ( labels.length != 7 ) {
7092             //                return false;
7093             //            }
7094             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7095             //                return false;
7096             //            }
7097             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7098             //                return false;
7099             //            }
7100             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7104             //                return false;
7105             //            }
7106             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7107             //                return false;
7108             //            }
7109             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7110             //                return false;
7111             //            }
7112             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7113             //                return false;
7114             //            }
7115         }
7116         catch ( final Exception e ) {
7117             e.printStackTrace( System.out );
7118             return false;
7119         }
7120         return true;
7121     }
7122
7123     private static boolean testNexusTreeParsing() {
7124         try {
7125             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7126             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7127             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7128             if ( phylogenies.length != 1 ) {
7129                 return false;
7130             }
7131             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7132                 return false;
7133             }
7134             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7135                 return false;
7136             }
7137             phylogenies = null;
7138             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7139             if ( phylogenies.length != 1 ) {
7140                 return false;
7141             }
7142             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7143                 return false;
7144             }
7145             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7146                 return false;
7147             }
7148             phylogenies = null;
7149             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7150             if ( phylogenies.length != 1 ) {
7151                 return false;
7152             }
7153             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7154                 return false;
7155             }
7156             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7157                 return false;
7158             }
7159             if ( phylogenies[ 0 ].isRooted() ) {
7160                 return false;
7161             }
7162             phylogenies = null;
7163             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7164             if ( phylogenies.length != 18 ) {
7165                 return false;
7166             }
7167             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7168                 return false;
7169             }
7170             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7171                 return false;
7172             }
7173             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7174                 return false;
7175             }
7176             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7177                 return false;
7178             }
7179             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7180                 return false;
7181             }
7182             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7183                 return false;
7184             }
7185             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7186                 return false;
7187             }
7188             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7189                 return false;
7190             }
7191             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7192                 return false;
7193             }
7194             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7195                 return false;
7196             }
7197             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7198                 return false;
7199             }
7200             if ( phylogenies[ 8 ].isRooted() ) {
7201                 return false;
7202             }
7203             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7204                 return false;
7205             }
7206             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7207                 return false;
7208             }
7209             if ( !phylogenies[ 9 ].isRooted() ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7216                 return false;
7217             }
7218             if ( !phylogenies[ 10 ].isRooted() ) {
7219                 return false;
7220             }
7221             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7225                 return false;
7226             }
7227             if ( phylogenies[ 11 ].isRooted() ) {
7228                 return false;
7229             }
7230             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7231                 return false;
7232             }
7233             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7234                 return false;
7235             }
7236             if ( !phylogenies[ 12 ].isRooted() ) {
7237                 return false;
7238             }
7239             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 13 ].isRooted() ) {
7246                 return false;
7247             }
7248             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7249                 return false;
7250             }
7251             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7252                 return false;
7253             }
7254             if ( !phylogenies[ 14 ].isRooted() ) {
7255                 return false;
7256             }
7257             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7258                 return false;
7259             }
7260             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7261                 return false;
7262             }
7263             if ( phylogenies[ 15 ].isRooted() ) {
7264                 return false;
7265             }
7266             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7270                 return false;
7271             }
7272             if ( !phylogenies[ 16 ].isRooted() ) {
7273                 return false;
7274             }
7275             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7276                 return false;
7277             }
7278             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7279                 return false;
7280             }
7281             if ( phylogenies[ 17 ].isRooted() ) {
7282                 return false;
7283             }
7284             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7285                 return false;
7286             }
7287             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7288             phylogenies = null;
7289             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7290             if ( phylogenies.length != 9 ) {
7291                 return false;
7292             }
7293             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7294                     .getDistanceToParent() ) ) {
7295                 return false;
7296             }
7297             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7298                     .getDistanceToParent() ) ) {
7299                 return false;
7300             }
7301             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7302                 return false;
7303             }
7304             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7305                 return false;
7306             }
7307             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7308                 return false;
7309             }
7310             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7311                 return false;
7312             }
7313             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7314                 return false;
7315             }
7316         }
7317         catch ( final Exception e ) {
7318             e.printStackTrace( System.out );
7319             return false;
7320         }
7321         return true;
7322     }
7323
7324     private static boolean testNexusTreeParsingIterating() {
7325         try {
7326             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7327             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7328             if ( !p.hasNext() ) {
7329                 return false;
7330             }
7331             Phylogeny phy = p.next();
7332             if ( phy == null ) {
7333                 return false;
7334             }
7335             if ( phy.getNumberOfExternalNodes() != 25 ) {
7336                 return false;
7337             }
7338             if ( !phy.getName().equals( "" ) ) {
7339                 return false;
7340             }
7341             if ( p.hasNext() ) {
7342                 return false;
7343             }
7344             phy = p.next();
7345             if ( phy != null ) {
7346                 return false;
7347             }
7348             p.reset();
7349             if ( !p.hasNext() ) {
7350                 return false;
7351             }
7352             phy = p.next();
7353             if ( phy == null ) {
7354                 return false;
7355             }
7356             if ( phy.getNumberOfExternalNodes() != 25 ) {
7357                 return false;
7358             }
7359             if ( !phy.getName().equals( "" ) ) {
7360                 return false;
7361             }
7362             if ( p.hasNext() ) {
7363                 return false;
7364             }
7365             phy = p.next();
7366             if ( phy != null ) {
7367                 return false;
7368             }
7369             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7370             if ( !p.hasNext() ) {
7371                 return false;
7372             }
7373             phy = p.next();
7374             if ( phy == null ) {
7375                 return false;
7376             }
7377             if ( phy.getNumberOfExternalNodes() != 10 ) {
7378                 return false;
7379             }
7380             if ( !phy.getName().equals( "name" ) ) {
7381                 return false;
7382             }
7383             if ( p.hasNext() ) {
7384                 return false;
7385             }
7386             phy = p.next();
7387             if ( phy != null ) {
7388                 return false;
7389             }
7390             p.reset();
7391             if ( !p.hasNext() ) {
7392                 return false;
7393             }
7394             phy = p.next();
7395             if ( phy == null ) {
7396                 return false;
7397             }
7398             if ( phy.getNumberOfExternalNodes() != 10 ) {
7399                 return false;
7400             }
7401             if ( !phy.getName().equals( "name" ) ) {
7402                 return false;
7403             }
7404             if ( p.hasNext() ) {
7405                 return false;
7406             }
7407             phy = p.next();
7408             if ( phy != null ) {
7409                 return false;
7410             }
7411             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7412             if ( !p.hasNext() ) {
7413                 return false;
7414             }
7415             phy = p.next();
7416             if ( phy == null ) {
7417                 return false;
7418             }
7419             if ( phy.getNumberOfExternalNodes() != 3 ) {
7420                 return false;
7421             }
7422             if ( !phy.getName().equals( "" ) ) {
7423                 return false;
7424             }
7425             if ( phy.isRooted() ) {
7426                 return false;
7427             }
7428             if ( p.hasNext() ) {
7429                 return false;
7430             }
7431             phy = p.next();
7432             if ( phy != null ) {
7433                 return false;
7434             }
7435             //
7436             p.reset();
7437             if ( !p.hasNext() ) {
7438                 return false;
7439             }
7440             phy = p.next();
7441             if ( phy == null ) {
7442                 return false;
7443             }
7444             if ( phy.getNumberOfExternalNodes() != 3 ) {
7445                 return false;
7446             }
7447             if ( !phy.getName().equals( "" ) ) {
7448                 return false;
7449             }
7450             if ( p.hasNext() ) {
7451                 return false;
7452             }
7453             phy = p.next();
7454             if ( phy != null ) {
7455                 return false;
7456             }
7457             //
7458             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7459             if ( !p.hasNext() ) {
7460                 return false;
7461             }
7462             //0
7463             phy = p.next();
7464             if ( phy == null ) {
7465                 return false;
7466             }
7467             if ( phy.getNumberOfExternalNodes() != 10 ) {
7468                 return false;
7469             }
7470             if ( !phy.getName().equals( "tree 0" ) ) {
7471                 return false;
7472             }
7473             //1
7474             if ( !p.hasNext() ) {
7475                 return false;
7476             }
7477             phy = p.next();
7478             if ( phy == null ) {
7479                 return false;
7480             }
7481             if ( phy.getNumberOfExternalNodes() != 10 ) {
7482                 return false;
7483             }
7484             if ( !phy.getName().equals( "tree 1" ) ) {
7485                 return false;
7486             }
7487             //2
7488             if ( !p.hasNext() ) {
7489                 return false;
7490             }
7491             phy = p.next();
7492             if ( phy == null ) {
7493                 return false;
7494             }
7495             if ( phy.getNumberOfExternalNodes() != 3 ) {
7496                 System.out.println( phy.toString() );
7497                 return false;
7498             }
7499             if ( !phy.getName().equals( "" ) ) {
7500                 return false;
7501             }
7502             if ( phy.isRooted() ) {
7503                 return false;
7504             }
7505             //3
7506             if ( !p.hasNext() ) {
7507                 return false;
7508             }
7509             phy = p.next();
7510             if ( phy == null ) {
7511                 return false;
7512             }
7513             if ( phy.getNumberOfExternalNodes() != 4 ) {
7514                 return false;
7515             }
7516             if ( !phy.getName().equals( "" ) ) {
7517                 return false;
7518             }
7519             if ( !phy.isRooted() ) {
7520                 return false;
7521             }
7522             //4
7523             if ( !p.hasNext() ) {
7524                 return false;
7525             }
7526             phy = p.next();
7527             if ( phy == null ) {
7528                 return false;
7529             }
7530             if ( phy.getNumberOfExternalNodes() != 5 ) {
7531                 System.out.println( phy.getNumberOfExternalNodes() );
7532                 return false;
7533             }
7534             if ( !phy.getName().equals( "" ) ) {
7535                 return false;
7536             }
7537             if ( !phy.isRooted() ) {
7538                 return false;
7539             }
7540             //5
7541             if ( !p.hasNext() ) {
7542                 return false;
7543             }
7544             phy = p.next();
7545             if ( phy == null ) {
7546                 return false;
7547             }
7548             if ( phy.getNumberOfExternalNodes() != 3 ) {
7549                 return false;
7550             }
7551             if ( !phy.getName().equals( "" ) ) {
7552                 return false;
7553             }
7554             if ( phy.isRooted() ) {
7555                 return false;
7556             }
7557             //6
7558             if ( !p.hasNext() ) {
7559                 return false;
7560             }
7561             phy = p.next();
7562             if ( phy == null ) {
7563                 return false;
7564             }
7565             if ( phy.getNumberOfExternalNodes() != 2 ) {
7566                 return false;
7567             }
7568             if ( !phy.getName().equals( "" ) ) {
7569                 return false;
7570             }
7571             if ( !phy.isRooted() ) {
7572                 return false;
7573             }
7574             //7
7575             if ( !p.hasNext() ) {
7576                 return false;
7577             }
7578             phy = p.next();
7579             if ( phy.getNumberOfExternalNodes() != 3 ) {
7580                 return false;
7581             }
7582             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7583                 return false;
7584             }
7585             if ( !phy.isRooted() ) {
7586                 return false;
7587             }
7588             //8
7589             if ( !p.hasNext() ) {
7590                 return false;
7591             }
7592             phy = p.next();
7593             if ( phy.getNumberOfExternalNodes() != 3 ) {
7594                 return false;
7595             }
7596             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7597                 return false;
7598             }
7599             if ( !phy.getName().equals( "tree 8" ) ) {
7600                 return false;
7601             }
7602             //9
7603             if ( !p.hasNext() ) {
7604                 return false;
7605             }
7606             phy = p.next();
7607             if ( phy.getNumberOfExternalNodes() != 3 ) {
7608                 return false;
7609             }
7610             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7611                 return false;
7612             }
7613             if ( !phy.getName().equals( "tree 9" ) ) {
7614                 return false;
7615             }
7616             //10
7617             if ( !p.hasNext() ) {
7618                 return false;
7619             }
7620             phy = p.next();
7621             if ( phy.getNumberOfExternalNodes() != 3 ) {
7622                 return false;
7623             }
7624             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7625                 return false;
7626             }
7627             if ( !phy.getName().equals( "tree 10" ) ) {
7628                 return false;
7629             }
7630             if ( !phy.isRooted() ) {
7631                 return false;
7632             }
7633             //11
7634             if ( !p.hasNext() ) {
7635                 return false;
7636             }
7637             phy = p.next();
7638             if ( phy.getNumberOfExternalNodes() != 3 ) {
7639                 return false;
7640             }
7641             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7642                 return false;
7643             }
7644             if ( !phy.getName().equals( "tree 11" ) ) {
7645                 return false;
7646             }
7647             if ( phy.isRooted() ) {
7648                 return false;
7649             }
7650             //12
7651             if ( !p.hasNext() ) {
7652                 return false;
7653             }
7654             phy = p.next();
7655             if ( phy.getNumberOfExternalNodes() != 3 ) {
7656                 return false;
7657             }
7658             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7659                 return false;
7660             }
7661             if ( !phy.getName().equals( "tree 12" ) ) {
7662                 return false;
7663             }
7664             if ( !phy.isRooted() ) {
7665                 return false;
7666             }
7667             //13
7668             if ( !p.hasNext() ) {
7669                 return false;
7670             }
7671             phy = p.next();
7672             if ( phy.getNumberOfExternalNodes() != 3 ) {
7673                 return false;
7674             }
7675             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7676                 return false;
7677             }
7678             if ( !phy.getName().equals( "tree 13" ) ) {
7679                 return false;
7680             }
7681             if ( !phy.isRooted() ) {
7682                 return false;
7683             }
7684             //14
7685             if ( !p.hasNext() ) {
7686                 return false;
7687             }
7688             phy = p.next();
7689             if ( phy.getNumberOfExternalNodes() != 10 ) {
7690                 System.out.println( phy.getNumberOfExternalNodes() );
7691                 return false;
7692             }
7693             if ( !phy
7694                     .toNewHampshire()
7695                     .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;" ) ) {
7696                 System.out.println( phy.toNewHampshire() );
7697                 return false;
7698             }
7699             if ( !phy.getName().equals( "tree 14" ) ) {
7700                 return false;
7701             }
7702             if ( !phy.isRooted() ) {
7703                 return false;
7704             }
7705             //15
7706             if ( !p.hasNext() ) {
7707                 return false;
7708             }
7709             phy = p.next();
7710             if ( phy.getNumberOfExternalNodes() != 10 ) {
7711                 System.out.println( phy.getNumberOfExternalNodes() );
7712                 return false;
7713             }
7714             if ( !phy
7715                     .toNewHampshire()
7716                     .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;" ) ) {
7717                 System.out.println( phy.toNewHampshire() );
7718                 return false;
7719             }
7720             if ( !phy.getName().equals( "tree 15" ) ) {
7721                 return false;
7722             }
7723             if ( phy.isRooted() ) {
7724                 return false;
7725             }
7726             //16
7727             if ( !p.hasNext() ) {
7728                 return false;
7729             }
7730             phy = p.next();
7731             if ( phy.getNumberOfExternalNodes() != 10 ) {
7732                 System.out.println( phy.getNumberOfExternalNodes() );
7733                 return false;
7734             }
7735             if ( !phy
7736                     .toNewHampshire()
7737                     .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;" ) ) {
7738                 System.out.println( phy.toNewHampshire() );
7739                 return false;
7740             }
7741             if ( !phy.getName().equals( "tree 16" ) ) {
7742                 return false;
7743             }
7744             if ( !phy.isRooted() ) {
7745                 return false;
7746             }
7747             //17
7748             if ( !p.hasNext() ) {
7749                 return false;
7750             }
7751             phy = p.next();
7752             if ( phy.getNumberOfExternalNodes() != 10 ) {
7753                 System.out.println( phy.getNumberOfExternalNodes() );
7754                 return false;
7755             }
7756             if ( !phy
7757                     .toNewHampshire()
7758                     .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;" ) ) {
7759                 System.out.println( phy.toNewHampshire() );
7760                 return false;
7761             }
7762             if ( !phy.getName().equals( "tree 17" ) ) {
7763                 return false;
7764             }
7765             if ( phy.isRooted() ) {
7766                 return false;
7767             }
7768             //
7769             if ( p.hasNext() ) {
7770                 return false;
7771             }
7772             phy = p.next();
7773             if ( phy != null ) {
7774                 return false;
7775             }
7776             p.reset();
7777             //0
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy == null ) {
7783                 return false;
7784             }
7785             if ( phy.getNumberOfExternalNodes() != 10 ) {
7786                 return false;
7787             }
7788             if ( !phy.getName().equals( "tree 0" ) ) {
7789                 return false;
7790             }
7791             //1
7792             if ( !p.hasNext() ) {
7793                 return false;
7794             }
7795             phy = p.next();
7796             if ( phy == null ) {
7797                 return false;
7798             }
7799             if ( phy.getNumberOfExternalNodes() != 10 ) {
7800                 return false;
7801             }
7802             if ( !phy.getName().equals( "tree 1" ) ) {
7803                 return false;
7804             }
7805             //2
7806             if ( !p.hasNext() ) {
7807                 return false;
7808             }
7809             phy = p.next();
7810             if ( phy == null ) {
7811                 return false;
7812             }
7813             if ( phy.getNumberOfExternalNodes() != 3 ) {
7814                 return false;
7815             }
7816             if ( !phy.getName().equals( "" ) ) {
7817                 return false;
7818             }
7819             if ( phy.isRooted() ) {
7820                 return false;
7821             }
7822             //3
7823             if ( !p.hasNext() ) {
7824                 return false;
7825             }
7826             phy = p.next();
7827             if ( phy == null ) {
7828                 return false;
7829             }
7830             if ( phy.getNumberOfExternalNodes() != 4 ) {
7831                 return false;
7832             }
7833             if ( !phy.getName().equals( "" ) ) {
7834                 return false;
7835             }
7836             if ( !phy.isRooted() ) {
7837                 return false;
7838             }
7839             //4
7840             if ( !p.hasNext() ) {
7841                 return false;
7842             }
7843             phy = p.next();
7844             if ( phy == null ) {
7845                 return false;
7846             }
7847             if ( phy.getNumberOfExternalNodes() != 5 ) {
7848                 System.out.println( phy.getNumberOfExternalNodes() );
7849                 return false;
7850             }
7851             if ( !phy.getName().equals( "" ) ) {
7852                 return false;
7853             }
7854             if ( !phy.isRooted() ) {
7855                 return false;
7856             }
7857             //5
7858             if ( !p.hasNext() ) {
7859                 return false;
7860             }
7861             phy = p.next();
7862             if ( phy == null ) {
7863                 return false;
7864             }
7865             if ( phy.getNumberOfExternalNodes() != 3 ) {
7866                 return false;
7867             }
7868             if ( !phy.getName().equals( "" ) ) {
7869                 return false;
7870             }
7871             if ( phy.isRooted() ) {
7872                 return false;
7873             }
7874             //
7875             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7876             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7877             // 0
7878             if ( !p2.hasNext() ) {
7879                 return false;
7880             }
7881             phy = p2.next();
7882             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7883                 return false;
7884             }
7885             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7886                 return false;
7887             }
7888             // 1
7889             if ( !p2.hasNext() ) {
7890                 return false;
7891             }
7892             phy = p2.next();
7893             // 2
7894             if ( !p2.hasNext() ) {
7895                 return false;
7896             }
7897             phy = p2.next();
7898             // 3
7899             if ( !p2.hasNext() ) {
7900                 return false;
7901             }
7902             phy = p2.next();
7903             // 4
7904             if ( !p2.hasNext() ) {
7905                 return false;
7906             }
7907             phy = p2.next();
7908             // 5
7909             if ( !p2.hasNext() ) {
7910                 return false;
7911             }
7912             phy = p2.next();
7913             // 6
7914             if ( !p2.hasNext() ) {
7915                 return false;
7916             }
7917             phy = p2.next();
7918             // 7
7919             if ( !p2.hasNext() ) {
7920                 return false;
7921             }
7922             phy = p2.next();
7923             // 8
7924             if ( !p2.hasNext() ) {
7925                 return false;
7926             }
7927             phy = p2.next();
7928             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7929                 return false;
7930             }
7931             if ( p2.hasNext() ) {
7932                 return false;
7933             }
7934             phy = p2.next();
7935             if ( phy != null ) {
7936                 return false;
7937             }
7938             // 0
7939             p2.reset();
7940             if ( !p2.hasNext() ) {
7941                 return false;
7942             }
7943             phy = p2.next();
7944             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7945                 return false;
7946             }
7947             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7948                 return false;
7949             }
7950         }
7951         catch ( final Exception e ) {
7952             e.printStackTrace( System.out );
7953             return false;
7954         }
7955         return true;
7956     }
7957
7958     private static boolean testNexusTreeParsingTranslating() {
7959         try {
7960             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7961             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7962             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7963             if ( phylogenies.length != 1 ) {
7964                 return false;
7965             }
7966             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7967                 return false;
7968             }
7969             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7970                 return false;
7971             }
7972             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7973                 return false;
7974             }
7975             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7976                 return false;
7977             }
7978             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7979                     .equals( "Aranaeus" ) ) {
7980                 return false;
7981             }
7982             phylogenies = null;
7983             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7984             if ( phylogenies.length != 3 ) {
7985                 return false;
7986             }
7987             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7988                 return false;
7989             }
7990             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7991                 return false;
7992             }
7993             if ( phylogenies[ 0 ].isRooted() ) {
7994                 return false;
7995             }
7996             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7997                 return false;
7998             }
7999             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8000                 return false;
8001             }
8002             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8003                     .equals( "Aranaeus" ) ) {
8004                 return false;
8005             }
8006             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8007                 return false;
8008             }
8009             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8010                 return false;
8011             }
8012             if ( phylogenies[ 1 ].isRooted() ) {
8013                 return false;
8014             }
8015             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8016                 return false;
8017             }
8018             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8019                 return false;
8020             }
8021             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8022                     .equals( "Aranaeus" ) ) {
8023                 return false;
8024             }
8025             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8026                 return false;
8027             }
8028             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8029                 return false;
8030             }
8031             if ( !phylogenies[ 2 ].isRooted() ) {
8032                 return false;
8033             }
8034             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8035                 return false;
8036             }
8037             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8038                 return false;
8039             }
8040             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8041                     .equals( "Aranaeus" ) ) {
8042                 return false;
8043             }
8044             phylogenies = null;
8045             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8046             if ( phylogenies.length != 3 ) {
8047                 return false;
8048             }
8049             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8050                 return false;
8051             }
8052             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8053                 return false;
8054             }
8055             if ( phylogenies[ 0 ].isRooted() ) {
8056                 return false;
8057             }
8058             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8059                 return false;
8060             }
8061             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8062                 return false;
8063             }
8064             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8065                     .equals( "Aranaeus" ) ) {
8066                 return false;
8067             }
8068             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8069                 return false;
8070             }
8071             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8072                 return false;
8073             }
8074             if ( phylogenies[ 1 ].isRooted() ) {
8075                 return false;
8076             }
8077             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8078                 return false;
8079             }
8080             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8081                 return false;
8082             }
8083             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8084                     .equals( "Aranaeus" ) ) {
8085                 return false;
8086             }
8087             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8088                 return false;
8089             }
8090             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8091                 return false;
8092             }
8093             if ( !phylogenies[ 2 ].isRooted() ) {
8094                 return false;
8095             }
8096             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8097                 return false;
8098             }
8099             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8100                 return false;
8101             }
8102             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8103                     .equals( "Aranaeus" ) ) {
8104                 return false;
8105             }
8106             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8107             if ( phylogenies.length != 3 ) {
8108                 return false;
8109             }
8110             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8111                            0.00100049 ) ) {
8112                 return false;
8113             }
8114         }
8115         catch ( final Exception e ) {
8116             e.printStackTrace( System.out );
8117             return false;
8118         }
8119         return true;
8120     }
8121
8122     private static boolean testNHParsing() {
8123         try {
8124             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8125             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8126             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8127                 return false;
8128             }
8129             final NHXParser nhxp = new NHXParser();
8130             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8131             nhxp.setReplaceUnderscores( true );
8132             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8133             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8134                 return false;
8135             }
8136             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8137                 return false;
8138             }
8139             final Phylogeny p1b = factory
8140                     .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 ",
8141                              new NHXParser() )[ 0 ];
8142             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8143                 return false;
8144             }
8145             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8146                 return false;
8147             }
8148             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8149             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8150             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8151             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8152             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8153             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8154             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8155             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8156             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8157             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8158             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8159                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8160                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8161                                                     new NHXParser() );
8162             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8163                 return false;
8164             }
8165             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8166                 return false;
8167             }
8168             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8169                 return false;
8170             }
8171             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8172                 return false;
8173             }
8174             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8175             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8176             final String p16_S = "((A,B),C)";
8177             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8178             if ( p16.length != 1 ) {
8179                 return false;
8180             }
8181             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8182                 return false;
8183             }
8184             final String p17_S = "(C,(A,B))";
8185             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8186             if ( p17.length != 1 ) {
8187                 return false;
8188             }
8189             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8190                 return false;
8191             }
8192             final String p18_S = "((A,B),(C,D))";
8193             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8194             if ( p18.length != 1 ) {
8195                 return false;
8196             }
8197             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8198                 return false;
8199             }
8200             final String p19_S = "(((A,B),C),D)";
8201             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8202             if ( p19.length != 1 ) {
8203                 return false;
8204             }
8205             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8206                 return false;
8207             }
8208             final String p20_S = "(A,(B,(C,D)))";
8209             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8210             if ( p20.length != 1 ) {
8211                 return false;
8212             }
8213             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8214                 return false;
8215             }
8216             final String p21_S = "(A,(B,(C,(D,E))))";
8217             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8218             if ( p21.length != 1 ) {
8219                 return false;
8220             }
8221             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8222                 return false;
8223             }
8224             final String p22_S = "((((A,B),C),D),E)";
8225             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8226             if ( p22.length != 1 ) {
8227                 return false;
8228             }
8229             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8230                 return false;
8231             }
8232             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8233             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8234             if ( p23.length != 1 ) {
8235                 System.out.println( "xl=" + p23.length );
8236                 System.exit( -1 );
8237                 return false;
8238             }
8239             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8240                 return false;
8241             }
8242             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8243             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8244             if ( p24.length != 1 ) {
8245                 return false;
8246             }
8247             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8248                 return false;
8249             }
8250             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8251             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8252             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8253             if ( p241.length != 2 ) {
8254                 return false;
8255             }
8256             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8257                 return false;
8258             }
8259             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8260                 return false;
8261             }
8262             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8263                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8264                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8265                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8266                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8267                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8268                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8269                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8270             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8271             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8272                 return false;
8273             }
8274             final String p26_S = "(A,B)ab";
8275             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8276             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8277                 return false;
8278             }
8279             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8280             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8281             if ( p27s.length != 1 ) {
8282                 System.out.println( "xxl=" + p27s.length );
8283                 System.exit( -1 );
8284                 return false;
8285             }
8286             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8287                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8288                 System.exit( -1 );
8289                 return false;
8290             }
8291             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8292                                                     new NHXParser() );
8293             if ( p27.length != 1 ) {
8294                 System.out.println( "yl=" + p27.length );
8295                 System.exit( -1 );
8296                 return false;
8297             }
8298             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8299                 System.out.println( p27[ 0 ].toNewHampshireX() );
8300                 System.exit( -1 );
8301                 return false;
8302             }
8303             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8304             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8305             final String p28_S3 = "(A,B)ab";
8306             final String p28_S4 = "((((A,B),C),D),;E;)";
8307             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8308                                                     new NHXParser() );
8309             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8310                 return false;
8311             }
8312             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8313                 return false;
8314             }
8315             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8316                 return false;
8317             }
8318             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8319                 return false;
8320             }
8321             if ( p28.length != 4 ) {
8322                 return false;
8323             }
8324             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";
8325             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8326             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8327                 return false;
8328             }
8329             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";
8330             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8331             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8332                 return false;
8333             }
8334             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8335             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8336             if ( ( p32.length != 0 ) ) {
8337                 return false;
8338             }
8339             final String p33_S = "A";
8340             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8341             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8342                 return false;
8343             }
8344             final String p34_S = "B;";
8345             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8346             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8347                 return false;
8348             }
8349             final String p35_S = "B:0.2";
8350             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8351             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8352                 return false;
8353             }
8354             final String p36_S = "(A)";
8355             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8356             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8357                 return false;
8358             }
8359             final String p37_S = "((A))";
8360             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8361             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8362                 return false;
8363             }
8364             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8365             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8366             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8367                 return false;
8368             }
8369             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8370             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8371             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8372                 return false;
8373             }
8374             final String p40_S = "(A,B,C)";
8375             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8376             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8377                 return false;
8378             }
8379             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8380             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8381             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8382                 return false;
8383             }
8384             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8385             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8386             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8387                 return false;
8388             }
8389             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)";
8390             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8391             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8392                 return false;
8393             }
8394             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)))";
8395             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8396             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8397                 return false;
8398             }
8399             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8400             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8401             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8402                 return false;
8403             }
8404             final String p46_S = "";
8405             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8406             if ( p46.length != 0 ) {
8407                 return false;
8408             }
8409             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8410             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8411                 return false;
8412             }
8413             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8414             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8415                 return false;
8416             }
8417             final Phylogeny p49 = factory
8418                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8419                              new NHXParser() )[ 0 ];
8420             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8421                 return false;
8422             }
8423             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8424             if ( p50.getNode( "A" ) == null ) {
8425                 return false;
8426             }
8427             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8428                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8429                 return false;
8430             }
8431             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8432                 return false;
8433             }
8434             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8435                     .equals( "((A,B)88:2.0,C);" ) ) {
8436                 return false;
8437             }
8438             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8439             if ( p51.getNode( "A(A" ) == null ) {
8440                 return false;
8441             }
8442             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8443             if ( p52.getNode( "A(A" ) == null ) {
8444                 return false;
8445             }
8446             final Phylogeny p53 = factory
8447                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8448                              new NHXParser() )[ 0 ];
8449             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8450                 return false;
8451             }
8452             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8453             if ( p54.getNode( "A" ) == null ) {
8454                 return false;
8455             }
8456             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8457                 return false;
8458             }
8459             final Phylogeny p55 = factory
8460                     .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);" ),
8461                              new NHXParser() )[ 0 ];
8462             if ( !p55
8463                     .toNewHampshire()
8464                     .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);" ) ) {
8465                 System.out.println( p55.toNewHampshire() );
8466                 return false;
8467             }
8468             final Phylogeny p56 = factory
8469                     .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);" ),
8470                              new NHXParser() )[ 0 ];
8471             if ( !p56
8472                     .toNewHampshire()
8473                     .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);" ) ) {
8474                 System.out.println( p56.toNewHampshire() );
8475                 return false;
8476             }
8477             final Phylogeny p57 = factory
8478                     .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);" ),
8479                              new NHXParser() )[ 0 ];
8480             if ( !p57
8481                     .toNewHampshire()
8482                     .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);" ) ) {
8483                 System.out.println( p56.toNewHampshire() );
8484                 return false;
8485             }
8486             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8487             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8488             if ( !p58.toNewHampshire().equals( s58 ) ) {
8489                 System.out.println( p58.toNewHampshire() );
8490                 return false;
8491             }
8492             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8493             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8494             if ( !p59.toNewHampshire().equals( s59 ) ) {
8495                 System.out.println( p59.toNewHampshire() );
8496                 return false;
8497             }
8498             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8499             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8500             if ( !p60.toNewHampshire().equals( s60 ) ) {
8501                 System.out.println( p60.toNewHampshire() );
8502                 return false;
8503             }
8504             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8505             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8506             if ( !p61.toNewHampshire()
8507                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8508                 System.out.println( p61.toNewHampshire() );
8509                 return false;
8510             }
8511         }
8512         catch ( final Exception e ) {
8513             e.printStackTrace( System.out );
8514             return false;
8515         }
8516         return true;
8517     }
8518
8519     private static boolean testNHParsingIter() {
8520         try {
8521             final String p0_str = "(A,B);";
8522             final NHXParser p = new NHXParser();
8523             p.setSource( p0_str );
8524             if ( !p.hasNext() ) {
8525                 return false;
8526             }
8527             final Phylogeny p0 = p.next();
8528             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8529                 System.out.println( p0.toNewHampshire() );
8530                 return false;
8531             }
8532             if ( p.hasNext() ) {
8533                 return false;
8534             }
8535             if ( p.next() != null ) {
8536                 return false;
8537             }
8538             //
8539             final String p00_str = "(A,B)root;";
8540             p.setSource( p00_str );
8541             final Phylogeny p00 = p.next();
8542             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8543                 System.out.println( p00.toNewHampshire() );
8544                 return false;
8545             }
8546             //
8547             final String p000_str = "A;";
8548             p.setSource( p000_str );
8549             final Phylogeny p000 = p.next();
8550             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8551                 System.out.println( p000.toNewHampshire() );
8552                 return false;
8553             }
8554             //
8555             final String p0000_str = "A";
8556             p.setSource( p0000_str );
8557             final Phylogeny p0000 = p.next();
8558             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8559                 System.out.println( p0000.toNewHampshire() );
8560                 return false;
8561             }
8562             //
8563             p.setSource( "(A)" );
8564             final Phylogeny p00000 = p.next();
8565             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8566                 System.out.println( p00000.toNewHampshire() );
8567                 return false;
8568             }
8569             //
8570             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8571             p.setSource( p1_str );
8572             if ( !p.hasNext() ) {
8573                 return false;
8574             }
8575             final Phylogeny p1_0 = p.next();
8576             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8577                 System.out.println( p1_0.toNewHampshire() );
8578                 return false;
8579             }
8580             if ( !p.hasNext() ) {
8581                 return false;
8582             }
8583             final Phylogeny p1_1 = p.next();
8584             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8585                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8586                 return false;
8587             }
8588             if ( !p.hasNext() ) {
8589                 return false;
8590             }
8591             final Phylogeny p1_2 = p.next();
8592             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8593                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8594                 return false;
8595             }
8596             if ( !p.hasNext() ) {
8597                 return false;
8598             }
8599             final Phylogeny p1_3 = p.next();
8600             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8601                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8602                 return false;
8603             }
8604             if ( p.hasNext() ) {
8605                 return false;
8606             }
8607             if ( p.next() != null ) {
8608                 return false;
8609             }
8610             //
8611             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8612             p.setSource( p2_str );
8613             if ( !p.hasNext() ) {
8614                 return false;
8615             }
8616             Phylogeny p2_0 = p.next();
8617             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8618                 System.out.println( p2_0.toNewHampshire() );
8619                 return false;
8620             }
8621             if ( !p.hasNext() ) {
8622                 return false;
8623             }
8624             Phylogeny p2_1 = p.next();
8625             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8626                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8627                 return false;
8628             }
8629             if ( !p.hasNext() ) {
8630                 return false;
8631             }
8632             Phylogeny p2_2 = p.next();
8633             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8634                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8635                 return false;
8636             }
8637             if ( !p.hasNext() ) {
8638                 return false;
8639             }
8640             Phylogeny p2_3 = p.next();
8641             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8642                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8643                 return false;
8644             }
8645             if ( !p.hasNext() ) {
8646                 return false;
8647             }
8648             Phylogeny p2_4 = p.next();
8649             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8650                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8651                 return false;
8652             }
8653             if ( p.hasNext() ) {
8654                 return false;
8655             }
8656             if ( p.next() != null ) {
8657                 return false;
8658             }
8659             ////
8660             p.reset();
8661             if ( !p.hasNext() ) {
8662                 return false;
8663             }
8664             p2_0 = p.next();
8665             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8666                 System.out.println( p2_0.toNewHampshire() );
8667                 return false;
8668             }
8669             if ( !p.hasNext() ) {
8670                 return false;
8671             }
8672             p2_1 = p.next();
8673             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8674                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8675                 return false;
8676             }
8677             if ( !p.hasNext() ) {
8678                 return false;
8679             }
8680             p2_2 = p.next();
8681             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8682                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8683                 return false;
8684             }
8685             if ( !p.hasNext() ) {
8686                 return false;
8687             }
8688             p2_3 = p.next();
8689             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8690                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8691                 return false;
8692             }
8693             if ( !p.hasNext() ) {
8694                 return false;
8695             }
8696             p2_4 = p.next();
8697             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8698                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8699                 return false;
8700             }
8701             if ( p.hasNext() ) {
8702                 return false;
8703             }
8704             if ( p.next() != null ) {
8705                 return false;
8706             }
8707             //
8708             final String p3_str = "((A,B),C)abc";
8709             p.setSource( p3_str );
8710             if ( !p.hasNext() ) {
8711                 return false;
8712             }
8713             final Phylogeny p3_0 = p.next();
8714             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8715                 return false;
8716             }
8717             if ( p.hasNext() ) {
8718                 return false;
8719             }
8720             if ( p.next() != null ) {
8721                 return false;
8722             }
8723             //
8724             final String p4_str = "((A,B)ab,C)abc";
8725             p.setSource( p4_str );
8726             if ( !p.hasNext() ) {
8727                 return false;
8728             }
8729             final Phylogeny p4_0 = p.next();
8730             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8731                 return false;
8732             }
8733             if ( p.hasNext() ) {
8734                 return false;
8735             }
8736             if ( p.next() != null ) {
8737                 return false;
8738             }
8739             //
8740             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8741             p.setSource( p5_str );
8742             if ( !p.hasNext() ) {
8743                 return false;
8744             }
8745             final Phylogeny p5_0 = p.next();
8746             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8747                 return false;
8748             }
8749             if ( p.hasNext() ) {
8750                 return false;
8751             }
8752             if ( p.next() != null ) {
8753                 return false;
8754             }
8755             //
8756             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8757             p.setSource( p6_str );
8758             if ( !p.hasNext() ) {
8759                 return false;
8760             }
8761             Phylogeny p6_0 = p.next();
8762             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8763                 return false;
8764             }
8765             if ( p.hasNext() ) {
8766                 return false;
8767             }
8768             if ( p.next() != null ) {
8769                 return false;
8770             }
8771             p.reset();
8772             if ( !p.hasNext() ) {
8773                 return false;
8774             }
8775             p6_0 = p.next();
8776             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8777                 return false;
8778             }
8779             if ( p.hasNext() ) {
8780                 return false;
8781             }
8782             if ( p.next() != null ) {
8783                 return false;
8784             }
8785             //
8786             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8787             p.setSource( p7_str );
8788             if ( !p.hasNext() ) {
8789                 return false;
8790             }
8791             Phylogeny p7_0 = p.next();
8792             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8793                 return false;
8794             }
8795             if ( p.hasNext() ) {
8796                 return false;
8797             }
8798             if ( p.next() != null ) {
8799                 return false;
8800             }
8801             p.reset();
8802             if ( !p.hasNext() ) {
8803                 return false;
8804             }
8805             p7_0 = p.next();
8806             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8807                 return false;
8808             }
8809             if ( p.hasNext() ) {
8810                 return false;
8811             }
8812             if ( p.next() != null ) {
8813                 return false;
8814             }
8815             //
8816             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8817             p.setSource( p8_str );
8818             if ( !p.hasNext() ) {
8819                 return false;
8820             }
8821             Phylogeny p8_0 = p.next();
8822             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8823                 return false;
8824             }
8825             if ( !p.hasNext() ) {
8826                 return false;
8827             }
8828             if ( !p.hasNext() ) {
8829                 return false;
8830             }
8831             Phylogeny p8_1 = p.next();
8832             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8833                 return false;
8834             }
8835             if ( p.hasNext() ) {
8836                 return false;
8837             }
8838             if ( p.next() != null ) {
8839                 return false;
8840             }
8841             p.reset();
8842             if ( !p.hasNext() ) {
8843                 return false;
8844             }
8845             p8_0 = p.next();
8846             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8847                 return false;
8848             }
8849             if ( !p.hasNext() ) {
8850                 return false;
8851             }
8852             p8_1 = p.next();
8853             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8854                 return false;
8855             }
8856             if ( p.hasNext() ) {
8857                 return false;
8858             }
8859             if ( p.next() != null ) {
8860                 return false;
8861             }
8862             p.reset();
8863             //
8864             p.setSource( "" );
8865             if ( p.hasNext() ) {
8866                 return false;
8867             }
8868             //
8869             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8870             if ( !p.hasNext() ) {
8871                 return false;
8872             }
8873             Phylogeny p_27 = p.next();
8874             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8875                 System.out.println( p_27.toNewHampshireX() );
8876                 System.exit( -1 );
8877                 return false;
8878             }
8879             if ( p.hasNext() ) {
8880                 return false;
8881             }
8882             if ( p.next() != null ) {
8883                 return false;
8884             }
8885             p.reset();
8886             if ( !p.hasNext() ) {
8887                 return false;
8888             }
8889             p_27 = p.next();
8890             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8891                 System.out.println( p_27.toNewHampshireX() );
8892                 System.exit( -1 );
8893                 return false;
8894             }
8895             if ( p.hasNext() ) {
8896                 return false;
8897             }
8898             if ( p.next() != null ) {
8899                 return false;
8900             }
8901             //
8902             final String p30_str = "(A,B);(C,D)";
8903             final NHXParser p30 = new NHXParser();
8904             p30.setSource( p30_str );
8905             if ( !p30.hasNext() ) {
8906                 return false;
8907             }
8908             Phylogeny phy30 = p30.next();
8909             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8910                 System.out.println( phy30.toNewHampshire() );
8911                 return false;
8912             }
8913             if ( !p30.hasNext() ) {
8914                 return false;
8915             }
8916             Phylogeny phy301 = p30.next();
8917             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8918                 System.out.println( phy301.toNewHampshire() );
8919                 return false;
8920             }
8921             if ( p30.hasNext() ) {
8922                 return false;
8923             }
8924             if ( p30.hasNext() ) {
8925                 return false;
8926             }
8927             if ( p30.next() != null ) {
8928                 return false;
8929             }
8930             if ( p30.next() != null ) {
8931                 return false;
8932             }
8933             p30.reset();
8934             if ( !p30.hasNext() ) {
8935                 return false;
8936             }
8937             phy30 = p30.next();
8938             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8939                 System.out.println( phy30.toNewHampshire() );
8940                 return false;
8941             }
8942             if ( !p30.hasNext() ) {
8943                 return false;
8944             }
8945             phy301 = p30.next();
8946             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8947                 System.out.println( phy301.toNewHampshire() );
8948                 return false;
8949             }
8950             if ( p30.hasNext() ) {
8951                 return false;
8952             }
8953             if ( p30.hasNext() ) {
8954                 return false;
8955             }
8956             if ( p30.next() != null ) {
8957                 return false;
8958             }
8959             if ( p30.next() != null ) {
8960                 return false;
8961             }
8962         }
8963         catch ( final Exception e ) {
8964             e.printStackTrace( System.out );
8965             return false;
8966         }
8967         return true;
8968     }
8969
8970     private static boolean testNHXconversion() {
8971         try {
8972             final PhylogenyNode n1 = new PhylogenyNode();
8973             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8974             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8975             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8976             final PhylogenyNode n5 = PhylogenyNode
8977                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8978             final PhylogenyNode n6 = PhylogenyNode
8979                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8980             if ( !n1.toNewHampshireX().equals( "" ) ) {
8981                 return false;
8982             }
8983             if ( !n2.toNewHampshireX().equals( "" ) ) {
8984                 return false;
8985             }
8986             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8987                 return false;
8988             }
8989             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8990                 return false;
8991             }
8992             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8993                 return false;
8994             }
8995             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8996                 System.out.println( n6.toNewHampshireX() );
8997                 return false;
8998             }
8999             final PhylogenyNode n7 = new PhylogenyNode();
9000             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9001             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9002                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9003                 System.out.println( n7
9004                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9005                 return false;
9006             }
9007         }
9008         catch ( final Exception e ) {
9009             e.printStackTrace( System.out );
9010             return false;
9011         }
9012         return true;
9013     }
9014
9015     private static boolean testNHXNodeParsing() {
9016         try {
9017             final PhylogenyNode n1 = new PhylogenyNode();
9018             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9019             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9020             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9021             final PhylogenyNode n5 = PhylogenyNode
9022                     .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]" );
9023             if ( !n3.getName().equals( "n3" ) ) {
9024                 return false;
9025             }
9026             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9027                 return false;
9028             }
9029             if ( n3.isDuplication() ) {
9030                 return false;
9031             }
9032             if ( n3.isHasAssignedEvent() ) {
9033                 return false;
9034             }
9035             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9036                 return false;
9037             }
9038             if ( !n4.getName().equals( "n4" ) ) {
9039                 return false;
9040             }
9041             if ( n4.getDistanceToParent() != 0.01 ) {
9042                 return false;
9043             }
9044             if ( !n5.getName().equals( "n5" ) ) {
9045                 return false;
9046             }
9047             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9048                 return false;
9049             }
9050             if ( n5.getDistanceToParent() != 0.1 ) {
9051                 return false;
9052             }
9053             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9054                 return false;
9055             }
9056             if ( !n5.isDuplication() ) {
9057                 return false;
9058             }
9059             if ( !n5.isHasAssignedEvent() ) {
9060                 return false;
9061             }
9062             final PhylogenyNode n8 = PhylogenyNode
9063                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9064                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9065             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9066                 return false;
9067             }
9068             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9069                 return false;
9070             }
9071             final PhylogenyNode n9 = PhylogenyNode
9072                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9073                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9074             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9075                 return false;
9076             }
9077             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9078                 return false;
9079             }
9080             final PhylogenyNode n10 = PhylogenyNode
9081                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9082             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9083                 return false;
9084             }
9085             final PhylogenyNode n20 = PhylogenyNode
9086                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9087             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9088                 return false;
9089             }
9090             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9091                 return false;
9092             }
9093             final PhylogenyNode n20x = PhylogenyNode
9094                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9095             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9096                 return false;
9097             }
9098             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9099                 return false;
9100             }
9101             final PhylogenyNode n20xx = PhylogenyNode
9102                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9103             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9104                 return false;
9105             }
9106             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9107                 return false;
9108             }
9109             final PhylogenyNode n20xxx = PhylogenyNode
9110                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9111             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9112                 return false;
9113             }
9114             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9115                 return false;
9116             }
9117             final PhylogenyNode n20xxxx = PhylogenyNode
9118                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9119             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9120                 return false;
9121             }
9122             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9123                 return false;
9124             }
9125             final PhylogenyNode n21 = PhylogenyNode
9126                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9127             if ( !n21.getName().equals( "N21_PIG" ) ) {
9128                 return false;
9129             }
9130             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9131                 return false;
9132             }
9133             final PhylogenyNode n21x = PhylogenyNode
9134                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9135             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9136                 return false;
9137             }
9138             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9139                 return false;
9140             }
9141             final PhylogenyNode n22 = PhylogenyNode
9142                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9143             if ( !n22.getName().equals( "n22/PIG" ) ) {
9144                 return false;
9145             }
9146             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9147                 return false;
9148             }
9149             final PhylogenyNode n23 = PhylogenyNode
9150                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9151             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9152                 return false;
9153             }
9154             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9155                 return false;
9156             }
9157             final PhylogenyNode a = PhylogenyNode
9158                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9159             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9160                 return false;
9161             }
9162             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9163                 return false;
9164             }
9165             final PhylogenyNode c1 = PhylogenyNode
9166                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9167                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9168             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9169                 return false;
9170             }
9171             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9172                 return false;
9173             }
9174             final PhylogenyNode c2 = PhylogenyNode
9175                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9176                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9177             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9178                 return false;
9179             }
9180             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9181                 return false;
9182             }
9183             final PhylogenyNode e3 = PhylogenyNode
9184                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9185             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9186                 return false;
9187             }
9188             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9189                 return false;
9190             }
9191             final PhylogenyNode n11 = PhylogenyNode
9192                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9193                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9194             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9195                 return false;
9196             }
9197             if ( n11.getDistanceToParent() != 0.4 ) {
9198                 return false;
9199             }
9200             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9201                 return false;
9202             }
9203             final PhylogenyNode n12 = PhylogenyNode
9204                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9205                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9206             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9207                 return false;
9208             }
9209             if ( n12.getDistanceToParent() != 0.4 ) {
9210                 return false;
9211             }
9212             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9213                 return false;
9214             }
9215             final PhylogenyNode o = PhylogenyNode
9216                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9217             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9218                 return false;
9219             }
9220             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9221                 return false;
9222             }
9223             if ( n1.getName().compareTo( "" ) != 0 ) {
9224                 return false;
9225             }
9226             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9227                 return false;
9228             }
9229             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9230                 return false;
9231             }
9232             if ( n2.getName().compareTo( "" ) != 0 ) {
9233                 return false;
9234             }
9235             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9236                 return false;
9237             }
9238             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9239                 return false;
9240             }
9241             final PhylogenyNode n00 = PhylogenyNode
9242                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9243             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9244                 return false;
9245             }
9246             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9247                 return false;
9248             }
9249             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9250             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9251                 return false;
9252             }
9253             final PhylogenyNode n13 = PhylogenyNode
9254                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9255             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9256                 return false;
9257             }
9258             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9259                 return false;
9260             }
9261             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9262                 return false;
9263             }
9264             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9265                 return false;
9266             }
9267             final PhylogenyNode n14 = PhylogenyNode
9268                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9269             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9270                 return false;
9271             }
9272             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9273                 return false;
9274             }
9275             final PhylogenyNode n15 = PhylogenyNode
9276                     .createInstanceFromNhxString( "something_wicked[123]",
9277                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9278             if ( !n15.getName().equals( "something_wicked" ) ) {
9279                 return false;
9280             }
9281             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9282                 return false;
9283             }
9284             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9285                 return false;
9286             }
9287             final PhylogenyNode n16 = PhylogenyNode
9288                     .createInstanceFromNhxString( "something_wicked2[9]",
9289                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9290             if ( !n16.getName().equals( "something_wicked2" ) ) {
9291                 return false;
9292             }
9293             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9294                 return false;
9295             }
9296             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9297                 return false;
9298             }
9299             final PhylogenyNode n17 = PhylogenyNode
9300                     .createInstanceFromNhxString( "something_wicked3[a]",
9301                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9302             if ( !n17.getName().equals( "something_wicked3" ) ) {
9303                 return false;
9304             }
9305             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9306                 return false;
9307             }
9308             final PhylogenyNode n18 = PhylogenyNode
9309                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9310             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9311                 return false;
9312             }
9313             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9314                 return false;
9315             }
9316             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9317                 return false;
9318             }
9319             final PhylogenyNode n19 = PhylogenyNode
9320                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9321             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9322                 return false;
9323             }
9324             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9325                 return false;
9326             }
9327             final PhylogenyNode n30 = PhylogenyNode
9328                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9329                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9330             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9331                 return false;
9332             }
9333             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9334                 return false;
9335             }
9336             final PhylogenyNode n31 = PhylogenyNode
9337                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9338                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9339             if ( n31.getNodeData().isHasTaxonomy() ) {
9340                 return false;
9341             }
9342             final PhylogenyNode n32 = PhylogenyNode
9343                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9344             if ( n32.getNodeData().isHasTaxonomy() ) {
9345                 return false;
9346             }
9347             final PhylogenyNode n40 = PhylogenyNode
9348                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9349             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9350                 return false;
9351             }
9352             final PhylogenyNode n41 = PhylogenyNode
9353                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9354             if ( n41.getNodeData().isHasTaxonomy() ) {
9355                 return false;
9356             }
9357             final PhylogenyNode n42 = PhylogenyNode
9358                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9359             if ( n42.getNodeData().isHasTaxonomy() ) {
9360                 return false;
9361             }
9362             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9363                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9364             if ( n43.getNodeData().isHasTaxonomy() ) {
9365                 return false;
9366             }
9367             final PhylogenyNode n44 = PhylogenyNode
9368                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9369             if ( n44.getNodeData().isHasTaxonomy() ) {
9370                 return false;
9371             }
9372         }
9373         catch ( final Exception e ) {
9374             e.printStackTrace( System.out );
9375             return false;
9376         }
9377         return true;
9378     }
9379
9380     private static boolean testNHXParsing() {
9381         try {
9382             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9383             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9384             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9385                 return false;
9386             }
9387             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]";
9388             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9389             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9390                 return false;
9391             }
9392             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]";
9393             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9394             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9395                 return false;
9396             }
9397             final Phylogeny[] p3 = factory
9398                     .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]",
9399                              new NHXParser() );
9400             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9401                 return false;
9402             }
9403             final Phylogeny[] p4 = factory
9404                     .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(]",
9405                              new NHXParser() );
9406             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9407                 return false;
9408             }
9409             final Phylogeny[] p5 = factory
9410                     .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(((]",
9411                              new NHXParser() );
9412             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9413                 return false;
9414             }
9415             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)";
9416             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)";
9417             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9418             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9419                 return false;
9420             }
9421             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)))";
9422             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)))";
9423             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9424             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9425                 return false;
9426             }
9427             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])   ))[,,, ])))))))";
9428             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9429             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9430             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9431                 return false;
9432             }
9433             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9434             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9435                 return false;
9436             }
9437             final Phylogeny p10 = factory
9438                     .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]",
9439                              new NHXParser() )[ 0 ];
9440             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9441                 return false;
9442             }
9443             final Phylogeny p11 = factory
9444                     .create( " [79]   ( ('A: \" ' [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
9445                              new NHXParser() )[ 0 ];
9446             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9447                 return false;
9448             }
9449         }
9450         catch ( final Exception e ) {
9451             e.printStackTrace( System.out );
9452             return false;
9453         }
9454         return true;
9455     }
9456
9457     private static boolean testNHXParsingMB() {
9458         try {
9459             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9460             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9461                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9462                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9463                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9464                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9465                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9466                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9467                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9468                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9469             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9470                 return false;
9471             }
9472             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9473                 return false;
9474             }
9475             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9476                            0.1100000000000000e+00 ) ) {
9477                 return false;
9478             }
9479             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9480                 return false;
9481             }
9482             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9483                 return false;
9484             }
9485             final Phylogeny p2 = factory
9486                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9487                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9488                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9489                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9490                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9491                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9492                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9493                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9494                                      + "7.369400000000000e-02}])",
9495                              new NHXParser() )[ 0 ];
9496             if ( p2.getNode( "1" ) == null ) {
9497                 return false;
9498             }
9499             if ( p2.getNode( "2" ) == null ) {
9500                 return false;
9501             }
9502         }
9503         catch ( final Exception e ) {
9504             e.printStackTrace( System.out );
9505             System.exit( -1 );
9506             return false;
9507         }
9508         return true;
9509     }
9510
9511     private static boolean testNHXParsingQuotes() {
9512         try {
9513             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9514             final NHXParser p = new NHXParser();
9515             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9516             if ( phylogenies_0.length != 5 ) {
9517                 return false;
9518             }
9519             final Phylogeny phy = phylogenies_0[ 4 ];
9520             if ( phy.getNumberOfExternalNodes() != 7 ) {
9521                 return false;
9522             }
9523             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9524                 return false;
9525             }
9526             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9527                 return false;
9528             }
9529             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9530                     .getScientificName().equals( "hsapiens" ) ) {
9531                 return false;
9532             }
9533             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9534                 return false;
9535             }
9536             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9537                 return false;
9538             }
9539             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9540                 return false;
9541             }
9542             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9543                 return false;
9544             }
9545             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9546                 return false;
9547             }
9548             final NHXParser p1p = new NHXParser();
9549             p1p.setIgnoreQuotes( true );
9550             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9551             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9552                 return false;
9553             }
9554             final NHXParser p2p = new NHXParser();
9555             p1p.setIgnoreQuotes( false );
9556             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9557             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9558                 return false;
9559             }
9560             final NHXParser p3p = new NHXParser();
9561             p3p.setIgnoreQuotes( false );
9562             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9563             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9564                 return false;
9565             }
9566             final NHXParser p4p = new NHXParser();
9567             p4p.setIgnoreQuotes( false );
9568             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9569             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9570                 return false;
9571             }
9572             final Phylogeny p10 = factory
9573                     .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]",
9574                              new NHXParser() )[ 0 ];
9575             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]";
9576             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9577                 return false;
9578             }
9579             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9580             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9581                 return false;
9582             }
9583             final Phylogeny p12 = factory
9584                     .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]",
9585                              new NHXParser() )[ 0 ];
9586             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]";
9587             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9588                 return false;
9589             }
9590             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9591             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9592                 return false;
9593             }
9594             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;";
9595             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9596                 return false;
9597             }
9598             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9599             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9600                 return false;
9601             }
9602         }
9603         catch ( final Exception e ) {
9604             e.printStackTrace( System.out );
9605             return false;
9606         }
9607         return true;
9608     }
9609
9610     private static boolean testNodeRemoval() {
9611         try {
9612             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9613             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9614             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9615             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9616                 return false;
9617             }
9618             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9619             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9620             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9621                 return false;
9622             }
9623             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9624             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9625             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9626                 return false;
9627             }
9628         }
9629         catch ( final Exception e ) {
9630             e.printStackTrace( System.out );
9631             return false;
9632         }
9633         return true;
9634     }
9635
9636     private static boolean testPhylogenyBranch() {
9637         try {
9638             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9639             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9640             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9641             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9642             if ( !a1b1.equals( a1b1 ) ) {
9643                 return false;
9644             }
9645             if ( !a1b1.equals( b1a1 ) ) {
9646                 return false;
9647             }
9648             if ( !b1a1.equals( a1b1 ) ) {
9649                 return false;
9650             }
9651             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9652             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9653             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9654             if ( a1_b1.equals( b1_a1 ) ) {
9655                 return false;
9656             }
9657             if ( a1_b1.equals( a1_b1_ ) ) {
9658                 return false;
9659             }
9660             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9661             if ( !a1_b1.equals( b1_a1_ ) ) {
9662                 return false;
9663             }
9664             if ( a1_b1_.equals( b1_a1_ ) ) {
9665                 return false;
9666             }
9667             if ( !a1_b1_.equals( b1_a1 ) ) {
9668                 return false;
9669             }
9670         }
9671         catch ( final Exception e ) {
9672             e.printStackTrace( System.out );
9673             return false;
9674         }
9675         return true;
9676     }
9677
9678     private static boolean testPhyloXMLparsingOfDistributionElement() {
9679         try {
9680             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9681             PhyloXmlParser xml_parser = null;
9682             try {
9683                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9684             }
9685             catch ( final Exception e ) {
9686                 // Do nothing -- means were not running from jar.
9687             }
9688             if ( xml_parser == null ) {
9689                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9690                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9691                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9692                 }
9693                 else {
9694                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9695                 }
9696             }
9697             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9698                                                               xml_parser );
9699             if ( xml_parser.getErrorCount() > 0 ) {
9700                 System.out.println( xml_parser.getErrorMessages().toString() );
9701                 return false;
9702             }
9703             if ( phylogenies_0.length != 1 ) {
9704                 return false;
9705             }
9706             final Phylogeny t1 = phylogenies_0[ 0 ];
9707             PhylogenyNode n = null;
9708             Distribution d = null;
9709             n = t1.getNode( "root node" );
9710             if ( !n.getNodeData().isHasDistribution() ) {
9711                 return false;
9712             }
9713             if ( n.getNodeData().getDistributions().size() != 1 ) {
9714                 return false;
9715             }
9716             d = n.getNodeData().getDistribution();
9717             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9718                 return false;
9719             }
9720             if ( d.getPoints().size() != 1 ) {
9721                 return false;
9722             }
9723             if ( d.getPolygons() != null ) {
9724                 return false;
9725             }
9726             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9727                 return false;
9728             }
9729             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9730                 return false;
9731             }
9732             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9733                 return false;
9734             }
9735             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9736                 return false;
9737             }
9738             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9739                 return false;
9740             }
9741             n = t1.getNode( "node a" );
9742             if ( !n.getNodeData().isHasDistribution() ) {
9743                 return false;
9744             }
9745             if ( n.getNodeData().getDistributions().size() != 2 ) {
9746                 return false;
9747             }
9748             d = n.getNodeData().getDistribution( 1 );
9749             if ( !d.getDesc().equals( "San Diego" ) ) {
9750                 return false;
9751             }
9752             if ( d.getPoints().size() != 1 ) {
9753                 return false;
9754             }
9755             if ( d.getPolygons() != null ) {
9756                 return false;
9757             }
9758             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9759                 return false;
9760             }
9761             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9762                 return false;
9763             }
9764             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9765                 return false;
9766             }
9767             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9768                 return false;
9769             }
9770             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9771                 return false;
9772             }
9773             n = t1.getNode( "node bb" );
9774             if ( !n.getNodeData().isHasDistribution() ) {
9775                 return false;
9776             }
9777             if ( n.getNodeData().getDistributions().size() != 1 ) {
9778                 return false;
9779             }
9780             d = n.getNodeData().getDistribution( 0 );
9781             if ( d.getPoints().size() != 3 ) {
9782                 return false;
9783             }
9784             if ( d.getPolygons().size() != 2 ) {
9785                 return false;
9786             }
9787             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9788                 return false;
9789             }
9790             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9797                 return false;
9798             }
9799             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9800                 return false;
9801             }
9802             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9803                 return false;
9804             }
9805             Polygon p = d.getPolygons().get( 0 );
9806             if ( p.getPoints().size() != 3 ) {
9807                 return false;
9808             }
9809             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9810                 return false;
9811             }
9812             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9813                 return false;
9814             }
9815             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9816                 return false;
9817             }
9818             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9819                 return false;
9820             }
9821             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9822                 return false;
9823             }
9824             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9825                 return false;
9826             }
9827             p = d.getPolygons().get( 1 );
9828             if ( p.getPoints().size() != 3 ) {
9829                 return false;
9830             }
9831             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9832                 return false;
9833             }
9834             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9835                 return false;
9836             }
9837             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9838                 return false;
9839             }
9840             // Roundtrip:
9841             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9842             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9843             if ( rt.length != 1 ) {
9844                 return false;
9845             }
9846             final Phylogeny t1_rt = rt[ 0 ];
9847             n = t1_rt.getNode( "root node" );
9848             if ( !n.getNodeData().isHasDistribution() ) {
9849                 return false;
9850             }
9851             if ( n.getNodeData().getDistributions().size() != 1 ) {
9852                 return false;
9853             }
9854             d = n.getNodeData().getDistribution();
9855             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9856                 return false;
9857             }
9858             if ( d.getPoints().size() != 1 ) {
9859                 return false;
9860             }
9861             if ( d.getPolygons() != null ) {
9862                 return false;
9863             }
9864             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9865                 return false;
9866             }
9867             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9868                 return false;
9869             }
9870             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9871                 return false;
9872             }
9873             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9874                 return false;
9875             }
9876             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9877                 return false;
9878             }
9879             n = t1_rt.getNode( "node a" );
9880             if ( !n.getNodeData().isHasDistribution() ) {
9881                 return false;
9882             }
9883             if ( n.getNodeData().getDistributions().size() != 2 ) {
9884                 return false;
9885             }
9886             d = n.getNodeData().getDistribution( 1 );
9887             if ( !d.getDesc().equals( "San Diego" ) ) {
9888                 return false;
9889             }
9890             if ( d.getPoints().size() != 1 ) {
9891                 return false;
9892             }
9893             if ( d.getPolygons() != null ) {
9894                 return false;
9895             }
9896             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9897                 return false;
9898             }
9899             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9900                 return false;
9901             }
9902             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9903                 return false;
9904             }
9905             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9906                 return false;
9907             }
9908             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9909                 return false;
9910             }
9911             n = t1_rt.getNode( "node bb" );
9912             if ( !n.getNodeData().isHasDistribution() ) {
9913                 return false;
9914             }
9915             if ( n.getNodeData().getDistributions().size() != 1 ) {
9916                 return false;
9917             }
9918             d = n.getNodeData().getDistribution( 0 );
9919             if ( d.getPoints().size() != 3 ) {
9920                 return false;
9921             }
9922             if ( d.getPolygons().size() != 2 ) {
9923                 return false;
9924             }
9925             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9926                 return false;
9927             }
9928             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9929                 return false;
9930             }
9931             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9935                 return false;
9936             }
9937             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9938                 return false;
9939             }
9940             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9941                 return false;
9942             }
9943             p = d.getPolygons().get( 0 );
9944             if ( p.getPoints().size() != 3 ) {
9945                 return false;
9946             }
9947             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9948                 return false;
9949             }
9950             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9951                 return false;
9952             }
9953             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9954                 return false;
9955             }
9956             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9957                 return false;
9958             }
9959             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9960                 return false;
9961             }
9962             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9963                 return false;
9964             }
9965             p = d.getPolygons().get( 1 );
9966             if ( p.getPoints().size() != 3 ) {
9967                 return false;
9968             }
9969             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9970                 return false;
9971             }
9972             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9973                 return false;
9974             }
9975             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9976                 return false;
9977             }
9978         }
9979         catch ( final Exception e ) {
9980             e.printStackTrace( System.out );
9981             return false;
9982         }
9983         return true;
9984     }
9985
9986     private static boolean testPostOrderIterator() {
9987         try {
9988             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9989             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9990             PhylogenyNodeIterator it0;
9991             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9992                 it0.next();
9993             }
9994             for( it0.reset(); it0.hasNext(); ) {
9995                 it0.next();
9996             }
9997             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9998             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9999             if ( !it.next().getName().equals( "A" ) ) {
10000                 return false;
10001             }
10002             if ( !it.next().getName().equals( "B" ) ) {
10003                 return false;
10004             }
10005             if ( !it.next().getName().equals( "ab" ) ) {
10006                 return false;
10007             }
10008             if ( !it.next().getName().equals( "C" ) ) {
10009                 return false;
10010             }
10011             if ( !it.next().getName().equals( "D" ) ) {
10012                 return false;
10013             }
10014             if ( !it.next().getName().equals( "cd" ) ) {
10015                 return false;
10016             }
10017             if ( !it.next().getName().equals( "abcd" ) ) {
10018                 return false;
10019             }
10020             if ( !it.next().getName().equals( "E" ) ) {
10021                 return false;
10022             }
10023             if ( !it.next().getName().equals( "F" ) ) {
10024                 return false;
10025             }
10026             if ( !it.next().getName().equals( "ef" ) ) {
10027                 return false;
10028             }
10029             if ( !it.next().getName().equals( "G" ) ) {
10030                 return false;
10031             }
10032             if ( !it.next().getName().equals( "H" ) ) {
10033                 return false;
10034             }
10035             if ( !it.next().getName().equals( "gh" ) ) {
10036                 return false;
10037             }
10038             if ( !it.next().getName().equals( "efgh" ) ) {
10039                 return false;
10040             }
10041             if ( !it.next().getName().equals( "r" ) ) {
10042                 return false;
10043             }
10044             if ( it.hasNext() ) {
10045                 return false;
10046             }
10047         }
10048         catch ( final Exception e ) {
10049             e.printStackTrace( System.out );
10050             return false;
10051         }
10052         return true;
10053     }
10054
10055     private static boolean testPreOrderIterator() {
10056         try {
10057             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10058             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10059             PhylogenyNodeIterator it0;
10060             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10061                 it0.next();
10062             }
10063             for( it0.reset(); it0.hasNext(); ) {
10064                 it0.next();
10065             }
10066             PhylogenyNodeIterator it = t0.iteratorPreorder();
10067             if ( !it.next().getName().equals( "r" ) ) {
10068                 return false;
10069             }
10070             if ( !it.next().getName().equals( "ab" ) ) {
10071                 return false;
10072             }
10073             if ( !it.next().getName().equals( "A" ) ) {
10074                 return false;
10075             }
10076             if ( !it.next().getName().equals( "B" ) ) {
10077                 return false;
10078             }
10079             if ( !it.next().getName().equals( "cd" ) ) {
10080                 return false;
10081             }
10082             if ( !it.next().getName().equals( "C" ) ) {
10083                 return false;
10084             }
10085             if ( !it.next().getName().equals( "D" ) ) {
10086                 return false;
10087             }
10088             if ( it.hasNext() ) {
10089                 return false;
10090             }
10091             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10092             it = t1.iteratorPreorder();
10093             if ( !it.next().getName().equals( "r" ) ) {
10094                 return false;
10095             }
10096             if ( !it.next().getName().equals( "abcd" ) ) {
10097                 return false;
10098             }
10099             if ( !it.next().getName().equals( "ab" ) ) {
10100                 return false;
10101             }
10102             if ( !it.next().getName().equals( "A" ) ) {
10103                 return false;
10104             }
10105             if ( !it.next().getName().equals( "B" ) ) {
10106                 return false;
10107             }
10108             if ( !it.next().getName().equals( "cd" ) ) {
10109                 return false;
10110             }
10111             if ( !it.next().getName().equals( "C" ) ) {
10112                 return false;
10113             }
10114             if ( !it.next().getName().equals( "D" ) ) {
10115                 return false;
10116             }
10117             if ( !it.next().getName().equals( "efgh" ) ) {
10118                 return false;
10119             }
10120             if ( !it.next().getName().equals( "ef" ) ) {
10121                 return false;
10122             }
10123             if ( !it.next().getName().equals( "E" ) ) {
10124                 return false;
10125             }
10126             if ( !it.next().getName().equals( "F" ) ) {
10127                 return false;
10128             }
10129             if ( !it.next().getName().equals( "gh" ) ) {
10130                 return false;
10131             }
10132             if ( !it.next().getName().equals( "G" ) ) {
10133                 return false;
10134             }
10135             if ( !it.next().getName().equals( "H" ) ) {
10136                 return false;
10137             }
10138             if ( it.hasNext() ) {
10139                 return false;
10140             }
10141         }
10142         catch ( final Exception e ) {
10143             e.printStackTrace( System.out );
10144             return false;
10145         }
10146         return true;
10147     }
10148
10149     private static boolean testPropertiesMap() {
10150         try {
10151             final PropertiesMap pm = new PropertiesMap();
10152             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10153             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10154             final Property p2 = new Property( "something:else",
10155                                               "?",
10156                                               "improbable:research",
10157                                               "xsd:decimal",
10158                                               AppliesTo.NODE );
10159             pm.addProperty( p0 );
10160             pm.addProperty( p1 );
10161             pm.addProperty( p2 );
10162             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10163                 return false;
10164             }
10165             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10166                 return false;
10167             }
10168             if ( pm.getProperties().size() != 3 ) {
10169                 return false;
10170             }
10171             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10172                 return false;
10173             }
10174             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10175                 return false;
10176             }
10177             if ( pm.getProperties().size() != 3 ) {
10178                 return false;
10179             }
10180             pm.removeProperty( "dimensions:diameter" );
10181             if ( pm.getProperties().size() != 2 ) {
10182                 return false;
10183             }
10184             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10185                 return false;
10186             }
10187             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10188                 return false;
10189             }
10190         }
10191         catch ( final Exception e ) {
10192             e.printStackTrace( System.out );
10193             return false;
10194         }
10195         return true;
10196     }
10197
10198     private static boolean testProteinId() {
10199         try {
10200             final ProteinId id1 = new ProteinId( "a" );
10201             final ProteinId id2 = new ProteinId( "a" );
10202             final ProteinId id3 = new ProteinId( "A" );
10203             final ProteinId id4 = new ProteinId( "b" );
10204             if ( !id1.equals( id1 ) ) {
10205                 return false;
10206             }
10207             if ( id1.getId().equals( "x" ) ) {
10208                 return false;
10209             }
10210             if ( id1.getId().equals( null ) ) {
10211                 return false;
10212             }
10213             if ( !id1.equals( id2 ) ) {
10214                 return false;
10215             }
10216             if ( id1.equals( id3 ) ) {
10217                 return false;
10218             }
10219             if ( id1.hashCode() != id1.hashCode() ) {
10220                 return false;
10221             }
10222             if ( id1.hashCode() != id2.hashCode() ) {
10223                 return false;
10224             }
10225             if ( id1.hashCode() == id3.hashCode() ) {
10226                 return false;
10227             }
10228             if ( id1.compareTo( id1 ) != 0 ) {
10229                 return false;
10230             }
10231             if ( id1.compareTo( id2 ) != 0 ) {
10232                 return false;
10233             }
10234             if ( id1.compareTo( id3 ) != 0 ) {
10235                 return false;
10236             }
10237             if ( id1.compareTo( id4 ) >= 0 ) {
10238                 return false;
10239             }
10240             if ( id4.compareTo( id1 ) <= 0 ) {
10241                 return false;
10242             }
10243             if ( !id4.getId().equals( "b" ) ) {
10244                 return false;
10245             }
10246             final ProteinId id5 = new ProteinId( " C " );
10247             if ( !id5.getId().equals( "C" ) ) {
10248                 return false;
10249             }
10250             if ( id5.equals( id1 ) ) {
10251                 return false;
10252             }
10253         }
10254         catch ( final Exception e ) {
10255             e.printStackTrace( System.out );
10256             return false;
10257         }
10258         return true;
10259     }
10260
10261     private static boolean testReIdMethods() {
10262         try {
10263             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10264             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10265             final long count = PhylogenyNode.getNodeCount();
10266             p.levelOrderReID();
10267             if ( p.getNode( "r" ).getId() != count ) {
10268                 return false;
10269             }
10270             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10271                 return false;
10272             }
10273             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10274                 return false;
10275             }
10276             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10277                 return false;
10278             }
10279             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10280                 return false;
10281             }
10282             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10283                 return false;
10284             }
10285             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10286                 return false;
10287             }
10288             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10289                 return false;
10290             }
10291             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10292                 return false;
10293             }
10294             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10295                 return false;
10296             }
10297             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10298                 return false;
10299             }
10300             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10301                 return false;
10302             }
10303             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10304                 return false;
10305             }
10306             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10307                 return false;
10308             }
10309             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10310                 return false;
10311             }
10312         }
10313         catch ( final Exception e ) {
10314             e.printStackTrace( System.out );
10315             return false;
10316         }
10317         return true;
10318     }
10319
10320     private static boolean testRerooting() {
10321         try {
10322             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10323             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",
10324                                                  new NHXParser() )[ 0 ];
10325             if ( !t1.isRooted() ) {
10326                 return false;
10327             }
10328             t1.reRoot( t1.getNode( "D" ) );
10329             t1.reRoot( t1.getNode( "CD" ) );
10330             t1.reRoot( t1.getNode( "A" ) );
10331             t1.reRoot( t1.getNode( "B" ) );
10332             t1.reRoot( t1.getNode( "AB" ) );
10333             t1.reRoot( t1.getNode( "D" ) );
10334             t1.reRoot( t1.getNode( "C" ) );
10335             t1.reRoot( t1.getNode( "CD" ) );
10336             t1.reRoot( t1.getNode( "A" ) );
10337             t1.reRoot( t1.getNode( "B" ) );
10338             t1.reRoot( t1.getNode( "AB" ) );
10339             t1.reRoot( t1.getNode( "D" ) );
10340             t1.reRoot( t1.getNode( "D" ) );
10341             t1.reRoot( t1.getNode( "C" ) );
10342             t1.reRoot( t1.getNode( "A" ) );
10343             t1.reRoot( t1.getNode( "B" ) );
10344             t1.reRoot( t1.getNode( "AB" ) );
10345             t1.reRoot( t1.getNode( "C" ) );
10346             t1.reRoot( t1.getNode( "D" ) );
10347             t1.reRoot( t1.getNode( "CD" ) );
10348             t1.reRoot( t1.getNode( "D" ) );
10349             t1.reRoot( t1.getNode( "A" ) );
10350             t1.reRoot( t1.getNode( "B" ) );
10351             t1.reRoot( t1.getNode( "AB" ) );
10352             t1.reRoot( t1.getNode( "C" ) );
10353             t1.reRoot( t1.getNode( "D" ) );
10354             t1.reRoot( t1.getNode( "CD" ) );
10355             t1.reRoot( t1.getNode( "D" ) );
10356             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10357                 return false;
10358             }
10359             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10360                 return false;
10361             }
10362             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10363                 return false;
10364             }
10365             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10366                 return false;
10367             }
10368             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10369                 return false;
10370             }
10371             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10372                 return false;
10373             }
10374             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",
10375                                                  new NHXParser() )[ 0 ];
10376             t2.reRoot( t2.getNode( "A" ) );
10377             t2.reRoot( t2.getNode( "D" ) );
10378             t2.reRoot( t2.getNode( "ABC" ) );
10379             t2.reRoot( t2.getNode( "A" ) );
10380             t2.reRoot( t2.getNode( "B" ) );
10381             t2.reRoot( t2.getNode( "D" ) );
10382             t2.reRoot( t2.getNode( "C" ) );
10383             t2.reRoot( t2.getNode( "ABC" ) );
10384             t2.reRoot( t2.getNode( "A" ) );
10385             t2.reRoot( t2.getNode( "B" ) );
10386             t2.reRoot( t2.getNode( "AB" ) );
10387             t2.reRoot( t2.getNode( "AB" ) );
10388             t2.reRoot( t2.getNode( "D" ) );
10389             t2.reRoot( t2.getNode( "C" ) );
10390             t2.reRoot( t2.getNode( "B" ) );
10391             t2.reRoot( t2.getNode( "AB" ) );
10392             t2.reRoot( t2.getNode( "D" ) );
10393             t2.reRoot( t2.getNode( "D" ) );
10394             t2.reRoot( t2.getNode( "ABC" ) );
10395             t2.reRoot( t2.getNode( "A" ) );
10396             t2.reRoot( t2.getNode( "B" ) );
10397             t2.reRoot( t2.getNode( "AB" ) );
10398             t2.reRoot( t2.getNode( "D" ) );
10399             t2.reRoot( t2.getNode( "C" ) );
10400             t2.reRoot( t2.getNode( "ABC" ) );
10401             t2.reRoot( t2.getNode( "A" ) );
10402             t2.reRoot( t2.getNode( "B" ) );
10403             t2.reRoot( t2.getNode( "AB" ) );
10404             t2.reRoot( t2.getNode( "D" ) );
10405             t2.reRoot( t2.getNode( "D" ) );
10406             t2.reRoot( t2.getNode( "C" ) );
10407             t2.reRoot( t2.getNode( "A" ) );
10408             t2.reRoot( t2.getNode( "B" ) );
10409             t2.reRoot( t2.getNode( "AB" ) );
10410             t2.reRoot( t2.getNode( "C" ) );
10411             t2.reRoot( t2.getNode( "D" ) );
10412             t2.reRoot( t2.getNode( "ABC" ) );
10413             t2.reRoot( t2.getNode( "D" ) );
10414             t2.reRoot( t2.getNode( "A" ) );
10415             t2.reRoot( t2.getNode( "B" ) );
10416             t2.reRoot( t2.getNode( "AB" ) );
10417             t2.reRoot( t2.getNode( "C" ) );
10418             t2.reRoot( t2.getNode( "D" ) );
10419             t2.reRoot( t2.getNode( "ABC" ) );
10420             t2.reRoot( t2.getNode( "D" ) );
10421             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10422                 return false;
10423             }
10424             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10425                 return false;
10426             }
10427             t2.reRoot( t2.getNode( "ABC" ) );
10428             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10429                 return false;
10430             }
10431             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10432                 return false;
10433             }
10434             t2.reRoot( t2.getNode( "AB" ) );
10435             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10436                 return false;
10437             }
10438             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10439                 return false;
10440             }
10441             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10442                 return false;
10443             }
10444             t2.reRoot( t2.getNode( "AB" ) );
10445             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10446                 return false;
10447             }
10448             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10449                 return false;
10450             }
10451             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10452                 return false;
10453             }
10454             t2.reRoot( t2.getNode( "D" ) );
10455             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10456                 return false;
10457             }
10458             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10459                 return false;
10460             }
10461             t2.reRoot( t2.getNode( "ABC" ) );
10462             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10463                 return false;
10464             }
10465             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10466                 return false;
10467             }
10468             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10469                                                  new NHXParser() )[ 0 ];
10470             t3.reRoot( t3.getNode( "B" ) );
10471             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10472                 return false;
10473             }
10474             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10475                 return false;
10476             }
10477             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10478                 return false;
10479             }
10480             t3.reRoot( t3.getNode( "B" ) );
10481             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10482                 return false;
10483             }
10484             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10485                 return false;
10486             }
10487             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10488                 return false;
10489             }
10490             t3.reRoot( t3.getRoot() );
10491             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10492                 return false;
10493             }
10494             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10495                 return false;
10496             }
10497             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10498                 return false;
10499             }
10500         }
10501         catch ( final Exception e ) {
10502             e.printStackTrace( System.out );
10503             return false;
10504         }
10505         return true;
10506     }
10507
10508     private static boolean testSDIse() {
10509         try {
10510             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10511             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10512             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10513             gene1.setRooted( true );
10514             species1.setRooted( true );
10515             final SDI sdi = new SDI( gene1, species1 );
10516             if ( !gene1.getRoot().isDuplication() ) {
10517                 return false;
10518             }
10519             final Phylogeny species2 = factory
10520                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10521                              new NHXParser() )[ 0 ];
10522             final Phylogeny gene2 = factory
10523                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10524                              new NHXParser() )[ 0 ];
10525             species2.setRooted( true );
10526             gene2.setRooted( true );
10527             final SDI sdi2 = new SDI( gene2, species2 );
10528             if ( sdi2.getDuplicationsSum() != 0 ) {
10529                 return false;
10530             }
10531             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10532                 return false;
10533             }
10534             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10535                 return false;
10536             }
10537             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10538                 return false;
10539             }
10540             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10541                 return false;
10542             }
10543             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10544                 return false;
10545             }
10546             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10547                 return false;
10548             }
10549             final Phylogeny species3 = factory
10550                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10551                              new NHXParser() )[ 0 ];
10552             final Phylogeny gene3 = factory
10553                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10554                              new NHXParser() )[ 0 ];
10555             species3.setRooted( true );
10556             gene3.setRooted( true );
10557             final SDI sdi3 = new SDI( gene3, species3 );
10558             if ( sdi3.getDuplicationsSum() != 1 ) {
10559                 return false;
10560             }
10561             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10562                 return false;
10563             }
10564             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10565                 return false;
10566             }
10567             final Phylogeny species4 = factory
10568                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10569                              new NHXParser() )[ 0 ];
10570             final Phylogeny gene4 = factory
10571                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10572                              new NHXParser() )[ 0 ];
10573             species4.setRooted( true );
10574             gene4.setRooted( true );
10575             final SDI sdi4 = new SDI( gene4, species4 );
10576             if ( sdi4.getDuplicationsSum() != 1 ) {
10577                 return false;
10578             }
10579             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10580                 return false;
10581             }
10582             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10583                 return false;
10584             }
10585             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10586                 return false;
10587             }
10588             if ( species4.getNumberOfExternalNodes() != 6 ) {
10589                 return false;
10590             }
10591             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10592                 return false;
10593             }
10594             final Phylogeny species5 = factory
10595                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10596                              new NHXParser() )[ 0 ];
10597             final Phylogeny gene5 = factory
10598                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10599                              new NHXParser() )[ 0 ];
10600             species5.setRooted( true );
10601             gene5.setRooted( true );
10602             final SDI sdi5 = new SDI( gene5, species5 );
10603             if ( sdi5.getDuplicationsSum() != 2 ) {
10604                 return false;
10605             }
10606             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10607                 return false;
10608             }
10609             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10610                 return false;
10611             }
10612             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10613                 return false;
10614             }
10615             if ( species5.getNumberOfExternalNodes() != 6 ) {
10616                 return false;
10617             }
10618             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10619                 return false;
10620             }
10621             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10622             // Conjecture for Comparing Molecular Phylogenies"
10623             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10624             final Phylogeny species6 = factory
10625                     .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,"
10626                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10627                              new NHXParser() )[ 0 ];
10628             final Phylogeny gene6 = factory
10629                     .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,"
10630                                      + "((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,"
10631                                      + "(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;",
10632                              new NHXParser() )[ 0 ];
10633             species6.setRooted( true );
10634             gene6.setRooted( true );
10635             final SDI sdi6 = new SDI( gene6, species6 );
10636             if ( sdi6.getDuplicationsSum() != 3 ) {
10637                 return false;
10638             }
10639             if ( !gene6.getNode( "r" ).isDuplication() ) {
10640                 return false;
10641             }
10642             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10643                 return false;
10644             }
10645             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10646                 return false;
10647             }
10648             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10649                 return false;
10650             }
10651             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10652                 return false;
10653             }
10654             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10655                 return false;
10656             }
10657             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10658                 return false;
10659             }
10660             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10661                 return false;
10662             }
10663             sdi6.computeMappingCostL();
10664             if ( sdi6.computeMappingCostL() != 17 ) {
10665                 return false;
10666             }
10667             if ( species6.getNumberOfExternalNodes() != 9 ) {
10668                 return false;
10669             }
10670             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10671                 return false;
10672             }
10673             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10674                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10675                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10676                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10677                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10678             species7.setRooted( true );
10679             final Phylogeny gene7_1 = Test
10680                     .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])" );
10681             gene7_1.setRooted( true );
10682             final SDI sdi7 = new SDI( gene7_1, species7 );
10683             if ( sdi7.getDuplicationsSum() != 0 ) {
10684                 return false;
10685             }
10686             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10687                 return false;
10688             }
10689             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10690                 return false;
10691             }
10692             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10693                 return false;
10694             }
10695             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10696                 return false;
10697             }
10698             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10699                 return false;
10700             }
10701             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10702                 return false;
10703             }
10704             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10705                 return false;
10706             }
10707             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10708                 return false;
10709             }
10710             final Phylogeny gene7_2 = Test
10711                     .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])" );
10712             gene7_2.setRooted( true );
10713             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10714             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10715                 return false;
10716             }
10717             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10718                 return false;
10719             }
10720             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10721                 return false;
10722             }
10723             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10724                 return false;
10725             }
10726             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10727                 return false;
10728             }
10729             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10730                 return false;
10731             }
10732             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10733                 return false;
10734             }
10735             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10736                 return false;
10737             }
10738             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10739                 return false;
10740             }
10741             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10742                 return false;
10743             }
10744         }
10745         catch ( final Exception e ) {
10746             return false;
10747         }
10748         return true;
10749     }
10750
10751     private static boolean testSDIunrooted() {
10752         try {
10753             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10754             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10755             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10756             final Iterator<PhylogenyBranch> iter = l.iterator();
10757             PhylogenyBranch br = iter.next();
10758             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10759                 return false;
10760             }
10761             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10762                 return false;
10763             }
10764             br = iter.next();
10765             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10766                 return false;
10767             }
10768             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10769                 return false;
10770             }
10771             br = iter.next();
10772             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10773                 return false;
10774             }
10775             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10776                 return false;
10777             }
10778             br = iter.next();
10779             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10780                 return false;
10781             }
10782             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10783                 return false;
10784             }
10785             br = iter.next();
10786             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10787                 return false;
10788             }
10789             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10790                 return false;
10791             }
10792             br = iter.next();
10793             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10794                 return false;
10795             }
10796             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10797                 return false;
10798             }
10799             br = iter.next();
10800             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10801                 return false;
10802             }
10803             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10804                 return false;
10805             }
10806             br = iter.next();
10807             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10808                 return false;
10809             }
10810             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10811                 return false;
10812             }
10813             br = iter.next();
10814             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10815                 return false;
10816             }
10817             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10818                 return false;
10819             }
10820             br = iter.next();
10821             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10822                 return false;
10823             }
10824             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10825                 return false;
10826             }
10827             br = iter.next();
10828             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10829                 return false;
10830             }
10831             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10832                 return false;
10833             }
10834             br = iter.next();
10835             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10836                 return false;
10837             }
10838             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10839                 return false;
10840             }
10841             br = iter.next();
10842             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10843                 return false;
10844             }
10845             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10846                 return false;
10847             }
10848             br = iter.next();
10849             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10850                 return false;
10851             }
10852             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10853                 return false;
10854             }
10855             br = iter.next();
10856             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10857                 return false;
10858             }
10859             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10860                 return false;
10861             }
10862             if ( iter.hasNext() ) {
10863                 return false;
10864             }
10865             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10866             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10867             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10868             br = iter1.next();
10869             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10870                 return false;
10871             }
10872             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10873                 return false;
10874             }
10875             br = iter1.next();
10876             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10877                 return false;
10878             }
10879             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10880                 return false;
10881             }
10882             br = iter1.next();
10883             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10884                 return false;
10885             }
10886             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10887                 return false;
10888             }
10889             if ( iter1.hasNext() ) {
10890                 return false;
10891             }
10892             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10893             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10894             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10895             br = iter2.next();
10896             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10897                 return false;
10898             }
10899             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10900                 return false;
10901             }
10902             br = iter2.next();
10903             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10904                 return false;
10905             }
10906             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10907                 return false;
10908             }
10909             br = iter2.next();
10910             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10911                 return false;
10912             }
10913             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10914                 return false;
10915             }
10916             if ( iter2.hasNext() ) {
10917                 return false;
10918             }
10919             final Phylogeny species0 = factory
10920                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10921                              new NHXParser() )[ 0 ];
10922             final Phylogeny gene1 = factory
10923                     .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])",
10924                              new NHXParser() )[ 0 ];
10925             species0.setRooted( true );
10926             gene1.setRooted( true );
10927             final SDIR sdi_unrooted = new SDIR();
10928             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10929             if ( sdi_unrooted.getCount() != 1 ) {
10930                 return false;
10931             }
10932             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10933                 return false;
10934             }
10935             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10936                 return false;
10937             }
10938             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10939                 return false;
10940             }
10941             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10942                 return false;
10943             }
10944             final Phylogeny gene2 = factory
10945                     .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])",
10946                              new NHXParser() )[ 0 ];
10947             gene2.setRooted( true );
10948             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10949             if ( sdi_unrooted.getCount() != 1 ) {
10950                 return false;
10951             }
10952             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10953                 return false;
10954             }
10955             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10956                 return false;
10957             }
10958             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10959                 return false;
10960             }
10961             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10962                 return false;
10963             }
10964             final Phylogeny species6 = factory
10965                     .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,"
10966                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10967                              new NHXParser() )[ 0 ];
10968             final Phylogeny gene6 = factory
10969                     .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],"
10970                                      + "(((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],"
10971                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10972                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10973                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10974                              new NHXParser() )[ 0 ];
10975             species6.setRooted( true );
10976             gene6.setRooted( true );
10977             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10978             if ( sdi_unrooted.getCount() != 1 ) {
10979                 return false;
10980             }
10981             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10982                 return false;
10983             }
10984             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10985                 return false;
10986             }
10987             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10988                 return false;
10989             }
10990             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10991                 return false;
10992             }
10993             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10994                 return false;
10995             }
10996             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10997                 return false;
10998             }
10999             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11000                 return false;
11001             }
11002             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11003                 return false;
11004             }
11005             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11006                 return false;
11007             }
11008             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11009                 return false;
11010             }
11011             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11012                 return false;
11013             }
11014             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11015                 return false;
11016             }
11017             p6 = null;
11018             final Phylogeny species7 = factory
11019                     .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,"
11020                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11021                              new NHXParser() )[ 0 ];
11022             final Phylogeny gene7 = factory
11023                     .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],"
11024                                      + "(((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],"
11025                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11026                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11027                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11028                              new NHXParser() )[ 0 ];
11029             species7.setRooted( true );
11030             gene7.setRooted( true );
11031             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11032             if ( sdi_unrooted.getCount() != 1 ) {
11033                 return false;
11034             }
11035             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11036                 return false;
11037             }
11038             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11039                 return false;
11040             }
11041             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11042                 return false;
11043             }
11044             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11045                 return false;
11046             }
11047             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11048                 return false;
11049             }
11050             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11051                 return false;
11052             }
11053             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11054                 return false;
11055             }
11056             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11057                 return false;
11058             }
11059             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11060                 return false;
11061             }
11062             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11063                 return false;
11064             }
11065             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11066                 return false;
11067             }
11068             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11069                 return false;
11070             }
11071             p7 = null;
11072             final Phylogeny species8 = factory
11073                     .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,"
11074                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11075                              new NHXParser() )[ 0 ];
11076             final Phylogeny gene8 = factory
11077                     .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],"
11078                                      + "(((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],"
11079                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11080                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11081                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11082                              new NHXParser() )[ 0 ];
11083             species8.setRooted( true );
11084             gene8.setRooted( true );
11085             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11086             if ( sdi_unrooted.getCount() != 1 ) {
11087                 return false;
11088             }
11089             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11090                 return false;
11091             }
11092             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11093                 return false;
11094             }
11095             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11096                 return false;
11097             }
11098             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11099                 return false;
11100             }
11101             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11102                 return false;
11103             }
11104             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11105                 return false;
11106             }
11107             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11108                 return false;
11109             }
11110             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11111                 return false;
11112             }
11113             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11114                 return false;
11115             }
11116             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11117                 return false;
11118             }
11119             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11120                 return false;
11121             }
11122             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11123                 return false;
11124             }
11125             p8 = null;
11126         }
11127         catch ( final Exception e ) {
11128             e.printStackTrace( System.out );
11129             return false;
11130         }
11131         return true;
11132     }
11133
11134     private static boolean testSequenceDbWsTools1() {
11135         try {
11136             final PhylogenyNode n = new PhylogenyNode();
11137             n.setName( "NP_001025424" );
11138             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11139             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11140                     || !acc.getValue().equals( "NP_001025424" ) ) {
11141                 return false;
11142             }
11143             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11144             acc = SequenceDbWsTools.obtainSeqAccession( n );
11145             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11146                     || !acc.getValue().equals( "NP_001025424" ) ) {
11147                 return false;
11148             }
11149             n.setName( "NP_001025424.1" );
11150             acc = SequenceDbWsTools.obtainSeqAccession( n );
11151             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11152                     || !acc.getValue().equals( "NP_001025424" ) ) {
11153                 return false;
11154             }
11155             n.setName( "NM_001030253" );
11156             acc = SequenceDbWsTools.obtainSeqAccession( n );
11157             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11158                     || !acc.getValue().equals( "NM_001030253" ) ) {
11159                 return false;
11160             }
11161             n.setName( "BCL2_HUMAN" );
11162             acc = SequenceDbWsTools.obtainSeqAccession( n );
11163             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11164                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11165                 System.out.println( acc.toString() );
11166                 return false;
11167             }
11168             n.setName( "P10415" );
11169             acc = SequenceDbWsTools.obtainSeqAccession( n );
11170             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11171                     || !acc.getValue().equals( "P10415" ) ) {
11172                 System.out.println( acc.toString() );
11173                 return false;
11174             }
11175             n.setName( " P10415 " );
11176             acc = SequenceDbWsTools.obtainSeqAccession( n );
11177             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11178                     || !acc.getValue().equals( "P10415" ) ) {
11179                 System.out.println( acc.toString() );
11180                 return false;
11181             }
11182             n.setName( "_P10415|" );
11183             acc = SequenceDbWsTools.obtainSeqAccession( n );
11184             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11185                     || !acc.getValue().equals( "P10415" ) ) {
11186                 System.out.println( acc.toString() );
11187                 return false;
11188             }
11189             n.setName( "AY695820" );
11190             acc = SequenceDbWsTools.obtainSeqAccession( n );
11191             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11192                     || !acc.getValue().equals( "AY695820" ) ) {
11193                 System.out.println( acc.toString() );
11194                 return false;
11195             }
11196             n.setName( "_AY695820_" );
11197             acc = SequenceDbWsTools.obtainSeqAccession( n );
11198             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11199                     || !acc.getValue().equals( "AY695820" ) ) {
11200                 System.out.println( acc.toString() );
11201                 return false;
11202             }
11203             n.setName( "AAA59452" );
11204             acc = SequenceDbWsTools.obtainSeqAccession( n );
11205             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11206                     || !acc.getValue().equals( "AAA59452" ) ) {
11207                 System.out.println( acc.toString() );
11208                 return false;
11209             }
11210             n.setName( "_AAA59452_" );
11211             acc = SequenceDbWsTools.obtainSeqAccession( n );
11212             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11213                     || !acc.getValue().equals( "AAA59452" ) ) {
11214                 System.out.println( acc.toString() );
11215                 return false;
11216             }
11217             n.setName( "AAA59452.1" );
11218             acc = SequenceDbWsTools.obtainSeqAccession( n );
11219             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11220                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11221                 System.out.println( acc.toString() );
11222                 return false;
11223             }
11224             n.setName( "_AAA59452.1_" );
11225             acc = SequenceDbWsTools.obtainSeqAccession( n );
11226             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11227                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11228                 System.out.println( acc.toString() );
11229                 return false;
11230             }
11231             n.setName( "GI:94894583" );
11232             acc = SequenceDbWsTools.obtainSeqAccession( n );
11233             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11234                     || !acc.getValue().equals( "94894583" ) ) {
11235                 System.out.println( acc.toString() );
11236                 return false;
11237             }
11238             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11239             acc = SequenceDbWsTools.obtainSeqAccession( n );
11240             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11241                     || !acc.getValue().equals( "71845847" ) ) {
11242                 System.out.println( acc.toString() );
11243                 return false;
11244             }
11245             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11246             acc = SequenceDbWsTools.obtainSeqAccession( n );
11247             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11248                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11249                 System.out.println( acc.toString() );
11250                 return false;
11251             }
11252         }
11253         catch ( final Exception e ) {
11254             return false;
11255         }
11256         return true;
11257     }
11258
11259     private static boolean testSequenceDbWsTools2() {
11260         try {
11261             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11262             SequenceDbWsTools.obtainSeqInformation( n1 );
11263             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11264                 return false;
11265             }
11266             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11267                 return false;
11268             }
11269             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11270                 return false;
11271             }
11272             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11273                 return false;
11274             }
11275             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11276             SequenceDbWsTools.obtainSeqInformation( n2 );
11277             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11278                 return false;
11279             }
11280             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11281                 return false;
11282             }
11283             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11284                 return false;
11285             }
11286             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11287                 return false;
11288             }
11289             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11290             SequenceDbWsTools.obtainSeqInformation( n3 );
11291             if ( !n3.getNodeData().getSequence().getName()
11292                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11293                 return false;
11294             }
11295             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11296                 return false;
11297             }
11298             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11299                 return false;
11300             }
11301             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11302                 return false;
11303             }
11304         }
11305         catch ( final IOException e ) {
11306             System.out.println();
11307             System.out.println( "the following might be due to absence internet connection:" );
11308             e.printStackTrace( System.out );
11309             return true;
11310         }
11311         catch ( final Exception e ) {
11312             e.printStackTrace();
11313             return false;
11314         }
11315         return true;
11316     }
11317
11318     private static boolean testSequenceIdParsing() {
11319         try {
11320             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11321             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11322                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11323                 if ( id != null ) {
11324                     System.out.println( "value   =" + id.getValue() );
11325                     System.out.println( "provider=" + id.getSource() );
11326                 }
11327                 return false;
11328             }
11329             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11330             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11331                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11332                 if ( id != null ) {
11333                     System.out.println( "value   =" + id.getValue() );
11334                     System.out.println( "provider=" + id.getSource() );
11335                 }
11336                 return false;
11337             }
11338             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11339             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11340                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11341                 if ( id != null ) {
11342                     System.out.println( "value   =" + id.getValue() );
11343                     System.out.println( "provider=" + id.getSource() );
11344                 }
11345                 return false;
11346             }
11347             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11348             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11349                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11350                 if ( id != null ) {
11351                     System.out.println( "value   =" + id.getValue() );
11352                     System.out.println( "provider=" + id.getSource() );
11353                 }
11354                 return false;
11355             }
11356             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11357             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11358                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11359                 if ( id != null ) {
11360                     System.out.println( "value   =" + id.getValue() );
11361                     System.out.println( "provider=" + id.getSource() );
11362                 }
11363                 return false;
11364             }
11365             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11366             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11367                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11368                 if ( id != null ) {
11369                     System.out.println( "value   =" + id.getValue() );
11370                     System.out.println( "provider=" + id.getSource() );
11371                 }
11372                 return false;
11373             }
11374             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11375             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11376                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11377                 if ( id != null ) {
11378                     System.out.println( "value   =" + id.getValue() );
11379                     System.out.println( "provider=" + id.getSource() );
11380                 }
11381                 return false;
11382             }
11383             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11384             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11385                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11386                 if ( id != null ) {
11387                     System.out.println( "value   =" + id.getValue() );
11388                     System.out.println( "provider=" + id.getSource() );
11389                 }
11390                 return false;
11391             }
11392             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11393             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11394                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11395                 if ( id != null ) {
11396                     System.out.println( "value   =" + id.getValue() );
11397                     System.out.println( "provider=" + id.getSource() );
11398                 }
11399                 return false;
11400             }
11401             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11402             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11403                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11404                 if ( id != null ) {
11405                     System.out.println( "value   =" + id.getValue() );
11406                     System.out.println( "provider=" + id.getSource() );
11407                 }
11408                 return false;
11409             }
11410             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11411             if ( id != null ) {
11412                 System.out.println( "value   =" + id.getValue() );
11413                 System.out.println( "provider=" + id.getSource() );
11414                 return false;
11415             }
11416             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11417             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11418                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11419                 if ( id != null ) {
11420                     System.out.println( "value   =" + id.getValue() );
11421                     System.out.println( "provider=" + id.getSource() );
11422                 }
11423                 return false;
11424             }
11425             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11426             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11427                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11428                 if ( id != null ) {
11429                     System.out.println( "value   =" + id.getValue() );
11430                     System.out.println( "provider=" + id.getSource() );
11431                 }
11432                 return false;
11433             }
11434             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11435             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11436                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11437                 if ( id != null ) {
11438                     System.out.println( "value   =" + id.getValue() );
11439                     System.out.println( "provider=" + id.getSource() );
11440                 }
11441                 return false;
11442             }
11443             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11444             if ( id != null ) {
11445                 System.out.println( "value   =" + id.getValue() );
11446                 System.out.println( "provider=" + id.getSource() );
11447                 return false;
11448             }
11449         }
11450         catch ( final Exception e ) {
11451             e.printStackTrace( System.out );
11452             return false;
11453         }
11454         return true;
11455     }
11456
11457     private static boolean testSequenceWriter() {
11458         try {
11459             final String n = ForesterUtil.LINE_SEPARATOR;
11460             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11461                 return false;
11462             }
11463             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11464                 return false;
11465             }
11466             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11467                 return false;
11468             }
11469             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11470                 return false;
11471             }
11472             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11473                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11474                 return false;
11475             }
11476             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11477                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11478                 return false;
11479             }
11480         }
11481         catch ( final Exception e ) {
11482             e.printStackTrace();
11483             return false;
11484         }
11485         return true;
11486     }
11487
11488     private static boolean testSpecies() {
11489         try {
11490             final Species s1 = new BasicSpecies( "a" );
11491             final Species s2 = new BasicSpecies( "a" );
11492             final Species s3 = new BasicSpecies( "A" );
11493             final Species s4 = new BasicSpecies( "b" );
11494             if ( !s1.equals( s1 ) ) {
11495                 return false;
11496             }
11497             if ( s1.getSpeciesId().equals( "x" ) ) {
11498                 return false;
11499             }
11500             if ( s1.getSpeciesId().equals( null ) ) {
11501                 return false;
11502             }
11503             if ( !s1.equals( s2 ) ) {
11504                 return false;
11505             }
11506             if ( s1.equals( s3 ) ) {
11507                 return false;
11508             }
11509             if ( s1.hashCode() != s1.hashCode() ) {
11510                 return false;
11511             }
11512             if ( s1.hashCode() != s2.hashCode() ) {
11513                 return false;
11514             }
11515             if ( s1.hashCode() == s3.hashCode() ) {
11516                 return false;
11517             }
11518             if ( s1.compareTo( s1 ) != 0 ) {
11519                 return false;
11520             }
11521             if ( s1.compareTo( s2 ) != 0 ) {
11522                 return false;
11523             }
11524             if ( s1.compareTo( s3 ) != 0 ) {
11525                 return false;
11526             }
11527             if ( s1.compareTo( s4 ) >= 0 ) {
11528                 return false;
11529             }
11530             if ( s4.compareTo( s1 ) <= 0 ) {
11531                 return false;
11532             }
11533             if ( !s4.getSpeciesId().equals( "b" ) ) {
11534                 return false;
11535             }
11536             final Species s5 = new BasicSpecies( " C " );
11537             if ( !s5.getSpeciesId().equals( "C" ) ) {
11538                 return false;
11539             }
11540             if ( s5.equals( s1 ) ) {
11541                 return false;
11542             }
11543         }
11544         catch ( final Exception e ) {
11545             e.printStackTrace( System.out );
11546             return false;
11547         }
11548         return true;
11549     }
11550
11551     private static boolean testSplit() {
11552         try {
11553             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11554             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11555             //Archaeopteryx.createApplication( p0 );
11556             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11557             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11558             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11559             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11560             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11561             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11562             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11563             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11564             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11565             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11566             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11567             // System.out.println( s0.toString() );
11568             //
11569             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11572             if ( s0.match( query_nodes ) ) {
11573                 return false;
11574             }
11575             query_nodes = new HashSet<PhylogenyNode>();
11576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11583             if ( !s0.match( query_nodes ) ) {
11584                 return false;
11585             }
11586             //
11587             query_nodes = new HashSet<PhylogenyNode>();
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11591             if ( !s0.match( query_nodes ) ) {
11592                 return false;
11593             }
11594             //
11595             query_nodes = new HashSet<PhylogenyNode>();
11596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11599             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11600             if ( !s0.match( query_nodes ) ) {
11601                 return false;
11602             }
11603             //
11604             query_nodes = new HashSet<PhylogenyNode>();
11605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11609             if ( !s0.match( query_nodes ) ) {
11610                 return false;
11611             }
11612             //
11613             query_nodes = new HashSet<PhylogenyNode>();
11614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11617             if ( !s0.match( query_nodes ) ) {
11618                 return false;
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             query_nodes = new HashSet<PhylogenyNode>();
11627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11632             if ( !s0.match( query_nodes ) ) {
11633                 return false;
11634             }
11635             query_nodes = new HashSet<PhylogenyNode>();
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11639             if ( !s0.match( query_nodes ) ) {
11640                 return false;
11641             }
11642             query_nodes = new HashSet<PhylogenyNode>();
11643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11647             if ( !s0.match( query_nodes ) ) {
11648                 return false;
11649             }
11650             query_nodes = new HashSet<PhylogenyNode>();
11651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11653             if ( s0.match( query_nodes ) ) {
11654                 return false;
11655             }
11656             query_nodes = new HashSet<PhylogenyNode>();
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11661             if ( s0.match( query_nodes ) ) {
11662                 return false;
11663             }
11664             query_nodes = new HashSet<PhylogenyNode>();
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11670             if ( s0.match( query_nodes ) ) {
11671                 return false;
11672             }
11673             query_nodes = new HashSet<PhylogenyNode>();
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11677             if ( s0.match( query_nodes ) ) {
11678                 return false;
11679             }
11680             query_nodes = new HashSet<PhylogenyNode>();
11681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11683             if ( s0.match( query_nodes ) ) {
11684                 return false;
11685             }
11686             query_nodes = new HashSet<PhylogenyNode>();
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11689             if ( s0.match( query_nodes ) ) {
11690                 return false;
11691             }
11692             query_nodes = new HashSet<PhylogenyNode>();
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11695             if ( s0.match( query_nodes ) ) {
11696                 return false;
11697             }
11698             query_nodes = new HashSet<PhylogenyNode>();
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11701             if ( s0.match( query_nodes ) ) {
11702                 return false;
11703             }
11704             query_nodes = new HashSet<PhylogenyNode>();
11705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11707             if ( s0.match( query_nodes ) ) {
11708                 return false;
11709             }
11710             query_nodes = new HashSet<PhylogenyNode>();
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11713             if ( s0.match( query_nodes ) ) {
11714                 return false;
11715             }
11716             query_nodes = new HashSet<PhylogenyNode>();
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11720             if ( s0.match( query_nodes ) ) {
11721                 return false;
11722             }
11723             query_nodes = new HashSet<PhylogenyNode>();
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11727             if ( s0.match( query_nodes ) ) {
11728                 return false;
11729             }
11730             query_nodes = new HashSet<PhylogenyNode>();
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11734             if ( s0.match( query_nodes ) ) {
11735                 return false;
11736             }
11737             query_nodes = new HashSet<PhylogenyNode>();
11738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11742             if ( s0.match( query_nodes ) ) {
11743                 return false;
11744             }
11745             /////////
11746             //            query_nodes = new HashSet<PhylogenyNode>();
11747             //            query_nodes.add( new PhylogenyNode( "X" ) );
11748             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11749             //            query_nodes.add( new PhylogenyNode( "A" ) );
11750             //            query_nodes.add( new PhylogenyNode( "B" ) );
11751             //            query_nodes.add( new PhylogenyNode( "C" ) );
11752             //            query_nodes.add( new PhylogenyNode( "D" ) );
11753             //            query_nodes.add( new PhylogenyNode( "E" ) );
11754             //            query_nodes.add( new PhylogenyNode( "F" ) );
11755             //            query_nodes.add( new PhylogenyNode( "G" ) );
11756             //            if ( !s0.match( query_nodes ) ) {
11757             //                return false;
11758             //            }
11759             //            query_nodes = new HashSet<PhylogenyNode>();
11760             //            query_nodes.add( new PhylogenyNode( "X" ) );
11761             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11762             //            query_nodes.add( new PhylogenyNode( "A" ) );
11763             //            query_nodes.add( new PhylogenyNode( "B" ) );
11764             //            query_nodes.add( new PhylogenyNode( "C" ) );
11765             //            if ( !s0.match( query_nodes ) ) {
11766             //                return false;
11767             //            }
11768             //            //
11769             //            query_nodes = new HashSet<PhylogenyNode>();
11770             //            query_nodes.add( new PhylogenyNode( "X" ) );
11771             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11772             //            query_nodes.add( new PhylogenyNode( "D" ) );
11773             //            query_nodes.add( new PhylogenyNode( "E" ) );
11774             //            query_nodes.add( new PhylogenyNode( "F" ) );
11775             //            query_nodes.add( new PhylogenyNode( "G" ) );
11776             //            if ( !s0.match( query_nodes ) ) {
11777             //                return false;
11778             //            }
11779             //            //
11780             //            query_nodes = new HashSet<PhylogenyNode>();
11781             //            query_nodes.add( new PhylogenyNode( "X" ) );
11782             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11783             //            query_nodes.add( new PhylogenyNode( "A" ) );
11784             //            query_nodes.add( new PhylogenyNode( "B" ) );
11785             //            query_nodes.add( new PhylogenyNode( "C" ) );
11786             //            query_nodes.add( new PhylogenyNode( "D" ) );
11787             //            if ( !s0.match( query_nodes ) ) {
11788             //                return false;
11789             //            }
11790             //            //
11791             //            query_nodes = new HashSet<PhylogenyNode>();
11792             //            query_nodes.add( new PhylogenyNode( "X" ) );
11793             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11794             //            query_nodes.add( new PhylogenyNode( "E" ) );
11795             //            query_nodes.add( new PhylogenyNode( "F" ) );
11796             //            query_nodes.add( new PhylogenyNode( "G" ) );
11797             //            if ( !s0.match( query_nodes ) ) {
11798             //                return false;
11799             //            }
11800             //            //
11801             //            query_nodes = new HashSet<PhylogenyNode>();
11802             //            query_nodes.add( new PhylogenyNode( "X" ) );
11803             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11804             //            query_nodes.add( new PhylogenyNode( "F" ) );
11805             //            query_nodes.add( new PhylogenyNode( "G" ) );
11806             //            if ( !s0.match( query_nodes ) ) {
11807             //                return false;
11808             //            }
11809             //
11810             query_nodes = new HashSet<PhylogenyNode>();
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11815             if ( s0.match( query_nodes ) ) {
11816                 return false;
11817             }
11818             //
11819             query_nodes = new HashSet<PhylogenyNode>();
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11824             if ( s0.match( query_nodes ) ) {
11825                 return false;
11826             }
11827             ///////////////////////////
11828             //
11829             query_nodes = new HashSet<PhylogenyNode>();
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11834             if ( s0.match( query_nodes ) ) {
11835                 return false;
11836             }
11837             //
11838             query_nodes = new HashSet<PhylogenyNode>();
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11843             if ( s0.match( query_nodes ) ) {
11844                 return false;
11845             }
11846             //
11847             query_nodes = new HashSet<PhylogenyNode>();
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11852             if ( s0.match( query_nodes ) ) {
11853                 return false;
11854             }
11855             //
11856             query_nodes = new HashSet<PhylogenyNode>();
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11861             if ( s0.match( query_nodes ) ) {
11862                 return false;
11863             }
11864             //
11865             query_nodes = new HashSet<PhylogenyNode>();
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11870             if ( s0.match( query_nodes ) ) {
11871                 return false;
11872             }
11873             //
11874             query_nodes = new HashSet<PhylogenyNode>();
11875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11878             if ( s0.match( query_nodes ) ) {
11879                 return false;
11880             }
11881             //
11882             query_nodes = new HashSet<PhylogenyNode>();
11883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11888             if ( s0.match( query_nodes ) ) {
11889                 return false;
11890             }
11891             //
11892             query_nodes = new HashSet<PhylogenyNode>();
11893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11898             if ( s0.match( query_nodes ) ) {
11899                 return false;
11900             }
11901             //
11902             query_nodes = new HashSet<PhylogenyNode>();
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11908             if ( s0.match( query_nodes ) ) {
11909                 return false;
11910             }
11911             //
11912             query_nodes = new HashSet<PhylogenyNode>();
11913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11919             if ( s0.match( query_nodes ) ) {
11920                 return false;
11921             }
11922         }
11923         catch ( final Exception e ) {
11924             e.printStackTrace();
11925             return false;
11926         }
11927         return true;
11928     }
11929
11930     private static boolean testSplitStrict() {
11931         try {
11932             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11933             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11934             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11935             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11936             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11937             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11938             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11939             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11940             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11941             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11942             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11943             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11946             if ( s0.match( query_nodes ) ) {
11947                 return false;
11948             }
11949             query_nodes = new HashSet<PhylogenyNode>();
11950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11957             if ( !s0.match( query_nodes ) ) {
11958                 return false;
11959             }
11960             //
11961             query_nodes = new HashSet<PhylogenyNode>();
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11965             if ( !s0.match( query_nodes ) ) {
11966                 return false;
11967             }
11968             //
11969             query_nodes = new HashSet<PhylogenyNode>();
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11983             if ( !s0.match( query_nodes ) ) {
11984                 return false;
11985             }
11986             //
11987             query_nodes = new HashSet<PhylogenyNode>();
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( "F" ) );
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11998             if ( !s0.match( query_nodes ) ) {
11999                 return false;
12000             }
12001             //
12002             query_nodes = new HashSet<PhylogenyNode>();
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12016             if ( !s0.match( query_nodes ) ) {
12017                 return false;
12018             }
12019             //
12020             query_nodes = new HashSet<PhylogenyNode>();
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "A" ) );
12032             if ( s0.match( query_nodes ) ) {
12033                 return false;
12034             }
12035             //
12036             query_nodes = new HashSet<PhylogenyNode>();
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12041             if ( s0.match( query_nodes ) ) {
12042                 return false;
12043             }
12044             //
12045             query_nodes = new HashSet<PhylogenyNode>();
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12051             if ( s0.match( query_nodes ) ) {
12052                 return false;
12053             }
12054             //
12055             query_nodes = new HashSet<PhylogenyNode>();
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12059             if ( s0.match( query_nodes ) ) {
12060                 return false;
12061             }
12062             //
12063             query_nodes = new HashSet<PhylogenyNode>();
12064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12066             if ( s0.match( query_nodes ) ) {
12067                 return false;
12068             }
12069             //
12070             query_nodes = new HashSet<PhylogenyNode>();
12071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12073             if ( s0.match( query_nodes ) ) {
12074                 return false;
12075             }
12076             //
12077             query_nodes = new HashSet<PhylogenyNode>();
12078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12080             if ( s0.match( query_nodes ) ) {
12081                 return false;
12082             }
12083             //
12084             query_nodes = new HashSet<PhylogenyNode>();
12085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12087             if ( s0.match( query_nodes ) ) {
12088                 return false;
12089             }
12090             //
12091             query_nodes = new HashSet<PhylogenyNode>();
12092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12093             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12094             if ( s0.match( query_nodes ) ) {
12095                 return false;
12096             }
12097             //
12098             query_nodes = new HashSet<PhylogenyNode>();
12099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12101             if ( s0.match( query_nodes ) ) {
12102                 return false;
12103             }
12104             //
12105             query_nodes = new HashSet<PhylogenyNode>();
12106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12109             if ( s0.match( query_nodes ) ) {
12110                 return false;
12111             }
12112             //
12113             query_nodes = new HashSet<PhylogenyNode>();
12114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12117             if ( s0.match( query_nodes ) ) {
12118                 return false;
12119             }
12120             //
12121             query_nodes = new HashSet<PhylogenyNode>();
12122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12125             if ( s0.match( query_nodes ) ) {
12126                 return false;
12127             }
12128             //
12129             query_nodes = new HashSet<PhylogenyNode>();
12130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12134             if ( s0.match( query_nodes ) ) {
12135                 return false;
12136             }
12137         }
12138         catch ( final Exception e ) {
12139             e.printStackTrace();
12140             return false;
12141         }
12142         return true;
12143     }
12144
12145     private static boolean testSubtreeDeletion() {
12146         try {
12147             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12148             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12149             t1.deleteSubtree( t1.getNode( "A" ), false );
12150             if ( t1.getNumberOfExternalNodes() != 5 ) {
12151                 return false;
12152             }
12153             t1.toNewHampshireX();
12154             t1.deleteSubtree( t1.getNode( "E" ), false );
12155             if ( t1.getNumberOfExternalNodes() != 4 ) {
12156                 return false;
12157             }
12158             t1.toNewHampshireX();
12159             t1.deleteSubtree( t1.getNode( "F" ), false );
12160             if ( t1.getNumberOfExternalNodes() != 3 ) {
12161                 return false;
12162             }
12163             t1.toNewHampshireX();
12164             t1.deleteSubtree( t1.getNode( "D" ), false );
12165             t1.toNewHampshireX();
12166             if ( t1.getNumberOfExternalNodes() != 3 ) {
12167                 return false;
12168             }
12169             t1.deleteSubtree( t1.getNode( "def" ), false );
12170             t1.toNewHampshireX();
12171             if ( t1.getNumberOfExternalNodes() != 2 ) {
12172                 return false;
12173             }
12174             t1.deleteSubtree( t1.getNode( "B" ), false );
12175             t1.toNewHampshireX();
12176             if ( t1.getNumberOfExternalNodes() != 1 ) {
12177                 return false;
12178             }
12179             t1.deleteSubtree( t1.getNode( "C" ), false );
12180             t1.toNewHampshireX();
12181             if ( t1.getNumberOfExternalNodes() != 1 ) {
12182                 return false;
12183             }
12184             t1.deleteSubtree( t1.getNode( "abc" ), false );
12185             t1.toNewHampshireX();
12186             if ( t1.getNumberOfExternalNodes() != 1 ) {
12187                 return false;
12188             }
12189             t1.deleteSubtree( t1.getNode( "r" ), false );
12190             if ( t1.getNumberOfExternalNodes() != 0 ) {
12191                 return false;
12192             }
12193             if ( !t1.isEmpty() ) {
12194                 return false;
12195             }
12196             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12197             t2.deleteSubtree( t2.getNode( "A" ), false );
12198             t2.toNewHampshireX();
12199             if ( t2.getNumberOfExternalNodes() != 5 ) {
12200                 return false;
12201             }
12202             t2.deleteSubtree( t2.getNode( "abc" ), false );
12203             t2.toNewHampshireX();
12204             if ( t2.getNumberOfExternalNodes() != 3 ) {
12205                 return false;
12206             }
12207             t2.deleteSubtree( t2.getNode( "def" ), false );
12208             t2.toNewHampshireX();
12209             if ( t2.getNumberOfExternalNodes() != 1 ) {
12210                 return false;
12211             }
12212         }
12213         catch ( final Exception e ) {
12214             e.printStackTrace( System.out );
12215             return false;
12216         }
12217         return true;
12218     }
12219
12220     private static boolean testSupportCount() {
12221         try {
12222             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12223             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12224             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12225                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12226                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12227                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12228                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12229                                                               new NHXParser() );
12230             SupportCount.count( t0_1, phylogenies_1, true, false );
12231             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12232             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12233                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12234                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12235                                                                       + "(((((A,B),C),D),E),(F,G))"
12236                                                                       + "(((((A,B),C),D),E),(F,G))"
12237                                                                       + "(((((A,B),C),D),E),(F,G))"
12238                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12239                                                                       + "(((((A,B),C),D),E),(F,G))"
12240                                                                       + "((((((A,B),C),D),E),F),G)"
12241                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12242                                                               new NHXParser() );
12243             SupportCount.count( t0_2, phylogenies_2, true, false );
12244             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12245             while ( it.hasNext() ) {
12246                 final PhylogenyNode n = it.next();
12247                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12248                     return false;
12249                 }
12250             }
12251             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12252             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12253                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12254             SupportCount.count( t0_3, phylogenies_3, true, false );
12255             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12256             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12257                 return false;
12258             }
12259             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12260                 return false;
12261             }
12262             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12263                 return false;
12264             }
12265             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12266                 return false;
12267             }
12268             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12269                 return false;
12270             }
12271             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12272                 return false;
12273             }
12274             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12275                 return false;
12276             }
12277             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12278                 return false;
12279             }
12280             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12281                 return false;
12282             }
12283             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12284                 return false;
12285             }
12286             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12287             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12288                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12289             SupportCount.count( t0_4, phylogenies_4, true, false );
12290             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12291             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12292                 return false;
12293             }
12294             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12295                 return false;
12296             }
12297             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12298                 return false;
12299             }
12300             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12301                 return false;
12302             }
12303             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12304                 return false;
12305             }
12306             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12307                 return false;
12308             }
12309             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12310                 return false;
12311             }
12312             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12313                 return false;
12314             }
12315             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12316                 return false;
12317             }
12318             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12319                 return false;
12320             }
12321             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12322             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12323             double d = SupportCount.compare( b1, a, true, true, true );
12324             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12325                 return false;
12326             }
12327             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12328             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12329             d = SupportCount.compare( b2, a, true, true, true );
12330             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12331                 return false;
12332             }
12333             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12334             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12335             d = SupportCount.compare( b3, a, true, true, true );
12336             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12337                 return false;
12338             }
12339             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12340             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12341             d = SupportCount.compare( b4, a, true, true, false );
12342             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12343                 return false;
12344             }
12345         }
12346         catch ( final Exception e ) {
12347             e.printStackTrace( System.out );
12348             return false;
12349         }
12350         return true;
12351     }
12352
12353     private static boolean testSupportTransfer() {
12354         try {
12355             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12356             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)",
12357                                                  new NHXParser() )[ 0 ];
12358             final Phylogeny p2 = factory
12359                     .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 ];
12360             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12361                 return false;
12362             }
12363             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12364                 return false;
12365             }
12366             support_transfer.moveBranchLengthsToBootstrap( p1 );
12367             support_transfer.transferSupportValues( p1, p2 );
12368             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12369                 return false;
12370             }
12371             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12372                 return false;
12373             }
12374             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12375                 return false;
12376             }
12377             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12378                 return false;
12379             }
12380             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12381                 return false;
12382             }
12383             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12384                 return false;
12385             }
12386             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12387                 return false;
12388             }
12389             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12390                 return false;
12391             }
12392         }
12393         catch ( final Exception e ) {
12394             e.printStackTrace( System.out );
12395             return false;
12396         }
12397         return true;
12398     }
12399
12400     private static boolean testTaxonomyExtraction() {
12401         try {
12402             final PhylogenyNode n0 = PhylogenyNode
12403                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12404             if ( n0.getNodeData().isHasTaxonomy() ) {
12405                 return false;
12406             }
12407             final PhylogenyNode n1 = PhylogenyNode
12408                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12409             if ( n1.getNodeData().isHasTaxonomy() ) {
12410                 System.out.println( n1.toString() );
12411                 return false;
12412             }
12413             final PhylogenyNode n2x = PhylogenyNode
12414                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12415             if ( n2x.getNodeData().isHasTaxonomy() ) {
12416                 return false;
12417             }
12418             final PhylogenyNode n3 = PhylogenyNode
12419                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12420             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12421                 System.out.println( n3.toString() );
12422                 return false;
12423             }
12424             final PhylogenyNode n4 = PhylogenyNode
12425                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12426             if ( n4.getNodeData().isHasTaxonomy() ) {
12427                 System.out.println( n4.toString() );
12428                 return false;
12429             }
12430             final PhylogenyNode n5 = PhylogenyNode
12431                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12432             if ( n5.getNodeData().isHasTaxonomy() ) {
12433                 System.out.println( n5.toString() );
12434                 return false;
12435             }
12436             final PhylogenyNode n6 = PhylogenyNode
12437                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12438             if ( n6.getNodeData().isHasTaxonomy() ) {
12439                 System.out.println( n6.toString() );
12440                 return false;
12441             }
12442             final PhylogenyNode n7 = PhylogenyNode
12443                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12444             if ( n7.getNodeData().isHasTaxonomy() ) {
12445                 System.out.println( n7.toString() );
12446                 return false;
12447             }
12448             final PhylogenyNode n8 = PhylogenyNode
12449                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12450             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12451                 System.out.println( n8.toString() );
12452                 return false;
12453             }
12454             final PhylogenyNode n9 = PhylogenyNode
12455                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12456             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12457                 System.out.println( n9.toString() );
12458                 return false;
12459             }
12460             final PhylogenyNode n10x = PhylogenyNode
12461                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12462             if ( n10x.getNodeData().isHasTaxonomy() ) {
12463                 System.out.println( n10x.toString() );
12464                 return false;
12465             }
12466             final PhylogenyNode n10xx = PhylogenyNode
12467                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12468             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12469                 System.out.println( n10xx.toString() );
12470                 return false;
12471             }
12472             final PhylogenyNode n10 = PhylogenyNode
12473                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12474             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12475                 System.out.println( n10.toString() );
12476                 return false;
12477             }
12478             final PhylogenyNode n11 = PhylogenyNode
12479                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12480             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12481                 System.out.println( n11.toString() );
12482                 return false;
12483             }
12484             final PhylogenyNode n12 = PhylogenyNode
12485                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12486                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12487             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12488                 System.out.println( n12.toString() );
12489                 return false;
12490             }
12491             final PhylogenyNode n13 = PhylogenyNode
12492                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12493             if ( n13.getNodeData().isHasTaxonomy() ) {
12494                 System.out.println( n13.toString() );
12495                 return false;
12496             }
12497             final PhylogenyNode n14 = PhylogenyNode
12498                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12499             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12500                 System.out.println( n14.toString() );
12501                 return false;
12502             }
12503             final PhylogenyNode n15 = PhylogenyNode
12504                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12505             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12506                 System.out.println( n15.toString() );
12507                 return false;
12508             }
12509             final PhylogenyNode n16 = PhylogenyNode
12510                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12511             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12512                 System.out.println( n16.toString() );
12513                 return false;
12514             }
12515             final PhylogenyNode n17 = PhylogenyNode
12516                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12517             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12518                 System.out.println( n17.toString() );
12519                 return false;
12520             }
12521             final PhylogenyNode n18 = PhylogenyNode
12522                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12523             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12524                 System.out.println( n18.toString() );
12525                 return false;
12526             }
12527             final PhylogenyNode n19 = PhylogenyNode
12528                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12529                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12530             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12531                 System.out.println( n19.toString() );
12532                 return false;
12533             }
12534             final PhylogenyNode n20 = PhylogenyNode
12535                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12536             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12537                 System.out.println( n20.toString() );
12538                 return false;
12539             }
12540             final PhylogenyNode n21 = PhylogenyNode
12541                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12542                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12543             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12544                 System.out.println( n21.toString() );
12545                 return false;
12546             }
12547             final PhylogenyNode n23 = PhylogenyNode
12548                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12549                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12550             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12551                 System.out.println( n23.toString() );
12552                 return false;
12553             }
12554             final PhylogenyNode n24 = PhylogenyNode
12555                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12556             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12557                 System.out.println( n24.toString() );
12558                 return false;
12559             }
12560             //
12561             final PhylogenyNode n25 = PhylogenyNode
12562                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12563                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12564             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12565                 System.out.println( n25.toString() );
12566                 return false;
12567             }
12568             final PhylogenyNode n26 = PhylogenyNode
12569                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12570                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12571             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12572                 System.out.println( n26.toString() );
12573                 return false;
12574             }
12575             final PhylogenyNode n27 = PhylogenyNode
12576                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12577             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12578                 System.out.println( n27.toString() );
12579                 return false;
12580             }
12581         }
12582         catch ( final Exception e ) {
12583             e.printStackTrace( System.out );
12584             return false;
12585         }
12586         return true;
12587     }
12588
12589     private static boolean testTreeCopy() {
12590         try {
12591             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12592             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12593             final Phylogeny t1 = t0.copy();
12594             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12595                 return false;
12596             }
12597             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12598                 return false;
12599             }
12600             t0.deleteSubtree( t0.getNode( "c" ), true );
12601             t0.deleteSubtree( t0.getNode( "a" ), true );
12602             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12603             t0.getNode( "b" ).setName( "Bee" );
12604             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12605                 return false;
12606             }
12607             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12608                 return false;
12609             }
12610             t0.deleteSubtree( t0.getNode( "e" ), true );
12611             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12612             t0.deleteSubtree( t0.getNode( "d" ), true );
12613             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12614                 return false;
12615             }
12616         }
12617         catch ( final Exception e ) {
12618             e.printStackTrace();
12619             return false;
12620         }
12621         return true;
12622     }
12623
12624     private static boolean testTreeMethods() {
12625         try {
12626             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12627             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12628             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12629             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12630                 System.out.println( t0.toNewHampshireX() );
12631                 return false;
12632             }
12633             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12634             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12635             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12636                 return false;
12637             }
12638             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12639                 return false;
12640             }
12641             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12642                 return false;
12643             }
12644         }
12645         catch ( final Exception e ) {
12646             e.printStackTrace( System.out );
12647             return false;
12648         }
12649         return true;
12650     }
12651
12652     private static boolean testUniprotEntryRetrieval() {
12653         try {
12654             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12655             if ( !entry.getAccession().equals( "P12345" ) ) {
12656                 return false;
12657             }
12658             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12659                 return false;
12660             }
12661             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12662                 return false;
12663             }
12664             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12665                 return false;
12666             }
12667             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12668                 return false;
12669             }
12670             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12671                 return false;
12672             }
12673             if ( !entry
12674                     .getMolecularSequence()
12675                     .getMolecularSequenceAsString()
12676                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12677                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12678                 System.out.println( entry.getMolecularSequence().getMolecularSequenceAsString() );
12679                 return false;
12680             }
12681         }
12682         catch ( final IOException e ) {
12683             System.out.println();
12684             System.out.println( "the following might be due to absence internet connection:" );
12685             e.printStackTrace( System.out );
12686             return true;
12687         }
12688         catch ( final Exception e ) {
12689             return false;
12690         }
12691         return true;
12692     }
12693
12694     private static boolean testUniprotTaxonomySearch() {
12695         try {
12696             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12697                                                                                                  10 );
12698             if ( results.size() != 1 ) {
12699                 return false;
12700             }
12701             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12702                 return false;
12703             }
12704             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12705                 return false;
12706             }
12707             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12708                 return false;
12709             }
12710             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12711                 return false;
12712             }
12713             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12714                 return false;
12715             }
12716             results = null;
12717             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12718             if ( results.size() != 1 ) {
12719                 return false;
12720             }
12721             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12722                 return false;
12723             }
12724             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12725                 return false;
12726             }
12727             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12728                 return false;
12729             }
12730             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12731                 return false;
12732             }
12733             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12734                 return false;
12735             }
12736             results = null;
12737             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12738             if ( results.size() != 1 ) {
12739                 return false;
12740             }
12741             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12742                 return false;
12743             }
12744             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12745                 return false;
12746             }
12747             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12748                 return false;
12749             }
12750             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12751                 return false;
12752             }
12753             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12754                 return false;
12755             }
12756             results = null;
12757             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12758             if ( results.size() != 1 ) {
12759                 return false;
12760             }
12761             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12762                 return false;
12763             }
12764             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12765                 return false;
12766             }
12767             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12771                 return false;
12772             }
12773             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12774                 return false;
12775             }
12776             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12777                 return false;
12778             }
12779             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12780                 return false;
12781             }
12782             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12783                     .equals( "Nematostella vectensis" ) ) {
12784                 System.out.println( results.get( 0 ).getLineage() );
12785                 return false;
12786             }
12787             //
12788             results = null;
12789             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12790             if ( results.size() != 1 ) {
12791                 return false;
12792             }
12793             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12794                 return false;
12795             }
12796             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12797                 return false;
12798             }
12799             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12800                 return false;
12801             }
12802             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12803                 return false;
12804             }
12805             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12806                 return false;
12807             }
12808             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12809                     .equals( "Xenopus tropicalis" ) ) {
12810                 System.out.println( results.get( 0 ).getLineage() );
12811                 return false;
12812             }
12813             //
12814             results = null;
12815             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12816             if ( results.size() != 1 ) {
12817                 return false;
12818             }
12819             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12820                 return false;
12821             }
12822             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12823                 return false;
12824             }
12825             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12826                 return false;
12827             }
12828             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12829                 return false;
12830             }
12831             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12832                 return false;
12833             }
12834             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12835                     .equals( "Xenopus tropicalis" ) ) {
12836                 System.out.println( results.get( 0 ).getLineage() );
12837                 return false;
12838             }
12839             //
12840             results = null;
12841             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12842             if ( results.size() != 1 ) {
12843                 return false;
12844             }
12845             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12846                 return false;
12847             }
12848             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12849                 return false;
12850             }
12851             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12852                 return false;
12853             }
12854             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12855                 return false;
12856             }
12857             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12858                 return false;
12859             }
12860             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12861                     .equals( "Xenopus tropicalis" ) ) {
12862                 System.out.println( results.get( 0 ).getLineage() );
12863                 return false;
12864             }
12865         }
12866         catch ( final IOException e ) {
12867             System.out.println();
12868             System.out.println( "the following might be due to absence internet connection:" );
12869             e.printStackTrace( System.out );
12870             return true;
12871         }
12872         catch ( final Exception e ) {
12873             return false;
12874         }
12875         return true;
12876     }
12877
12878     private static boolean testWabiTxSearch() {
12879         try {
12880             String result = "";
12881             result = TxSearch.searchSimple( "nematostella" );
12882             result = TxSearch.getTxId( "nematostella" );
12883             if ( !result.equals( "45350" ) ) {
12884                 return false;
12885             }
12886             result = TxSearch.getTxName( "45350" );
12887             if ( !result.equals( "Nematostella" ) ) {
12888                 return false;
12889             }
12890             result = TxSearch.getTxId( "nematostella vectensis" );
12891             if ( !result.equals( "45351" ) ) {
12892                 return false;
12893             }
12894             result = TxSearch.getTxName( "45351" );
12895             if ( !result.equals( "Nematostella vectensis" ) ) {
12896                 return false;
12897             }
12898             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12899             if ( !result.equals( "536089" ) ) {
12900                 return false;
12901             }
12902             result = TxSearch.getTxName( "536089" );
12903             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12904                 return false;
12905             }
12906             final List<String> queries = new ArrayList<String>();
12907             queries.add( "Campylobacter coli" );
12908             queries.add( "Escherichia coli" );
12909             queries.add( "Arabidopsis" );
12910             queries.add( "Trichoplax" );
12911             queries.add( "Samanea saman" );
12912             queries.add( "Kluyveromyces marxianus" );
12913             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12914             queries.add( "Bornavirus parrot/PDD/2008" );
12915             final List<RANKS> ranks = new ArrayList<RANKS>();
12916             ranks.add( RANKS.SUPERKINGDOM );
12917             ranks.add( RANKS.KINGDOM );
12918             ranks.add( RANKS.FAMILY );
12919             ranks.add( RANKS.GENUS );
12920             ranks.add( RANKS.TRIBE );
12921             result = TxSearch.searchLineage( queries, ranks );
12922             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12923             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12924         }
12925         catch ( final Exception e ) {
12926             System.out.println();
12927             System.out.println( "the following might be due to absence internet connection:" );
12928             e.printStackTrace( System.out );
12929             return false;
12930         }
12931         return true;
12932     }
12933 }